Fix checkstyle violations in yang-binding
[mdsal.git] / binding / yang-binding / src / test / java / org / opendaylight / yangtools / yang / binding / util / NotificationListenerInvokerTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.binding.util;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.fail;
12 import static org.mockito.Mockito.mock;
13
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;
23
24 public class NotificationListenerInvokerTest {
25
26     @Test
27     public void fromTest() throws Exception {
28         assertNotNull(NotificationListenerInvoker.from(TestInterface.class));
29     }
30
31     @Test(expected = IllegalStateException.class)
32     @SuppressWarnings("checkstyle:illegalThrows")
33     public void fromWithExceptionTest() throws Throwable {
34         try {
35             NotificationListenerInvoker.from(TestPrivateInterface.class);
36             fail("Expected IllegalAccessException");
37         } catch (UncheckedExecutionException e) {
38             throw e.getCause();
39         }
40     }
41
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));
48
49         notificationListenerInvoker.invokeNotification(notificationListener, QName.create("test"), null);
50         fail("Expected WrongMethodTypeException, no method to invoke is supplied");
51     }
52
53     public interface TestInterface extends NotificationListener, Augmentation {
54         QName QNAME = QName.create("test");
55         void onTestNotificationInterface(TestNotificationInterface notif);
56     }
57
58     private interface TestPrivateInterface extends NotificationListener, Augmentation {
59         QName QNAME = QName.create("test");
60         void onTestNotificationInterface(TestNotificationInterface notif);
61     }
62
63     private interface TestNotificationInterface extends Notification {
64         QName QNAME = QName.create("test");
65     }
66 }