Skip to content

Commit baf8e01

Browse files
Add tests for managed value types in ParameterTest and FirebaseRemoteConfigTest
- Added `testEqualityWithManagedValues` to `ParameterTest` to verify equality of parameters with `RolloutValue`, `PersonalizationValue`, and `ExperimentValue`. - Added `testGetTemplateWithManagedValues` to `FirebaseRemoteConfigTest` to verify that `getTemplate()` correctly parses managed values.
1 parent dad48bf commit baf8e01

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import static org.junit.Assert.assertTrue;
2323
import static org.junit.Assert.fail;
2424

25+
import com.google.common.collect.ImmutableMap;
2526
import com.google.firebase.ErrorCode;
2627
import com.google.firebase.FirebaseApp;
2728
import com.google.firebase.FirebaseOptions;
@@ -149,6 +150,33 @@ public void testGetTemplate() throws FirebaseRemoteConfigException {
149150
assertEquals(TEST_ETAG, template.getETag());
150151
}
151152

153+
@Test
154+
public void testGetTemplateWithManagedValues() throws FirebaseRemoteConfigException {
155+
Template template = new Template()
156+
.setETag(TEST_ETAG)
157+
.setParameters(ImmutableMap.of(
158+
"p1", new Parameter().setDefaultValue(
159+
ParameterValue.ofRollout("rollout_1", "value_1", 10.0)),
160+
"p2", new Parameter().setDefaultValue(
161+
ParameterValue.ofPersonalization("personalization_1"))
162+
));
163+
MockRemoteConfigClient client = MockRemoteConfigClient.fromTemplate(template);
164+
FirebaseRemoteConfig remoteConfig = getRemoteConfig(client);
165+
166+
Template fetchedTemplate = remoteConfig.getTemplate();
167+
168+
assertEquals(TEST_ETAG, fetchedTemplate.getETag());
169+
ParameterValue.RolloutValue rolloutValue =
170+
(ParameterValue.RolloutValue) fetchedTemplate.getParameters().get("p1").getDefaultValue();
171+
assertEquals("rollout_1", rolloutValue.getRolloutId());
172+
assertEquals("value_1", rolloutValue.getValue());
173+
assertEquals(10.0, rolloutValue.getPercent(), 0.0);
174+
175+
ParameterValue.PersonalizationValue personalizationValue =
176+
(ParameterValue.PersonalizationValue) fetchedTemplate.getParameters().get("p2").getDefaultValue();
177+
assertEquals("personalization_1", personalizationValue.getPersonalizationId());
178+
}
179+
152180
@Test
153181
public void testGetTemplateFailure() {
154182
MockRemoteConfigClient client = MockRemoteConfigClient.fromException(TEST_EXCEPTION);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,22 @@ public void testEquality() {
104104
assertNotEquals(parameterThree, parameterFive);
105105
assertNotEquals(parameterThree, parameterSeven);
106106
}
107+
108+
@Test
109+
public void testEqualityWithManagedValues() {
110+
final Parameter parameterOne = new Parameter()
111+
.setDefaultValue(ParameterValue.ofRollout("rollout_1", "value_1", 10.0));
112+
final Parameter parameterTwo = new Parameter()
113+
.setDefaultValue(ParameterValue.ofRollout("rollout_1", "value_1", 10.0));
114+
115+
assertEquals(parameterOne, parameterTwo);
116+
117+
final Parameter parameterThree = new Parameter()
118+
.setDefaultValue(ParameterValue.ofPersonalization("personalization_1"));
119+
final Parameter parameterFour = new Parameter()
120+
.setDefaultValue(ParameterValue.ofPersonalization("personalization_1"));
121+
122+
assertEquals(parameterThree, parameterFour);
123+
assertNotEquals(parameterOne, parameterThree);
124+
}
107125
}

0 commit comments

Comments
 (0)