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.yangtools.yang.binding.util;
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.Notification;
21 import org.opendaylight.yangtools.yang.binding.NotificationListener;
22 import org.opendaylight.yangtools.yang.common.QName;
24 public class NotificationListenerInvokerTest {
27 public void fromTest() throws Exception {
28 assertNotNull(NotificationListenerInvoker.from(TestInterface.class));
31 @Test(expected = IllegalStateException.class)
32 @SuppressWarnings("checkstyle:illegalThrows")
33 public void fromWithExceptionTest() throws Throwable {
35 NotificationListenerInvoker.from(TestPrivateInterface.class);
36 fail("Expected IllegalAccessException");
37 } catch (UncheckedExecutionException e) {
42 @Test(expected = WrongMethodTypeException.class)
43 public void invokeNotification() throws Exception {
44 final NotificationListener notificationListener = mock(NotificationListener.class);
45 final MethodHandle methodHandle = mock(MethodHandle.class);
46 final NotificationListenerInvoker notificationListenerInvoker =
47 new NotificationListenerInvoker(ImmutableMap.of(QName.create("test"), methodHandle));
49 notificationListenerInvoker.invokeNotification(notificationListener, QName.create("test"), null);
50 fail("Expected WrongMethodTypeException, no method to invoke is supplied");
53 public interface TestInterface extends NotificationListener, Augmentation {
54 QName QNAME = QName.create("test");
55 void onTestNotificationInterface(TestNotificationInterface notif);
58 private interface TestPrivateInterface extends NotificationListener, Augmentation {
59 QName QNAME = QName.create("test");
60 void onTestNotificationInterface(TestNotificationInterface notif);
63 private interface TestNotificationInterface extends Notification {
64 QName QNAME = QName.create("test");