package com.publicuhc.pluginframework.routing;

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 DefaultMethodProxyTest
{
    @Test
    public void testInvokeNoArg() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException
    {
        Method method = TestObject.class.getMethod("getNoArg");
        DefaultMethodProxy proxy = new DefaultMethodProxy(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);
        DefaultMethodProxy proxy = new DefaultMethodProxy(new TestObject(), method);

        Object returns = proxy.invoke("test");

        assertThat(returns).isInstanceOf(String.class);
        assertThat(returns).isSameAs("test");
    }

    public class TestObject
    {
        public static final String TEST_STRING = "TEST STRING";

        public String getNoArg()
        {
            return TEST_STRING;
        }

        public String getArg(String arg)
        {
            return arg;
        }
    }
}

@@ -41,16 +41,65 @@
 uting;%0A%0A
+import com.publicuhc.pluginframework.TestObject;%0A
 import o
@@ -1315,284 +1315,7 @@
    %7D
-%0A%0A    public class TestObject%0A    %7B%0A        public static final String TEST_STRING = %22TEST STRING%22;%0A%0A        public String getNoArg()%0A        %7B%0A            return TEST_STRING;%0A        %7D%0A%0A        public String getArg(String arg)%0A        %7B%0A            return arg;%0A        %7D%0A    %7D
 %0A%7D%0A

use the generic testobject