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;fp=binding%2Fmdsal-binding-dom-adapter%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fmdsal%2Fbinding%2Fdom%2Fadapter%2Finvoke%2FNotificationListenerInvokerTest.java;h=63417f389bb464dd57a45af59b6221ee8d58d33f;hb=03a3788f519241cb41d1527040467137d8ad5595;hp=0000000000000000000000000000000000000000;hpb=8ca975e65ecfff506f49c2696042c24d30984ed5;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 new file mode 100644 index 0000000000..63417f389b --- /dev/null +++ b/binding/mdsal-binding-dom-adapter/src/test/java/org/opendaylight/mdsal/binding/dom/adapter/invoke/NotificationListenerInvokerTest.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.mdsal.binding.dom.adapter.invoke; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.fail; +import static org.mockito.Mockito.mock; + +import com.google.common.collect.ImmutableMap; +import com.google.common.util.concurrent.UncheckedExecutionException; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.WrongMethodTypeException; +import org.junit.Test; +import org.opendaylight.yangtools.yang.binding.Augmentation; +import org.opendaylight.yangtools.yang.binding.Notification; +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)); + } + + @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(expected = WrongMethodTypeException.class) + public void invokeNotification() throws Exception { + 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); + } + + private interface TestPrivateInterface extends NotificationListener, Augmentation { + QName QNAME = QName.create("test", "test"); + void onTestNotificationInterface(TestNotificationInterface notif); + } + + public interface TestNotificationInterface extends Notification { + QName QNAME = QName.create("test", "test"); + } +} \ No newline at end of file