Fix checkstyle violations in yang-binding
[mdsal.git] / binding / yang-binding / src / test / java / org / opendaylight / yangtools / yang / binding / util / RpcMethodInvokerWithoutInputTest.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
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;
18
19 public class RpcMethodInvokerWithoutInputTest {
20
21     private static final TestImplClassWithoutInput TEST_IMPL_CLASS = new TestImplClassWithoutInput();
22
23     @Test
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));
29     }
30
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);
37     }
38
39     private static final class TestImplClassWithoutInput implements RpcService {
40
41         @SuppressWarnings("unused")
42         static Future<?> testMethod(final RpcService testArgument) {
43             return Futures.immediateFuture(null);
44         }
45
46         @SuppressWarnings("unused")
47         static Future<?> testMethodWithException(final RpcService testArgument) throws Exception {
48             throw new InternalError();
49         }
50     }
51 }