### Question:
ConfigurationFactory { static Set extractPropertyTokens(String sourceDocument) { Set propertyTokens = new HashSet(); Pattern pattern = Pattern.compile("\\$\\{.+?\\}"); Matcher matcher = pattern.matcher(sourceDocument); while (matcher.find()) { String token = matcher.group(); propertyTokens.add(token); } return propertyTokens; } private  ConfigurationFactory(); static Configuration parseConfiguration(final File file); static Configuration parseConfiguration(final URL url); static Configuration parseConfiguration(); static Configuration parseConfiguration(final InputStream inputStream);  }### Answer:
@Test public void testMatchPropertyTokensProperlyFormedUrl() { String example="<terracottaConfig url=\"${serverAndPort}\"/>"; Set propertyTokens = ConfigurationFactory.extractPropertyTokens(example); assertEquals(1, propertyTokens.size()); String firstPropertyToken = (String) (propertyTokens.toArray())[0]; assertEquals("${serverAndPort}", firstPropertyToken); }
@Test public void testMatchPropertyTokensProperlyFormed() { String example = "<cacheManagerPeerProviderFactory class=\"net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory\"" + "properties=\"peerDiscovery=automatic, " + "multicastGroupAddress=${multicastAddress}, " + "multicastGroupPort=4446, timeToLive=1\"/>"; Set propertyTokens = ConfigurationFactory.extractPropertyTokens(example); assertEquals(1, propertyTokens.size()); String firstPropertyToken = (String) (propertyTokens.toArray())[0]; assertEquals("${multicastAddress}", firstPropertyToken); }
@Test public void testMatchPropertyTokensProperlyFormedUrl() { String example = "<terracottaConfig url=\"${serverAndPort}\"/>"; Set propertyTokens = ConfigurationFactory.extractPropertyTokens(example); assertEquals(1, propertyTokens.size()); String firstPropertyToken = (String) (propertyTokens.toArray())[0]; assertEquals("${serverAndPort}", firstPropertyToken); }
@Test public void testMatchPropertyTokensProperlyFormedTwo() { String example = "<cacheManagerPeerProviderFactory class=\"net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory\"" + "properties=\"peerDiscovery=automatic, " + "multicastGroupAddress=${multicastAddress}\n, " + "multicastGroupPort=4446, timeToLive=${multicastAddress}\"/>"; Set propertyTokens = ConfigurationFactory.extractPropertyTokens(example); assertEquals(1, propertyTokens.size()); String firstPropertyToken = (String) (propertyTokens.toArray())[0]; assertEquals("${multicastAddress}", firstPropertyToken); }
@Test public void testMatchPropertyTokensProperlyFormedTwoUnique() { String example = "<cacheManagerPeerProviderFactory class=\"net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory\"" + "properties=\"peerDiscovery=automatic, " + "multicastGroupAddress=${multicastAddress}\n, " + "multicastGroupPort=4446, timeToLive=${multicastAddress1}\"/>"; Set propertyTokens = ConfigurationFactory.extractPropertyTokens(example); assertEquals(2, propertyTokens.size()); }
@Test public void testMatchPropertyTokensNotClosed() { String example = "<cacheManagerPeerProviderFactory class=\"net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory\"" + "properties=\"peerDiscovery=automatic, " + "multicastGroupAddress=${multicastAddress\n, " + "multicastGroupPort=4446, timeToLive=${multicastAddress\"/>"; Set propertyTokens = ConfigurationFactory.extractPropertyTokens(example); assertEquals(0, propertyTokens.size()); }