### Question:
ConsulConfigSource extends EnabledConfigSource { @Override public String getValue(String key) { if (key.startsWith(KEY_PREFIX)) { return null; } TimedEntry entry = cache.get(key); if (entry == null || entry.isExpired()) { log.log(Level.FINE, "load {0} from consul", key); GetValue value = null; try { value = getClient().getKVValue(getPrefix() + key).getValue(); } catch (Exception e) { log.log(Level.WARNING, "consul getKVValue failed: {0}", e.getMessage()); if (entry != null) { return entry.getValue(); } } if (value == null) { cache.put(key, new TimedEntry(null)); return null; } String decodedValue = value.getDecodedValue(); cache.put(key, new TimedEntry(decodedValue)); return decodedValue; } return entry.getValue(); } ConsulConfigSource();  ConsulConfigSource(ConsulClient client); @Override Map<String, String> getPropertiesIfEnabled(); @Override String getValue(String key); @Override String getName();  }### Answer:
@Test void testGetProperties_one() { GetValue value = new GetValue(); value.setValue(Base64.getEncoder().encodeToString("hello".getBytes())); when(configSource.client.getKVValue(anyString())).thenReturn(new Response<GetValue>(value, 0L, true, 0L)); configSource.getValue("test"); assertEquals(1, configSource.getProperties().size()); }
@Test void testGetValue_null() { when(configSource.client.getKVValue(anyString())).thenReturn(new Response<GetValue>(null, 0L, true, 0L)); assertNull(configSource.getValue("test")); }
@Test void testGetValue() { GetValue value = new GetValue(); value.setValue(Base64.getEncoder().encodeToString("hello".getBytes())); when(configSource.client.getKVValue(anyString())).thenReturn(new Response<GetValue>(value, 0L, true, 0L)); assertEquals("hello", configSource.getValue("test")); }
@Test void testGetValue_cache() { GetValue value = new GetValue(); value.setValue(Base64.getEncoder().encodeToString("hello".getBytes())); when(configSource.client.getKVValue(anyString())).thenReturn(new Response<GetValue>(value, 0L, true, 0L)); configSource.getValue("test"); configSource.getValue("test"); verify(configSource.client, times(1)).getKVValue("test"); }
@Test void testGetValue_exception() { when(configSource.client.getKVValue(anyString())).thenThrow(RuntimeException.class); assertNull(configSource.getValue("test")); }
@Test void testGetValue_prefix() { System.setProperty("configsource.consul.prefix", "myprefix"); configSource = new ConsulConfigSource(mock(ConsulClient.class)); GetValue value = new GetValue(); value.setValue(Base64.getEncoder().encodeToString("hello".getBytes())); when(configSource.client.getKVValue(anyString())).thenReturn(new Response<GetValue>(value, 0L, true, 0L)); configSource.getValue("test"); System.clearProperty("configsource.consul.prefix"); verify(configSource.client, times(1)).getKVValue("myprefix/test"); }