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.junit.Assert.assertNotNull;
11 import static org.junit.Assert.fail;
12 import static org.mockito.Mockito.mock;
14 import com.google.common.collect.ImmutableMap;
15 import com.google.common.util.concurrent.UncheckedExecutionException;
16 import java.lang.invoke.MethodHandle;
17 import java.lang.invoke.WrongMethodTypeException;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.binding.Augmentation;
20 import org.opendaylight.yangtools.yang.binding.DataObject;
21 import org.opendaylight.yangtools.yang.binding.Notification;
22 import org.opendaylight.yangtools.yang.binding.NotificationListener;
23 import org.opendaylight.yangtools.yang.common.QName;
25 public class NotificationListenerInvokerTest {
28 public void fromTest() throws Exception {
29 assertNotNull(NotificationListenerInvoker.from(TestInterface.class));
32 @Test(expected = IllegalStateException.class)
33 @SuppressWarnings({ "checkstyle:illegalThrows", "checkstyle:avoidHidingCauseException" })
34 public void fromWithExceptionTest() throws Throwable {
36 NotificationListenerInvoker.from(TestPrivateInterface.class);
37 fail("Expected IllegalAccessException");
38 } catch (UncheckedExecutionException e) {
43 @Test(expected = WrongMethodTypeException.class)
44 public void invokeNotification() throws Exception {
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 notificationListenerInvoker.invokeNotification(notificationListener, QName.create("test", "test"), null);
51 fail("Expected WrongMethodTypeException, no method to invoke is supplied");
54 public interface TestInterface extends NotificationListener, Augmentation {
55 QName QNAME = QName.create("test", "test");
57 void onTestNotificationInterface(TestNotificationInterface notif);
60 private interface TestPrivateInterface extends NotificationListener, Augmentation {
61 QName QNAME = QName.create("test", "test");
63 void onTestNotificationInterface(TestNotificationInterface notif);
66 public interface TestNotificationInterface extends DataObject, Notification<TestNotificationInterface> {
67 QName QNAME = QName.create("test", "test");