Fix checkstyle
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / invoke / 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.mdsal.binding.dom.adapter.invoke;
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.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;
24
25 public class NotificationListenerInvokerTest {
26
27     @Test
28     public void fromTest() throws Exception {
29         assertNotNull(NotificationListenerInvoker.from(TestInterface.class));
30     }
31
32     @Test(expected = IllegalStateException.class)
33     @SuppressWarnings({ "checkstyle:illegalThrows", "checkstyle:avoidHidingCauseException" })
34     public void fromWithExceptionTest() throws Throwable {
35         try {
36             NotificationListenerInvoker.from(TestPrivateInterface.class);
37             fail("Expected IllegalAccessException");
38         } catch (UncheckedExecutionException e) {
39             throw e.getCause();
40         }
41     }
42
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));
49
50         notificationListenerInvoker.invokeNotification(notificationListener, QName.create("test", "test"), null);
51         fail("Expected WrongMethodTypeException, no method to invoke is supplied");
52     }
53
54     public interface TestInterface extends NotificationListener, Augmentation {
55         QName QNAME = QName.create("test", "test");
56
57         void onTestNotificationInterface(TestNotificationInterface notif);
58     }
59
60     private interface TestPrivateInterface extends NotificationListener, Augmentation {
61         QName QNAME = QName.create("test", "test");
62
63         void onTestNotificationInterface(TestNotificationInterface notif);
64     }
65
66     public interface TestNotificationInterface extends DataObject, Notification<TestNotificationInterface> {
67         QName QNAME = QName.create("test", "test");
68     }
69 }