|
25 | 25 | import static com.google.firebase.remoteconfig.internal.ConfigSharedPrefsClient.LAST_FETCH_TIME_NO_FETCH_YET; |
26 | 26 | import static com.google.firebase.remoteconfig.internal.ConfigSharedPrefsClient.NO_BACKOFF_TIME; |
27 | 27 | import static com.google.firebase.remoteconfig.internal.ConfigSharedPrefsClient.NO_FAILED_FETCHES; |
| 28 | +import static com.google.firebase.remoteconfig.testutil.Assert.assertThrows; |
28 | 29 |
|
29 | 30 | import android.content.Context; |
30 | 31 | import android.content.SharedPreferences; |
|
37 | 38 | import com.google.firebase.remoteconfig.internal.ConfigSharedPrefsClient.LastFetchStatus; |
38 | 39 | import java.util.Collections; |
39 | 40 | import java.util.Date; |
| 41 | +import java.util.HashMap; |
40 | 42 | import java.util.Map; |
41 | 43 | import org.junit.Before; |
42 | 44 | import org.junit.Test; |
@@ -367,4 +369,43 @@ public void getCustomSignals_isSet_returnsCustomSignals() { |
367 | 369 | metadataClient.setCustomSignals(SAMPLE_CUSTOM_SIGNALS); |
368 | 370 | assertThat(metadataClient.getCustomSignals()).isEqualTo(SAMPLE_CUSTOM_SIGNALS); |
369 | 371 | } |
| 372 | + |
| 373 | + @Test |
| 374 | + public void setCustomSignals_multipleTimes_addsNewSignals() { |
| 375 | + Map<String, Object> signals1 = ImmutableMap.of("subscription", "premium"); |
| 376 | + Map<String, Object> signals2 = ImmutableMap.of("age", 20L); |
| 377 | + metadataClient.setCustomSignals(signals1); |
| 378 | + metadataClient.setCustomSignals(signals2); |
| 379 | + Map<String, Object> expectedSignals = ImmutableMap.of("subscription", "premium", "age", 20L); |
| 380 | + assertThat(metadataClient.getCustomSignals()).isEqualTo(expectedSignals); |
| 381 | + } |
| 382 | + |
| 383 | + @Test |
| 384 | + public void setCustomSignals_nullValue_removesSignal() { |
| 385 | + Map<String, Object> signals1 = ImmutableMap.of("subscription", "premium", "age", 20L); |
| 386 | + metadataClient.setCustomSignals(signals1); |
| 387 | + Map<String, Object> signals2 = new HashMap<>(); |
| 388 | + signals2.put("age", null); |
| 389 | + metadataClient.setCustomSignals(signals2); |
| 390 | + Map<String, Object> expectedSignals = ImmutableMap.of("subscription", "premium"); |
| 391 | + assertThat(metadataClient.getCustomSignals()).isEqualTo(expectedSignals); |
| 392 | + } |
| 393 | + |
| 394 | + @Test |
| 395 | + public void setCustomSignals_invalidInput_throwsException() { |
| 396 | + Map<String, Object> invalidSignals1 = new HashMap<>(); |
| 397 | + invalidSignals1.put("name", true); |
| 398 | + assertThrows( |
| 399 | + IllegalArgumentException.class, () -> metadataClient.setCustomSignals(invalidSignals1)); |
| 400 | + |
| 401 | + Map<String, Object> invalidSignals2 = new HashMap<>(); |
| 402 | + invalidSignals2.put("a".repeat(251), "value"); |
| 403 | + assertThrows( |
| 404 | + IllegalArgumentException.class, () -> metadataClient.setCustomSignals(invalidSignals2)); |
| 405 | + |
| 406 | + Map<String, Object> invalidSignals3 = new HashMap<>(); |
| 407 | + invalidSignals3.put("key", "a".repeat(501)); |
| 408 | + assertThrows( |
| 409 | + IllegalArgumentException.class, () -> metadataClient.setCustomSignals(invalidSignals3)); |
| 410 | + } |
370 | 411 | } |
0 commit comments