RouterImpl implements Router { @Override public Route getRouteFor(String httpMethod, String uri) { if (routes == null) { throw new IllegalStateException( "Attempt to get route when routes not compiled"); } for (Route route : routes) { if (route.matches(httpMethod, uri)) { return route; } } return null; } @Inject  RouterImpl(Injector injector,
                      NinjaProperties ninjaProperties,
                      WebSockets webSockets,
                      Provider<RouteBuilderImpl> routeBuilderImplProvider); @Override Route getRouteFor(String httpMethod, String uri); @Override String getReverseRoute(
            Class<?> controllerClass,
            String controllerMethodName); @Override String getReverseRoute(Class<?> controllerClass,
            String controllerMethodName,
            Object... parameterMap); @Override String getReverseRoute(Class<?> controllerClass,
            String controllerMethodName,
            Map<String, Object> parameterMap); @Override String getReverseRoute(
            Class<?> controllerClass,
            String controllerMethodName,
            Optional<Map<String, Object>> parameterMap); @Override String getReverseRoute(MethodReference controllerMethodRef); @Override String getReverseRoute(MethodReference controllerMethodRef, Map<String, Object> parameterMap); @Override String getReverseRoute(MethodReference controllerMethodRef, Object ... parameterMap); @Override String getReverseRoute(MethodReference controllerMethodRef, Optional<Map<String, Object>> parameterMap); @Override void compileRoutes(); @Override List<Route> getRoutes(); @Override RouteBuilder GET(); @Override RouteBuilder POST(); @Override RouteBuilder PUT(); @Override RouteBuilder DELETE(); @Override RouteBuilder OPTIONS(); @Override RouteBuilder HEAD(); @Override RouteBuilder WS(); @Override RouteBuilder METHOD(String method); @Override Optional<Route> getRouteForControllerClassAndMethod(
            Class<?> controllerClass,
            String controllerMethodName);  }
@Test public void getPathParametersEncodedWithNoPathParams() { Route route = router.getRouteFor("GET", "/testroute"); Map<String,String> pathParameters = route.getPathParametersEncoded("/testroute"); assertThat(pathParameters, aMapWithSize(0)); }
@Test public void routeForAnyInstanceMethodReference() { Route route = router.getRouteFor("GET", "/any_instance_method_ref"); Result result = route.getFilterChain().next(null); assertThat(result.getStatusCode(), is(201)); }
@Test public void routeForAnyInstanceMethodReferenceThrowsException() { Route route = router.getRouteFor("GET", "/any_instance_method_ref_exception"); try { Result result = route.getFilterChain().next(null); fail(); } catch (Exception e) { assertThat(e.getCause().getMessage(), is("test")); } }
@Test public void routeForAnyInstanceMethodReference2() { Route route = router.getRouteFor("GET", "/any_instance_method_ref2"); Result result = route.getFilterChain().next(null); assertThat(result.getStatusCode(), is(201)); }
@Test public void routeForSpecificInstanceMethodReference() { Route route = router.getRouteFor("GET", "/specific_instance_method_ref"); Result result = route.getFilterChain().next(null); assertThat(result.getRenderable(), is("Hi!")); }
@Test public void routeForSpecificInstanceMethodReferenceWithAnnotations() { Context context = mock(Context.class); when(context.getParameter("status")).thenReturn("207"); when(context.getValidation()).thenReturn(new ValidationImpl()); Route route = router.getRouteFor("GET", "/specific_instance_method_ref_annotations"); Result result = route.getFilterChain().next(context); assertThat(result.getStatusCode(), is(207)); assertThat(result.getRenderable(), is("Hi!")); }
@Test public void routeForAnonymoumsMethodReference() { Route route = router.getRouteFor("GET", "/anonymous_method_ref"); Result result = route.getFilterChain().next(null); assertThat(result.getStatusCode(), is(202)); }
@Test public void routeForAnonymoumsMethodReferenceWithCaptured() { Context context = mock(Context.class); Route route = router.getRouteFor("GET", "/anonymous_method_ref_captured"); Result result = route.getFilterChain().next(context); assertThat(result.getStatusCode(), is(208)); }
@Test public void routeForAnonymoumsMethodReferenceWithContext() { Context context = mock(Context.class); when(context.getParameterAsInteger("status")).thenReturn(206); Route route = router.getRouteFor("GET", "/anonymous_method_ref_context"); Result result = route.getFilterChain().next(context); assertThat(result.getStatusCode(), is(206)); }
@Test public void routeForAnonymoumsClassInstance() { Route route = router.getRouteFor("GET", "/anonymous_class"); Result result = route.getFilterChain().next(null); assertThat(result.getStatusCode(), is(203)); }
@Test public void routeForAnonymoumsClassInstanceWithAnnotations() { Context context = mock(Context.class); when(context.getParameter("status")).thenReturn("205"); when(context.getValidation()).thenReturn(new ValidationImpl()); Route route = router.getRouteFor("GET", "/anonymous_class_annotations"); Result result = route.getFilterChain().next(context); assertThat(result.getStatusCode(), is(205)); }