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.invoke;
10 import static org.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertThrows;
15 import static org.mockito.Mockito.mock;
17 import com.google.common.collect.ImmutableMap;
18 import com.google.common.util.concurrent.UncheckedExecutionException;
19 import java.lang.invoke.MethodHandle;
20 import java.lang.invoke.WrongMethodTypeException;
21 import org.junit.Test;
22 import org.opendaylight.yangtools.yang.binding.Augmentation;
23 import org.opendaylight.yangtools.yang.binding.DataObject;
24 import org.opendaylight.yangtools.yang.binding.Notification;
25 import org.opendaylight.yangtools.yang.binding.NotificationListener;
26 import org.opendaylight.yangtools.yang.common.QName;
28 public class NotificationListenerInvokerTest {
30 public void fromTest() throws Exception {
31 assertNotNull(NotificationListenerInvoker.from(TestInterface.class));
35 public void fromWithExceptionTest() {
36 final var cause = assertThrows(UncheckedExecutionException.class,
37 () -> NotificationListenerInvoker.from(TestPrivateInterface.class))
39 assertThat(cause, instanceOf(IllegalStateException.class));
40 assertThat(cause.getCause(), instanceOf(IllegalAccessException.class));
44 public void invokeNotification() {
45 final NotificationListener notificationListener = mock(NotificationListener.class);
46 final MethodHandle methodHandle = mock(MethodHandle.class);
47 final NotificationListenerInvoker notificationListenerInvoker =
48 new NotificationListenerInvoker(ImmutableMap.of(QName.create("test", "test"), methodHandle));
50 final var ex = assertThrows(WrongMethodTypeException.class,
51 () -> notificationListenerInvoker.invokeNotification(notificationListener, QName.create("test", "test"),
53 assertEquals("expected null but found (NotificationListener,DataContainer)void", ex.getMessage());
56 public interface TestInterface extends NotificationListener, Augmentation {
57 QName QNAME = QName.create("test", "test");
59 void onTestNotificationInterface(TestNotificationInterface notif);
62 private interface TestPrivateInterface extends NotificationListener, Augmentation {
63 QName QNAME = QName.create("test", "test");
65 void onTestNotificationInterface(TestNotificationInterface notif);
68 public interface TestNotificationInterface extends DataObject, Notification<TestNotificationInterface> {
69 QName QNAME = QName.create("test", "test");