RouteCompilerImpl implements RouteCompiler { public static List<String> detectVariables(Route route) { Pattern pattern = Pattern.compile("\\{(\\w+)\\}"); Matcher matcher = pattern.matcher(route.getPath()); List<String> variables = new ArrayList<>(); while (matcher.find()) { variables.add(matcher.group(1)); } return variables; }  CompiledRoute compile(Route route); static List<String> detectVariables(Route route); static String compileRegex(Route route, List<String> variables); static String quote(String str);  }
@Test public void testDetectVariables() { assertEquals( "-> assert none variables", RouteCompilerImpl.detectVariables( new Route("github.com/mr5/android-router", Activity.class) ).size(), 0 ); assertEquals( "-> assert 1 variable", RouteCompilerImpl.detectVariables( new Route("github.com/mr5/{repository}", Activity.class) ).size(), 1 ); assertEquals( "-> assert 2 variables", RouteCompilerImpl.detectVariables( new Route("github.com/{vendor}/{repository}", Activity.class) ).size(), 2 ); assertEquals( "-> assert variable name detecting correctly.", RouteCompilerImpl.detectVariables( new Route("github.com/{vendor}/{repository}", Activity.class) ), Arrays.asList("vendor", "repository") ); assertEquals( "-> assert sub domain detecting correctly.", RouteCompilerImpl.detectVariables( new Route("{vendor}.github.com/{page}", Activity.class) ), Arrays.asList("vendor", "page") ); assertEquals( "-> assert route with format correctly.", RouteCompilerImpl.detectVariables( new Route("{vendor}.github.com/{page}.{format}", Activity.class) ), Arrays.asList("vendor", "page", "format") ); }