### Question:
ConfigGetParameterHandler { public boolean getBoolean(String key) { String activatedString = getStringFromCache(activatedConfigsCache, key); if (activatedString != null) { if (TRUE_REGEX.matcher(activatedString).matches()) { return true; } else if (FALSE_REGEX.matcher(activatedString).matches()) { return false; } } String defaultsString = getStringFromCache(defaultConfigsCache, key); if (defaultsString != null) { if (TRUE_REGEX.matcher(defaultsString).matches()) { return true; } else if (FALSE_REGEX.matcher(defaultsString).matches()) { return false; } } logParameterValueDoesNotExist(key, "Boolean"); return DEFAULT_VALUE_FOR_BOOLEAN; } 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 getBoolean_activatedAndDefaultsKeysExist_returnsActivatedValue() throws Exception { loadActivatedCacheWithMap(ImmutableMap.of(BOOLEAN_KEY, ACTIVATED_BOOLEAN_STRING_VALUE)); loadDefaultsCacheWithMap(ImmutableMap.of(BOOLEAN_KEY, DEFAULTS_BOOLEAN_STRING_VALUE)); boolean booleanValue = getHandler.getBoolean(BOOLEAN_KEY); assertThat(booleanValue).isEqualTo(ACTIVATED_BOOLEAN_VALUE); }
@Test public void getBoolean_noActivatedKeyButDefaultsKeyExists_returnsDefaultsValue() throws Exception { loadActivatedCacheWithMap(ImmutableMap.of()); loadDefaultsCacheWithMap(ImmutableMap.of(BOOLEAN_KEY, DEFAULTS_BOOLEAN_STRING_VALUE)); boolean booleanValue = getHandler.getBoolean(BOOLEAN_KEY); assertThat(booleanValue).isEqualTo(DEFAULTS_BOOLEAN_VALUE); }
@Test public void getBoolean_activatedAndDefaultsKeysDoNotExist_returnsStaticDefault() throws Exception { loadActivatedCacheWithMap(ImmutableMap.of()); loadDefaultsCacheWithMap(ImmutableMap.of()); boolean booleanValue = getHandler.getBoolean(BOOLEAN_KEY); assertThat(booleanValue).isEqualTo(DEFAULT_VALUE_FOR_BOOLEAN); }
@Test public void getBoolean_activatedKeyExistsAndNoDefaultsConfigs_returnsActivatedValue() throws Exception { loadActivatedCacheWithMap(ImmutableMap.of(BOOLEAN_KEY, ACTIVATED_BOOLEAN_STRING_VALUE)); loadCacheWithConfig(mockDefaultsCache, null); boolean booleanValue = getHandler.getBoolean(BOOLEAN_KEY); assertThat(booleanValue).isEqualTo(ACTIVATED_BOOLEAN_VALUE); }
@Test public void getBoolean_noActivatedConfigsButDefaultsKeyExists_returnsDefaultsValue() throws Exception { loadCacheWithConfig(mockActivatedCache, null); loadDefaultsCacheWithMap(ImmutableMap.of(BOOLEAN_KEY, DEFAULTS_BOOLEAN_STRING_VALUE)); boolean booleanValue = getHandler.getBoolean(BOOLEAN_KEY); assertThat(booleanValue).isEqualTo(DEFAULTS_BOOLEAN_VALUE); }
@Test public void getBoolean_activatedAndDefaultsConfigsDoNotExist_returnsStaticDefault() { loadCacheWithConfig(mockActivatedCache, null); loadCacheWithConfig(mockDefaultsCache, null); boolean booleanValue = getHandler.getBoolean(BOOLEAN_KEY); assertThat(booleanValue).isEqualTo(DEFAULT_VALUE_FOR_BOOLEAN); }
@Test public void getBoolean_activatedStillLoadingFromDisk_blocksAndReturnsActivatedValue() throws Exception { loadActivatedAsyncCacheWithIncompleteTask(); loadActivatedBlockingCacheWith(ImmutableMap.of(BOOLEAN_KEY, ACTIVATED_BOOLEAN_STRING_VALUE)); boolean booleanValue = getHandler.getBoolean(BOOLEAN_KEY); assertThat(booleanValue).isEqualTo(ACTIVATED_BOOLEAN_VALUE); }