### Question:
ConfigGetParameterHandler { public String getString(String key) { String activatedString = getStringFromCache(activatedConfigsCache, key); if (activatedString != null) { return activatedString; } String defaultsString = getStringFromCache(defaultConfigsCache, key); if (defaultsString != null) { return defaultsString; } logParameterValueDoesNotExist(key, "String"); return DEFAULT_VALUE_FOR_STRING; } ConfigGetParameterHandler(
      ConfigCacheClient activatedConfigsCache, ConfigCacheClient defaultConfigsCache); String getString(String key); boolean getBoolean(String key); byte[] getByteArray(String key); double getDouble(String key); long getLong(String key); FirebaseRemoteConfigValue getValue(String key); Set<String> getKeysByPrefix(String prefix); Map<String, FirebaseRemoteConfigValue> getAll(); @VisibleForTesting(otherwise = VisibleForTesting.PACKAGE_PRIVATE)
  static final Charset FRC_BYTE_ARRAY_ENCODING; }### Answer:
@Test public void getString_getBlockingFails_returnsEmptyString() { loadCacheWithConfig(mockActivatedCache, null); loadCacheWithConfig(mockDefaultsCache, null); String stringValue = getHandler.getString(STRING_KEY); assertThat(stringValue).isEmpty(); }
@Test public void getString_activatedAndDefaultsKeysExist_returnsActivatedValue() throws Exception { loadActivatedCacheWithMap(ImmutableMap.of(STRING_KEY, ACTIVATED_STRING_VALUE)); loadDefaultsCacheWithMap(ImmutableMap.of(STRING_KEY, DEFAULTS_STRING_VALUE)); String stringValue = getHandler.getString(STRING_KEY); assertThat(stringValue).isEqualTo(ACTIVATED_STRING_VALUE); }
@Test public void getString_noActivatedKeyButDefaultsKeyExists_returnsDefaultsValue() throws Exception { loadActivatedCacheWithMap(ImmutableMap.of()); loadDefaultsCacheWithMap(ImmutableMap.of(STRING_KEY, DEFAULTS_STRING_VALUE)); String stringValue = getHandler.getString(STRING_KEY); assertThat(stringValue).isEqualTo(DEFAULTS_STRING_VALUE); }
@Test public void getString_activatedAndDefaultsKeysDoNotExist_returnsStaticDefault() throws Exception { loadActivatedCacheWithMap(ImmutableMap.of()); loadDefaultsCacheWithMap(ImmutableMap.of()); String stringValue = getHandler.getString(STRING_KEY); assertThat(stringValue).isEqualTo(DEFAULT_VALUE_FOR_STRING); }
@Test public void getString_activatedKeyExistsAndNoDefaultsConfigs_returnsActivatedValue() throws Exception { loadActivatedCacheWithMap(ImmutableMap.of(STRING_KEY, ACTIVATED_STRING_VALUE)); loadCacheWithConfig(mockDefaultsCache, null); String stringValue = getHandler.getString(STRING_KEY); assertThat(stringValue).isEqualTo(ACTIVATED_STRING_VALUE); }
@Test public void getString_noActivatedConfigsButDefaultsKeyExists_returnsDefaultsValue() throws Exception { loadCacheWithConfig(mockActivatedCache, null); loadDefaultsCacheWithMap(ImmutableMap.of(STRING_KEY, DEFAULTS_STRING_VALUE)); String stringValue = getHandler.getString(STRING_KEY); assertThat(stringValue).isEqualTo(DEFAULTS_STRING_VALUE); }
@Test public void getString_activatedAndDefaultsConfigsDoNotExist_returnsStaticDefault() { loadCacheWithConfig(mockActivatedCache, null); loadCacheWithConfig(mockDefaultsCache, null); String stringValue = getHandler.getString(STRING_KEY); assertThat(stringValue).isEqualTo(DEFAULT_VALUE_FOR_STRING); }
@Test public void getString_activatedStillLoadingFromDisk_blocksAndReturnsActivatedValue() throws Exception { loadActivatedAsyncCacheWithIncompleteTask(); loadActivatedBlockingCacheWith(ImmutableMap.of(STRING_KEY, ACTIVATED_STRING_VALUE)); String stringValue = getHandler.getString(STRING_KEY); assertThat(stringValue).isEqualTo(ACTIVATED_STRING_VALUE); }