ConfigPropertySource extends EnumerablePropertySource<Config> { @Override public String[] getPropertyNames() { Set<String> propertyNames = this.source.getPropertyNames(); if (propertyNames.isEmpty()) { return EMPTY_ARRAY; } return propertyNames.toArray(new String[propertyNames.size()]); } ConfigPropertySource(String name, Config source); @Override String[] getPropertyNames(); @Override Object getProperty(String name); void addChangeListener(ConfigChangeListener listener);  }
@Test public void testGetPropertyNames() throws Exception { String somePropertyName = "somePropertyName"; String anotherPropertyName = "anotherPropertyName"; Set<String> somePropertyNames = Sets.newHashSet(somePropertyName, anotherPropertyName); when(someConfig.getPropertyNames()).thenReturn(somePropertyNames); String[] result = configPropertySource.getPropertyNames(); verify(someConfig, times(1)).getPropertyNames(); assertArrayEquals(somePropertyNames.toArray(), result); }
@Test public void testGetEmptyPropertyNames() throws Exception { when(someConfig.getPropertyNames()).thenReturn(Sets.<String>newHashSet()); assertEquals(0, configPropertySource.getPropertyNames().length); }