package com.bastengao.struts2.freeroute;

import com.bastengao.struts2.freeroute.annotation.Route;
import org.junit.Assert;
import org.junit.Test;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

/**
 * @author bastengao
 * @date 13-3-2 09:48
 */
public class RouteMappingTest {

    @Test
    public void mockAnnotationTest() {
        Route route = mock(Route.class);
        when(route.value()).thenReturn("/path");

        Assert.assertEquals("/path", route.value());
    }
}

@@ -35,16 +35,78 @@
 route;%0A%0A
+import com.bastengao.struts2.freeroute.annotation.MethodType;%0A
 import c
@@ -154,16 +154,16 @@
 .Route;%0A
-
 import o
@@ -203,16 +203,50 @@
 .Test;%0A%0A
+import java.lang.reflect.Method;%0A%0A
 import s
@@ -542,16 +542,16 @@
 ath%22);%0A%0A
-
         
@@ -600,11 +600,1487 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void newRouteMapping() %7B%0A        Route route = mockRoute(%22/path%22);%0A%0A        Class clazz = RouteMappingTest.class;%0A        Method method = ReflectUtil.methodOf(clazz, %22newRouteMapping%22);%0A%0A        RouteMapping routeMapping = new RouteMapping(route, clazz, method);%0A%0A        Assert.assertSame(clazz, routeMapping.getAction());%0A        Assert.assertSame(method, routeMapping.getMethod());%0A        Assert.assertEquals(0, routeMapping.getHttpMethods().size());%0A        Assert.assertEquals(0, routeMapping.getHttpParams().size());%0A        Assert.assertFalse(routeMapping.hasPathVariables());%0A%0A        ActionInfo actionInfo = routeMapping.toAction();%0A        Assert.assertNotNull(actionInfo);%0A        Assert.assertEquals(%22%22, actionInfo.getNamespace());%0A        Assert.assertEquals(%22path%22+%22#%22+ method.getName() + %22@%22 + clazz.getName(), actionInfo.getActionName());%0A    %7D%0A%0A    private static Route mockRoute(String value, MethodType%5B%5D methods, String%5B%5D params) %7B%0A        Route route = mock(Route.class);%0A        when(route.value()).thenReturn(value);%0A        when(route.method()).thenReturn(methods);%0A        when(route.params()).thenReturn(params);%0A        return route;%0A    %7D%0A%0A    private static Route mockRoute(String value) %7B%0A        Route route = mock(Route.class);%0A        when(route.value()).thenReturn(value);%0A        when(route.method()).thenReturn(new MethodType%5B%5D%7B%7D);%0A        when(route.params()).thenReturn(new String%5B%5D%7B%7D);%0A        return route;%0A    %7D
 %0A%7D%0A

test new RouteMapping