### Question:
ResourceManagerImpl implements ResourceManager { @Override public LookupResult lookupResource(Method method, String path, String action) { List<PathItem> pathItems = Arrays.stream(path.replaceAll(" .map(s -> s.isEmpty() ? "/" : s).map(QueryStringDecoder::decodeComponent).map(PathItem::fromString).collect(Collectors.toList()); return resourceTree.find(method, pathItems, action); } ResourceManagerImpl(); @Override void registerResource(String context, ResourceHandler handler); @Override LookupResult lookupResource(Method method, String path, String action);  }### Answer:
@Test public void testLookupHandler() { registerHandler("root", "CompaniesHandler", "/companies", "/companies/{company}", "/companies/{company}/{id}"); registerHandler("root", "StocksHandler", "/stocks/{stock}", "/stocks/{stock}/{currency}"); registerHandler("root", "DirectorsHandler", "/directors", "/directors/director", "/directors/director/{personId}"); registerHandler("root", "InfoHandler", "/info", "/info/jvm", "/info/jvm/{format}", "/info/{format}/{encoding}"); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/root/dummy").getStatus()); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/fake/").getStatus()); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/").getStatus()); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/root/stocks").getStatus()); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/root/stocks/2/USD/1").getStatus()); assertInvocation(resourceManager.lookupResource(GET, "/root/stocks/2"), "StocksHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/stocks/2/USD"), "StocksHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/directors"), "DirectorsHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/directors/director"), "DirectorsHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/directors/director/John"), "DirectorsHandler"); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/root/directors/1345").getStatus()); assertEquals(NOT_FOUND, resourceManager.lookupResource(GET, "/root/directors/director/Tim/123").getStatus()); assertInvocation(resourceManager.lookupResource(GET, "/root/companies"), "CompaniesHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/info"), "InfoHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/info/jvm"), "InfoHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/info/jvm/json"), "InfoHandler"); assertInvocation(resourceManager.lookupResource(GET, "/root/info/json/zip"), "InfoHandler"); }
@Test public void testLookupStatuses() { registerHandler("ctx", "handler1", "/items/{item}"); registerHandlerWithAction("ctx", new Method[]{GET}, "handler2", "clear", "/items/{item}/{sub}"); LookupResult lookupResult = resourceManager.lookupResource(GET, "/invalid"); assertEquals(NOT_FOUND, lookupResult.getStatus()); lookupResult = resourceManager.lookupResource(GET, "/ctx/items/1"); assertEquals(FOUND, lookupResult.getStatus()); lookupResult = resourceManager.lookupResource(DELETE, "/ctx/items/1"); assertEquals(INVALID_METHOD, lookupResult.getStatus()); lookupResult = resourceManager.lookupResource(GET, "/ctx/items/1/1", "clear"); assertEquals(FOUND, lookupResult.getStatus()); lookupResult = resourceManager.lookupResource(GET, "/ctx/items/1/1"); assertEquals(INVALID_ACTION, lookupResult.getStatus()); lookupResult = resourceManager.lookupResource(GET, "/ctx/items/1/1", "invalid"); assertEquals(INVALID_ACTION, lookupResult.getStatus()); lookupResult = resourceManager.lookupResource(GET, "/ctx/items/1", "invalid"); assertEquals(INVALID_ACTION, lookupResult.getStatus()); }