X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=binding%2Fmdsal-binding-dom-adapter%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fadapter%2Finvoke%2FNotificationListenerInvokerTest.java;h=4d11ed0388ad8948f011052b01778f6e61c2e5fc;hb=eab9b7696b3fc547652934bb927fe5c9b27e1857;hp=e8880d366702926da226a0ee4c2bbc1d3951a1ae;hpb=c1e637cf8254e8c71f5849f531e000b1e4cd4b29;p=mdsal.git diff --git a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/NotificationListenerInvokerTest.java b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/NotificationListenerInvokerTest.java index e8880d3667..4d11ed0388 100644 --- a/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/NotificationListenerInvokerTest.java +++ b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/NotificationListenerInvokerTest.java @@ -7,8 +7,11 @@ */ package org.opendaylight.mdsal.binding.dom.adapter.invoke; +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.mock; import com.google.common.collect.ImmutableMap; @@ -16,6 +19,7 @@ import com.google.common.util.concurrent.UncheckedExecutionException; import java.lang.invoke.MethodHandle; import java.lang.invoke.WrongMethodTypeException; import org.junit.Test; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.bi.ba.notification.rev150205.OpendaylightTestNotificationListener; import org.opendaylight.yangtools.yang.binding.Augmentation; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.Notification; @@ -23,41 +27,36 @@ import org.opendaylight.yangtools.yang.binding.NotificationListener; import org.opendaylight.yangtools.yang.common.QName; public class NotificationListenerInvokerTest { - @Test public void fromTest() throws Exception { - assertNotNull(NotificationListenerInvoker.from(TestInterface.class)); + assertNotNull(NotificationListenerInvoker.from(OpendaylightTestNotificationListener.class)); } - @Test(expected = IllegalStateException.class) - @SuppressWarnings({ "checkstyle:illegalThrows", "checkstyle:avoidHidingCauseException" }) - public void fromWithExceptionTest() throws Throwable { - try { - NotificationListenerInvoker.from(TestPrivateInterface.class); - fail("Expected IllegalAccessException"); - } catch (UncheckedExecutionException e) { - throw e.getCause(); - } + @Test + public void fromWithExceptionTest() { + final var cause = assertThrows(UncheckedExecutionException.class, + () -> NotificationListenerInvoker.from(TestPrivateInterface.class)) + .getCause(); + assertThat(cause, instanceOf(IllegalStateException.class)); + assertThat(cause.getCause(), instanceOf(IllegalAccessException.class)); } - @Test(expected = WrongMethodTypeException.class) - public void invokeNotification() throws Exception { + @Test + public void invokeNotification() { final NotificationListener notificationListener = mock(NotificationListener.class); final MethodHandle methodHandle = mock(MethodHandle.class); final NotificationListenerInvoker notificationListenerInvoker = new NotificationListenerInvoker(ImmutableMap.of(QName.create("test", "test"), methodHandle)); - notificationListenerInvoker.invokeNotification(notificationListener, QName.create("test", "test"), null); - fail("Expected WrongMethodTypeException, no method to invoke is supplied"); - } - - public interface TestInterface extends NotificationListener, Augmentation { - QName QNAME = QName.create("test", "test"); - void onTestNotificationInterface(TestNotificationInterface notif); + final var ex = assertThrows(WrongMethodTypeException.class, + () -> notificationListenerInvoker.invokeNotification(notificationListener, QName.create("test", "test"), + null)); + assertEquals("expected null but found (NotificationListener,DataContainer)void", ex.getMessage()); } private interface TestPrivateInterface extends NotificationListener, Augmentation { QName QNAME = QName.create("test", "test"); + void onTestNotificationInterface(TestNotificationInterface notif); }