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
9 package org.opendaylight.netconf.mdsal.notification.impl;
11 import static org.junit.Assert.assertEquals;
12 import static org.mockito.ArgumentMatchers.any;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.verify;
16 import java.util.Collection;
17 import javax.annotation.Nonnull;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.mockito.ArgumentCaptor;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.mdsal.binding.api.DataBroker;
24 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.yangtools.yang.binding.DataObject;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29 public class OperationalDatastoreListenerTest {
32 private DataBroker dataBroker;
35 public void setUp() throws Exception {
36 MockitoAnnotations.initMocks(this);
40 public void testDataStoreListener() {
41 final InstanceIdentifier<DataObject> instanceIdentifier = InstanceIdentifier.create(DataObject.class);
42 final DataTreeIdentifier<DataObject> testId =
43 DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifier);
45 final OperationalDatastoreListener<DataObject> op =
46 new OperationalDatastoreListener<DataObject>(instanceIdentifier) {
48 public void onDataTreeChanged(@Nonnull final Collection collection) {
51 doReturn(null).when(dataBroker).registerDataTreeChangeListener(any(), any());
53 ArgumentCaptor<DataTreeIdentifier> argumentId = ArgumentCaptor.forClass(DataTreeIdentifier.class);
54 op.registerOnChanges(dataBroker);
55 verify(dataBroker).registerDataTreeChangeListener(argumentId.capture(), any());
57 assertEquals(testId, argumentId.getValue());