package org.wisdom.api.router;

import org.junit.Test;
import org.wisdom.api.Controller;
import org.wisdom.api.http.HttpMethod;
import org.wisdom.api.http.Result;

import java.util.List;

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

/**
 * Check the collection of the routes from @Route
 */
public class RouteAnnotationCollectionTest {


    @Test
    public void testWithClassWithoutRoutes() {
        Controller instance = new Controller() {
            @Override
            public List<Route> routes() {
                return null;
            }
        };
        List<Route> routes = RouteUtils.collectRouteFromControllerAnnotations(instance);
        assertThat(routes).isEmpty();
    }

    @Test
    public void testWithClassWithRoutes() {
        Controller instance = new Controller() {

            @org.wisdom.api.annotations.Route(method= HttpMethod.GET, uri = "/")
            public Result method1() {
                return null;
            }

            @org.wisdom.api.annotations.Route(method= HttpMethod.POST, uri = "/")
            public Result method2() {
                return null;
            }

            @Override
            public List<Route> routes() {
                return null;
            }
        };
        List<Route> routes = RouteUtils.collectRouteFromControllerAnnotations(instance);
        assertThat(routes).hasSize(2);
        assertThat(routes.get(0).getHttpMethod()).isEqualTo(HttpMethod.GET);
        assertThat(routes.get(0).getUrl()).isEqualTo("/");
        assertThat(routes.get(0).getControllerObject()).isEqualTo(instance);
        assertThat(routes.get(0).getControllerMethod().getName()).isEqualTo("method1");
        assertThat(routes.get(1).getHttpMethod()).isEqualTo(HttpMethod.POST);
        assertThat(routes.get(1).getUrl()).isEqualTo("/");
        assertThat(routes.get(1).getControllerObject()).isEqualTo(instance);
        assertThat(routes.get(1).getControllerMethod().getName()).isEqualTo("method2");
    }
}

@@ -1380,16 +1380,99 @@
 ize(2);%0A
+        if (%22method1%22.equals(routes.get(0).getControllerMethod().getName())) %7B%0A    
         
@@ -1540,32 +1540,36 @@
 d.GET);%0A        
+  
+  
 assertThat(route
@@ -1595,32 +1595,36 @@
 isEqualTo(%22/%22);%0A
+    
         assertTh
@@ -1684,32 +1684,36 @@
 tance);%0A        
+    
 assertThat(route
@@ -1776,32 +1776,36 @@
 hod1%22);%0A        
+  
+  
 assertThat(route
@@ -1858,32 +1858,36 @@
 .POST);%0A        
+    
 assertThat(route
@@ -1921,32 +1921,36 @@
 o(%22/%22);%0A        
+ 
+   
 assertThat(route
@@ -2002,32 +2002,36 @@
 tance);%0A        
+   
+ 
 assertThat(route
@@ -2090,20 +2090,682 @@
 %22method2%22);%0A
+        %7D else %7B%0A            assertThat(routes.get(1).getHttpMethod()).isEqualTo(HttpMethod.GET);%0A            assertThat(routes.get(1).getUrl()).isEqualTo(%22/%22);%0A            assertThat(routes.get(1).getControllerObject()).isEqualTo(instance);%0A            assertThat(routes.get(1).getControllerMethod().getName()).isEqualTo(%22method1%22);%0A            assertThat(routes.get(0).getHttpMethod()).isEqualTo(HttpMethod.POST);%0A            assertThat(routes.get(0).getUrl()).isEqualTo(%22/%22);%0A            assertThat(routes.get(0).getControllerObject()).isEqualTo(instance);%0A            assertThat(routes.get(0).getControllerMethod().getName()).isEqualTo(%22method2%22);%0A        %7D%0A
     %7D%0A%7D%0A

Improve test robustness.