d8b3f792dee1894358f5a8b940cc5a96a40a36e8
[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 com.google.common.collect.ImmutableSet;
14 import java.util.EventListener;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.concepts.ListenerRegistration;
18
19 public class ListenerRegistryTest {
20     private TestEventListener testEventListener;
21     private ExtendedTestEventListener extendedTestEventListener;
22     private ListenerRegistry<TestEventListener> registry;
23
24     @Before
25     public void init() {
26         testEventListener = new TestEventListener() {};
27         extendedTestEventListener = new ExtendedTestEventListener() {};
28         registry = ListenerRegistry.create();
29     }
30
31     @Test
32     public void testCreateNewInstance() {
33         assertNotNull("Intance of listener registry should not be null.", registry);
34     }
35
36     @Test
37     public void tetGetListenersMethod() {
38         assertEquals("Listener registry should have any listeners.", ImmutableSet.of(), registry.getRegistrations());
39     }
40
41     @Test
42     public void testRegisterMethod() {
43         final ListenerRegistration<ExtendedTestEventListener> listenerRegistration = registry.register(
44             extendedTestEventListener);
45         assertEquals("Listeners should be the same.", extendedTestEventListener, listenerRegistration.getInstance());
46     }
47
48     interface TestEventListener extends EventListener {
49
50     }
51
52     interface ExtendedTestEventListener extends TestEventListener {
53
54     }
55 }