Skip to content

Commit 2d7c8d9

Browse files
chore: Fix issue in the new RC unit tests (#1205)
1 parent ab858ef commit 2d7c8d9

2 files changed

Lines changed: 12 additions & 14 deletions

File tree

src/main/java/com/google/firebase/remoteconfig/ServerTemplateImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private ServerTemplateImpl(Builder builder) {
7575
try {
7676
this.cache.set(ServerTemplateData.fromJSON(initialTemplate));
7777
} catch (FirebaseRemoteConfigException e) {
78-
e.printStackTrace();
78+
throw new IllegalArgumentException("Unable to parse JSON string.", e);
7979
}
8080
}
8181

src/test/java/com/google/firebase/remoteconfig/ServerTemplateImplTest.java

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static org.junit.Assert.assertEquals;
2020
import static org.junit.Assert.assertThrows;
21+
import static org.junit.Assert.assertTrue;
2122

2223
import com.google.api.core.ApiFuture;
2324
import com.google.firebase.FirebaseApp;
@@ -188,20 +189,17 @@ public void testEvaluateWithoutDefaultValueReturnsEmptyString()
188189
public void testEvaluateWithInvalidCacheValueThrowsException()
189190
throws FirebaseRemoteConfigException {
190191
KeysAndValues defaultConfig = new KeysAndValues.Builder().build();
191-
KeysAndValues context = new KeysAndValues.Builder().build();
192192
String invalidJsonString = "abc";
193-
ServerTemplate template =
194-
new ServerTemplateImpl.Builder(null)
195-
.defaultConfig(defaultConfig)
196-
.cachedTemplate(invalidJsonString)
197-
.build();
198-
199-
FirebaseRemoteConfigException error =
200-
assertThrows(FirebaseRemoteConfigException.class, () -> template.evaluate(context));
201-
202-
assertEquals(
203-
"No Remote Config Server template in cache. Call load() before " + "calling evaluate().",
204-
error.getMessage());
193+
IllegalArgumentException error = assertThrows(
194+
IllegalArgumentException.class,
195+
() -> new ServerTemplateImpl.Builder(null)
196+
.defaultConfig(defaultConfig)
197+
.cachedTemplate(invalidJsonString)
198+
.build());
199+
200+
assertEquals("Unable to parse JSON string.", error.getMessage());
201+
// Verify the cause is the original FirebaseRemoteConfigException
202+
assertTrue(error.getCause() instanceof FirebaseRemoteConfigException);
205203
}
206204

207205
@Test

0 commit comments

Comments
 (0)