package com.publicuhc.pluginframework.routing.proxy;

import com.publicuhc.pluginframework.TestObject;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(PowerMockRunner.class)
public class ReflectionMethodProxyTest
{
    @Test
    public void testInvokeNoArg() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException
    {
        Method method = TestObject.class.getMethod("getNoArg");
        ReflectionMethodProxy proxy = new ReflectionMethodProxy(new TestObject(), method);

        Object returns = proxy.invoke();

        assertThat(returns).isInstanceOf(String.class);
        assertThat(returns).isSameAs(TestObject.TEST_STRING);
    }

    @Test
    public void testInvokeWithArg() throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
    {
        Method method = TestObject.class.getMethod("getArg", String.class);
        ReflectionMethodProxy proxy = new ReflectionMethodProxy(new TestObject(), method);

        Object returns = proxy.invoke(TestObject.TEST_STRING);

        assertThat(returns).isInstanceOf(String.class);
        assertThat(returns).isSameAs(TestObject.TEST_STRING);
    }
}

@@ -349,16 +349,217 @@
 ertThat;
+%0Aimport static org.mockito.Mockito.times;%0Aimport static org.mockito.Mockito.verify;%0Aimport static org.mockito.Mockito.verifyNoMoreInteractions;%0Aimport static org.powermock.api.mockito.PowerMockito.spy;
 %0A%0A@RunWi
@@ -747,32 +747,83 @@
 Exception%0A    %7B%0A
+        TestObject object = spy(new TestObject());%0A
         Method m
@@ -934,32 +934,22 @@
 odProxy(
-new TestO
+o
 bject
-()
 , method
@@ -1108,24 +1108,111 @@
 ST_STRING);%0A
+        verify(object, times(1)).getNoArg();%0A        verifyNoMoreInteractions(object);%0A
     %7D%0A%0A    @
@@ -1330,32 +1330,83 @@
 Exception%0A    %7B%0A
+        TestObject object = spy(new TestObject());%0A
         Method m
@@ -1529,32 +1529,22 @@
 odProxy(
-new TestO
+o
 bject
-()
 , method
@@ -1659,32 +1659,32 @@
 (String.class);%0A
-
         assertTh
@@ -1725,20 +1725,127 @@
 ST_STRING);%0A
+        verify(object, times(1)).getArg(TestObject.TEST_STRING);%0A        verifyNoMoreInteractions(object);%0A
     %7D%0A%7D%0A

verify methods were called