@Override
   public LookupResult lookupResource(Method method, String path, String action) {
      List<PathItem> pathItems = new ArrayList<>();
      final int l = path.length();
      int s = 0, pos = 0;
      while (pos < l) {
         char ch = path.charAt(pos);
         if (ch == '/') {
            if (pos == 0) {
               pathItems.add(ROOT);
            } else if (pos > s) {
               pathItems.add(new StringPathItem(QueryStringDecoder.decodeComponent(path.substring(s, pos))));
            }
            s = ++pos;
         } else {
            ++pos;
         }
      }
      if (s < pos) {
         pathItems.add(new StringPathItem(QueryStringDecoder.decodeComponent(path.substring(s))));
      }
      return resourceTree.find(method, pathItems, action);
   }
@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");
   }