Clean up mdsal-netconf-notification
[netconf.git] / netconf / mdsal-netconf-notification / src / test / java / org / opendaylight / netconf / mdsal / notification / impl / OperationalDatastoreListenerTest.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.netconf.mdsal.notification.impl;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.verify;
14
15 import java.util.Collection;
16 import org.junit.Test;
17 import org.junit.runner.RunWith;
18 import org.mockito.ArgumentCaptor;
19 import org.mockito.Captor;
20 import org.mockito.Mock;
21 import org.mockito.junit.MockitoJUnitRunner;
22 import org.opendaylight.mdsal.binding.api.DataBroker;
23 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
24 import org.opendaylight.mdsal.binding.api.DataTreeModification;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.yangtools.yang.binding.ChildOf;
27 import org.opendaylight.yangtools.yang.binding.DataRoot;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29
30 @RunWith(MockitoJUnitRunner.StrictStubs.class)
31 public class OperationalDatastoreListenerTest {
32     @Mock
33     private DataBroker dataBroker;
34     @Captor
35     private ArgumentCaptor<DataTreeIdentifier<?>> argumentId;
36
37     @Test
38     public void testDataStoreListener() {
39         final InstanceIdentifier<TestInterface> instanceIdentifier = InstanceIdentifier.create(TestInterface.class);
40
41         final var op = new OperationalDatastoreListener<>(instanceIdentifier) {
42             @Override
43             public void onDataTreeChanged(final Collection<DataTreeModification<TestInterface>> collection) {
44                 // no-op
45             }
46         };
47         doReturn(null).when(dataBroker).registerDataTreeChangeListener(any(), any());
48
49         op.registerOnChanges(dataBroker);
50         verify(dataBroker).registerDataTreeChangeListener(argumentId.capture(), any());
51
52         assertEquals(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier),
53             argumentId.getValue());
54     }
55
56     interface TestInterface extends ChildOf<DataRoot> {
57         @Override
58         default Class<TestInterface> implementedInterface() {
59             return TestInterface.class;
60         }
61     }
62 }