Decouple HashCodeBuilder from Builder
[yangtools.git] / common / util / src / test / java / org / opendaylight / yangtools / util / ListenerRegistryTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.yangtools.util;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12
13 import java.util.EventListener;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.concepts.ListenerRegistration;
17
18 public class ListenerRegistryTest {
19     private ExtendedTestEventListener extendedTestEventListener;
20     private ListenerRegistry<TestEventListener> registry;
21
22     @Before
23     public void init() {
24         extendedTestEventListener = new ExtendedTestEventListener() {};
25         registry = ListenerRegistry.create();
26     }
27
28     @Test
29     public void testCreateNewInstance() {
30         assertNotNull("Intance of listener registry should not be null.", registry);
31     }
32
33     @Test
34     public void testGetListenersMethod() {
35         assertEquals("Listener registry should not have any listeners.", 0, registry.streamListeners().count());
36     }
37
38     @Test
39     public void testRegisterMethod() {
40         final ListenerRegistration<ExtendedTestEventListener> listenerRegistration = registry.register(
41             extendedTestEventListener);
42         assertEquals("Listeners should be the same.", extendedTestEventListener, listenerRegistration.getInstance());
43     }
44
45     interface TestEventListener extends EventListener {
46
47     }
48
49     interface ExtendedTestEventListener extends TestEventListener {
50
51     }
52 }