### Question:
BaseProvider { protected Map.Entry<String, Pattern> getRegexEntry(String id) { Map.Entry<String, Pattern> regexEntry = null; for (Map.Entry<String, Pattern> entry : patterns.entrySet()) { Pattern pattern = entry.getValue(); Matcher matcher = pattern.matcher(id); if (matcher.matches()) { String key = entry.getKey(); if (regexEntry == null || key.startsWith(regexEntry.getKey())) { regexEntry = entry; } } } return regexEntry; } BaseProvider(Set<String> propertyIds); Set<String> checkPropertyIds(Set<String> propertyIds); Set<String> getPropertyIds(); Set<String> getCategoryIds();  }### Answer:
@Test public void testComplexMetricParsing() { Set<String> propertyIds = new HashSet<>(); propertyIds.add("metrics/flume/$1.substring(0)/CHANNEL/$2.replaceAll(\"[^-]+\",\"\")EventPutSuccessCount/rate/sum"); propertyIds.add("metrics/yarn/Queue/$1.replaceAll(\"([.])\",\"/\")/AppsCompleted"); propertyIds.add("metrics/yarn/Queue/$1.replaceAll(\",q(\\d+)=\",\"/\").substring(1)/AppsFailed"); TestProvider provider = new TestProvider(propertyIds); Entry<String, Pattern> entry = provider.getRegexEntry("metrics/flume/flume"); assertEquals("metrics/flume/$1", entry.getKey()); assertEquals("metrics/flume/(\\S*)", entry.getValue().pattern()); entry = provider.getRegexEntry("metrics/flume/flume/CHANNEL"); assertEquals("metrics/flume/$1/CHANNEL", entry.getKey()); assertEquals("metrics/flume/(\\S*)/CHANNEL", entry.getValue().pattern()); entry = provider.getRegexEntry("metrics/flume/flume/CHANNEL/EventPutSuccessCount"); assertEquals("metrics/flume/$1/CHANNEL/$2EventPutSuccessCount", entry.getKey()); assertEquals("metrics/flume/(\\S*)/CHANNEL/(\\S*)EventPutSuccessCount", entry.getValue().pattern()); entry = provider.getRegexEntry("metrics/flume/flume/CHANNEL/EventPutSuccessCount/rate"); assertEquals("metrics/flume/$1/CHANNEL/$2EventPutSuccessCount/rate", entry.getKey()); assertEquals( "metrics/flume/(\\S*)/CHANNEL/(\\S*)EventPutSuccessCount/rate", entry.getValue().pattern()); entry = provider.getRegexEntry("metrics/yarn/Queue/root/AppsCompleted"); assertEquals("metrics/yarn/Queue/$1.replaceAll(\"([.])\",\"/\")/AppsCompleted", entry.getKey()); assertEquals( "metrics/yarn/Queue/(\\S*)/AppsCompleted", entry.getValue().pattern()); entry = provider.getRegexEntry("metrics/yarn/Queue/root/default/AppsCompleted"); assertEquals("metrics/yarn/Queue/$1.replaceAll(\"([.])\",\"/\")/AppsCompleted", entry.getKey()); assertEquals( "metrics/yarn/Queue/(\\S*)/AppsCompleted", entry.getValue().pattern()); entry = provider.getRegexEntry("metrics/yarn/Queue/root/default/AppsFailed"); assertEquals("metrics/yarn/Queue/$1.replaceAll(\",q(\\d+)=\",\"/\").substring(1)/AppsFailed", entry.getKey()); assertEquals( "metrics/yarn/Queue/(\\S*)/AppsFailed", entry.getValue().pattern()); }