RouterImpl implements Router { @Override public String getReverseRoute( Class<?> controllerClass, String controllerMethodName) { Optional<Map<String, Object>> parameterMap = Optional.empty(); return getReverseRoute(controllerClass, controllerMethodName, parameterMap); } @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 getReverseRouteWithNoContextPathWorks() { String contextPath = ""; when(ninjaProperties.getContextPath()).thenReturn(contextPath); String route = router.getReverseRoute(TestController.class, "index"); assertThat(route, is("/testroute")); }
@Test public void getReverseRouteContextPathWorks() { String contextPath = "/myappcontext"; when(ninjaProperties.getContextPath()).thenReturn(contextPath); String route = router.getReverseRoute(TestController.class, "index"); assertThat(route, is("/myappcontext/testroute")); }
@Test public void getReverseRouteWithRegexWorks() { String contextPath = ""; when(ninjaProperties.getContextPath()).thenReturn(contextPath); String route = router.getReverseRoute( TestController.class, "user", "email", "me@me.com", "id", 10000); assertThat(route, is("/user/me@me.com/10000")); }
@Test public void getReverseRouteWithRegexAndQueryParametersWorks() { String contextPath = ""; when(ninjaProperties.getContextPath()).thenReturn(contextPath); String route = router.getReverseRoute( TestController.class, "user", "email", "me@me.com", "id", 10000, "q", "froglegs"); assertThat(route, equalTo("/user/me@me.com/10000?q=froglegs")); }
@Test public void getReverseRouteWithMultipleRegexWorks() { String contextPath = ""; when(ninjaProperties.getContextPath()).thenReturn(contextPath); String route = router.getReverseRoute(TestController.class, "entry", "userId", 1, "entryId", 100); assertThat(route, equalTo("/u1/entries/100")); }
@Test public void getReverseRouteWithMethodReference() { String contextPath = ""; when(ninjaProperties.getContextPath()).thenReturn(contextPath); String route = router.getReverseRoute(TestController.class, "ref"); String route2 = router.getReverseRoute(new MethodReference(TestController.class, "ref")); assertThat(route, is("/ref")); assertThat(route2, is("/ref")); }