### Question:
DefaultHandlerRegistry implements HandlerRegistry { public RestHandler getRestHandler(String path, String method) { method = method.toUpperCase(); if (path != null) { if (path.startsWith("/")) { path = path.substring(1); } String[] pathParts = StringUtils.splitPreserveAllTokens(path, '/'); Map<String, SortedSet<RestPath>> methods = serviceMethodPathMap.get(pathParts[0]); if (methods != null) { SortedSet<RestPath> paths = methods.get(method); if (paths != null) { for (RestPath restPath : paths) { RestHandler handler = restPath.accept(pathParts); if (handler != null) { return handler; } } } } } return new ErrorRestHandler(new ProtocolException(HttpServletResponse.SC_NOT_IMPLEMENTED, "No service defined for path " + path)); } @Inject  DefaultHandlerRegistry(Injector injector,
                                BeanJsonConverter beanJsonConverter,
                                HandlerExecutionListener executionListener); void addHandlers(Set<Object> handlers); RpcHandler getRpcHandler(JSONObject rpc); RestHandler getRestHandler(String path, String method); Set<String> getSupportedRestServices(); Set<String> getSupportedRpcServices();  }### Answer:
@Test public void testGetHandlerRest() throws Exception { assertNotNull(registry.getRestHandler("/test/", "GET")); }
@Test public void testOverrideHandlerRest() throws Exception { assertNotNull(registry.getRestHandler("/test/overidden/method/", "GET")); }
@Test public void testGetForAliasHandler() { assertNotNull(registry.getRestHandler("/test", "GET")); }
@Test public void testRestHandler_serviceDoesntExist() { RestHandler restHandler = registry.getRestHandler("/makebelieve", "GET"); try { Future<?> future = restHandler.execute(Maps.<String, String[]>newHashMap(), null, null, null); future.get(); fail("Expect exception for missing method"); } catch (ExecutionException t) { assertSame(t.getCause().getClass(), ProtocolException.class); Assert.assertEquals(HttpServletResponse.SC_NOT_IMPLEMENTED, ((ProtocolException) t.getCause()).getCode()); } catch (Throwable t) { fail("Unexpected exception " + t.toString()); } }
@Test public void testNonFutureDispatch() throws Exception { RestHandler handler = registry.getRestHandler("/test", "GET"); Future<?> future = handler.execute(Maps.<String, String[]>newHashMap(), null, null, null); assertEquals(TestHandler.GET_RESPONSE, future.get()); }
@Test public void testFutureDispatch() throws Exception { RestHandler handler = registry.getRestHandler("/test", "POST"); Future<?> future = handler.execute(Maps.<String, String[]>newHashMap(), null, null, null); assertEquals(TestHandler.CREATE_RESPONSE, future.get()); }
@Test public void testRestWithInputClassThatIsntRequestItem() throws Exception { RestHandler handler = registry.getRestHandler("/test/echo", "GET"); String[] value = {"Bob"}; Future<?> future = handler.execute(ImmutableMap.of("value", value), null, null, converter); assertEquals(future.get(), TestHandler.ECHO_PREFIX + "Bob"); }