### Question:
LegacyConfigsHandler { @WorkerThread public boolean saveLegacyConfigsIfNecessary() { if (legacySettings.getBoolean(SAVE_LEGACY_CONFIGS_FLAG_NAME, true)) { saveLegacyConfigs(getConvertedLegacyConfigs()); legacySettings.edit().putBoolean(SAVE_LEGACY_CONFIGS_FLAG_NAME, false).commit(); return true; } return false; } LegacyConfigsHandler(Context context, String appId); @WorkerThread boolean saveLegacyConfigsIfNecessary(); @VisibleForTesting static final String EXPERIMENT_ID_KEY; @VisibleForTesting static final String EXPERIMENT_VARIANT_ID_KEY; @VisibleForTesting static final String EXPERIMENT_START_TIME_KEY; @VisibleForTesting static final String EXPERIMENT_TRIGGER_EVENT_KEY; @VisibleForTesting
  static final String EXPERIMENT_TRIGGER_TIMEOUT_KEY; @VisibleForTesting static final String EXPERIMENT_TIME_TO_LIVE_KEY; }### Answer:
@Test public void saveLegacyConfigsIfNecessary_hasNoLegacyConfigs_doesNotWriteToCacheClients() { assertWithMessage("Did not save legacy configs!") .that(legacyConfigsHandler.saveLegacyConfigsIfNecessary()) .isTrue(); verifyNoWritesToAnyClient(); }
@Test public void saveLegacyConfigsIfNecessary_hasLegacyConfigs_writesConfigsToCacheClients() throws Exception { writeTestDataToLegacyConfigsFile(); assertWithMessage("Did not save legacy configs!") .that(legacyConfigsHandler.saveLegacyConfigsIfNecessary()) .isTrue(); validateFirebaseNamespaceConfigs(); validateSovietNamespaceConfigs(); validateFireperfNamespaceConfigs(); }
@Test public void saveLegacyConfigsIfNecessary_calledMultipleTimes_onlyFirstCallWritesToClients() throws Exception { writeTestDataToLegacyConfigsFile(); assertWithMessage("Did not save legacy configs!") .that(legacyConfigsHandler.saveLegacyConfigsIfNecessary()) .isTrue(); assertWithMessage("Saved legacy configs on second call!") .that(legacyConfigsHandler.saveLegacyConfigsIfNecessary()) .isFalse(); assertWithMessage("Saved legacy configs on third call!") .that(legacyConfigsHandler.saveLegacyConfigsIfNecessary()) .isFalse(); }