2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.netconf.mdsal.notification.impl;
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;
15 import java.util.Collection;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.mockito.ArgumentCaptor;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.mdsal.binding.api.DataBroker;
22 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
23 import org.opendaylight.mdsal.binding.api.DataTreeModification;
24 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
25 import org.opendaylight.yangtools.yang.binding.DataObject;
26 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 public class OperationalDatastoreListenerTest {
31 private DataBroker dataBroker;
34 public void setUp() throws Exception {
35 MockitoAnnotations.initMocks(this);
39 public void testDataStoreListener() {
40 final InstanceIdentifier<DataObject> instanceIdentifier = InstanceIdentifier.create(DataObject.class);
41 final DataTreeIdentifier<DataObject> testId =
42 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
44 final OperationalDatastoreListener<DataObject> op =
45 new OperationalDatastoreListener<DataObject>(instanceIdentifier) {
47 public void onDataTreeChanged(final Collection<DataTreeModification<DataObject>> collection) {
50 doReturn(null).when(dataBroker).registerDataTreeChangeListener(any(), any());
52 ArgumentCaptor<DataTreeIdentifier> argumentId = ArgumentCaptor.forClass(DataTreeIdentifier.class);
53 op.registerOnChanges(dataBroker);
54 verify(dataBroker).registerDataTreeChangeListener(argumentId.capture(), any());
56 assertEquals(testId, argumentId.getValue());