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;
12 import com.google.common.util.concurrent.Futures;
13 import java.lang.invoke.MethodHandle;
14 import java.lang.invoke.MethodHandles;
15 import java.util.concurrent.Future;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.yang.binding.RpcService;
19 public class RpcMethodInvokerWithoutInputTest {
21 private static final TestImplClassWithoutInput TEST_IMPL_CLASS = new TestImplClassWithoutInput();
24 public void invokeOnTest() throws Exception {
25 final MethodHandle methodHandle = MethodHandles.lookup().unreflect(
26 TestImplClassWithoutInput.class.getDeclaredMethod("testMethod", RpcService.class));
27 final RpcMethodInvokerWithoutInput invokerWithoutInput = new RpcMethodInvokerWithoutInput(methodHandle);
28 assertNotNull(invokerWithoutInput.invokeOn(TEST_IMPL_CLASS, null));
31 @Test(expected = InternalError.class)
32 public void invokeOnWithException() throws Exception {
33 final MethodHandle methodHandle = MethodHandles.lookup().unreflect(
34 TestImplClassWithoutInput.class.getDeclaredMethod("testMethodWithException", RpcService.class));
35 final RpcMethodInvokerWithoutInput invokerWithoutInput = new RpcMethodInvokerWithoutInput(methodHandle);
36 invokerWithoutInput.invokeOn(TEST_IMPL_CLASS, null);
39 private static final class TestImplClassWithoutInput implements RpcService {
41 @SuppressWarnings("unused")
42 static Future<?> testMethod(final RpcService testArgument) {
43 return Futures.immediateFuture(null);
46 @SuppressWarnings("unused")
47 static Future<?> testMethodWithException(final RpcService testArgument) throws Exception {
48 throw new InternalError();