Bug 5947: Increasing code coverage - binding-dom-adapter
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / BindingDOMMountPointListenerAdapterTest.java
1 /*
2  * Copyright (c) 2016 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.mdsal.binding.dom.adapter;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.reset;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.Mockito.verifyZeroInteractions;
16 import static org.mockito.MockitoAnnotations.initMocks;
17
18 import com.google.common.util.concurrent.MoreExecutors;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.opendaylight.mdsal.binding.api.MountPointService.MountPointListener;
23 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
24 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingTestContext;
25 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
26 import org.opendaylight.yangtools.concepts.ListenerRegistration;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28
29 public class BindingDOMMountPointListenerAdapterTest {
30
31     private BindingDOMMountPointListenerAdapter bindingDOMMountPointListenerAdapter;
32     private BindingToNormalizedNodeCodec codec;
33
34     @Mock private MountPointListener listener;
35     @Mock private DOMMountPointService mountPointService;
36     @Mock private ListenerRegistration listenerRegistration;
37
38     @Before
39     public void setUp() throws Exception {
40         initMocks(this);
41         final BindingBrokerTestFactory testFactory = new BindingBrokerTestFactory();
42         testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
43         final BindingTestContext testContext = testFactory.getTestContext();
44         testContext.start();
45         codec = testContext.getCodec();
46         doReturn(listenerRegistration).when(mountPointService).registerProvisionListener(any());
47         bindingDOMMountPointListenerAdapter =
48                 new BindingDOMMountPointListenerAdapter<>(listener, codec, mountPointService);
49     }
50
51     @Test
52     public void basicTest() throws Exception {
53         assertEquals(listener, bindingDOMMountPointListenerAdapter.getInstance());
54         bindingDOMMountPointListenerAdapter.close();
55         verify(listenerRegistration).close();
56     }
57
58     @Test
59     public void onMountPointCreatedWithExceptionTest() throws Exception {
60         reset(listener);
61         bindingDOMMountPointListenerAdapter.onMountPointCreated(YangInstanceIdentifier.EMPTY);
62         verifyZeroInteractions(listener);
63     }
64
65     @Test
66     public void onMountPointRemovedWithExceptionTest() throws Exception {
67         reset(listener);
68         bindingDOMMountPointListenerAdapter.onMountPointRemoved(YangInstanceIdentifier.EMPTY);
69         verifyZeroInteractions(listener);
70     }
71 }