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.mdsal.binding.dom.adapter;
10 import static org.junit.Assert.assertSame;
11 import static org.mockito.ArgumentMatchers.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.verifyNoInteractions;
17 import com.google.common.util.concurrent.MoreExecutors;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
22 import org.mockito.junit.MockitoJUnitRunner;
23 import org.opendaylight.mdsal.binding.api.MountPointService.MountPointListener;
24 import org.opendaylight.mdsal.binding.dom.adapter.test.util.BindingBrokerTestFactory;
25 import org.opendaylight.mdsal.dom.api.DOMMountPointService;
26 import org.opendaylight.yangtools.concepts.ListenerRegistration;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 @RunWith(MockitoJUnitRunner.StrictStubs.class)
30 public class BindingDOMMountPointListenerAdapterTest {
31 private BindingDOMMountPointListenerAdapter adapter;
32 private AdapterContext codec;
34 @Mock private MountPointListener listener;
35 @Mock private DOMMountPointService mountPointService;
36 @Mock private ListenerRegistration<?> listenerRegistration;
39 public void setUp() throws Exception {
40 final var testFactory = new BindingBrokerTestFactory();
41 testFactory.setExecutor(MoreExecutors.newDirectExecutorService());
42 final var testContext = testFactory.getTestContext();
44 codec = testContext.getCodec();
45 doReturn(listenerRegistration).when(mountPointService).registerProvisionListener(any());
46 adapter = new BindingDOMMountPointListenerAdapter(listener, codec, mountPointService);
50 public void basicTest() throws Exception {
51 assertSame(listener, adapter.listener);
53 verify(listenerRegistration).close();
57 public void onMountPointCreatedWithExceptionTest() throws Exception {
59 adapter.onMountPointCreated(YangInstanceIdentifier.of());
60 verifyNoInteractions(listener);
64 public void onMountPointRemovedWithExceptionTest() throws Exception {
66 adapter.onMountPointRemoved(YangInstanceIdentifier.of());
67 verifyNoInteractions(listener);