-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathParameterValueTest.java
More file actions
137 lines (113 loc) · 5.6 KB
/
ParameterValueTest.java
File metadata and controls
137 lines (113 loc) · 5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/*
* Copyright 2020 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.google.firebase.remoteconfig;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import com.google.common.collect.ImmutableList;
import com.google.firebase.remoteconfig.ParameterValue.ExperimentVariantValue;
import org.junit.Test;
public class ParameterValueTest {
@Test
public void testCreateExplicitValue() {
final ParameterValue.Explicit parameterValue = ParameterValue.of("title text");
assertEquals("title text", parameterValue.getValue());
}
@Test
public void testCreateInAppDefault() {
final ParameterValue.InAppDefault parameterValue = ParameterValue.inAppDefault();
assertEquals(ParameterValue.InAppDefault.class, parameterValue.getClass());
}
@Test
public void testCreateRolloutValue() {
final ParameterValue.RolloutValue parameterValue =
ParameterValue.ofRollout("rollout_1", "value_1", 10.0);
assertEquals("rollout_1", parameterValue.getRolloutId());
assertEquals("value_1", parameterValue.getValue());
assertEquals(10.0, parameterValue.getPercent(), 0.0);
}
@Test
public void testCreatePersonalizationValue() {
final ParameterValue.PersonalizationValue parameterValue =
ParameterValue.ofPersonalization("personalization_1");
assertEquals("personalization_1", parameterValue.getPersonalizationId());
}
@Test
public void testCreateExperimentValue() {
final ParameterValue.ExperimentValue parameterValue =
ParameterValue.ofExperiment("experiment_1", ImmutableList.of(
ExperimentVariantValue.of("variant_1", "value_1"),
ExperimentVariantValue.ofNoChange("variant_2")
), 10.0);
assertEquals("experiment_1", parameterValue.getExperimentId());
assertEquals(2, parameterValue.getExperimentVariantValues().size());
ExperimentVariantValue variant1 = parameterValue.getExperimentVariantValues().get(0);
assertEquals("variant_1", variant1.getVariantId());
assertEquals("value_1", variant1.getValue());
assertEquals(false, variant1.isNoChange());
assertEquals(null, variant1.getNoChange());
ExperimentVariantValue variant2 = parameterValue.getExperimentVariantValues().get(1);
assertEquals("variant_2", variant2.getVariantId());
assertEquals(null, variant2.getValue());
assertEquals(true, variant2.isNoChange());
}
@Test
public void testEquality() {
ParameterValue.Explicit parameterValueOne = ParameterValue.of("value");
ParameterValue.Explicit parameterValueTwo = ParameterValue.of("value");
ParameterValue.Explicit parameterValueThree = ParameterValue.of("title");
assertEquals(parameterValueOne, parameterValueTwo);
assertNotEquals(parameterValueOne, parameterValueThree);
ParameterValue.InAppDefault parameterValueFour = ParameterValue.inAppDefault();
ParameterValue.InAppDefault parameterValueFive = ParameterValue.inAppDefault();
assertEquals(parameterValueFour, parameterValueFive);
ParameterValue.RolloutValue rolloutValueOne =
ParameterValue.ofRollout("rollout_1", "value_1", 10.0);
ParameterValue.RolloutValue rolloutValueTwo =
ParameterValue.ofRollout("rollout_1", "value_1", 10.0);
ParameterValue.RolloutValue rolloutValueThree =
ParameterValue.ofRollout("rollout_2", "value_1", 10.0);
assertEquals(rolloutValueOne, rolloutValueTwo);
assertNotEquals(rolloutValueOne, rolloutValueThree);
ParameterValue.PersonalizationValue personalizationValueOne =
ParameterValue.ofPersonalization("personalization_1");
ParameterValue.PersonalizationValue personalizationValueTwo =
ParameterValue.ofPersonalization("personalization_1");
ParameterValue.PersonalizationValue personalizationValueThree =
ParameterValue.ofPersonalization("personalization_2");
assertEquals(personalizationValueOne, personalizationValueTwo);
assertNotEquals(personalizationValueOne, personalizationValueThree);
ParameterValue.ExperimentValue experimentValueOne =
ParameterValue.ofExperiment("experiment_1", ImmutableList.of(
ExperimentVariantValue.of("variant_1", "value_1")
), 10.0);
ParameterValue.ExperimentValue experimentValueTwo =
ParameterValue.ofExperiment("experiment_1", ImmutableList.of(
ExperimentVariantValue.of("variant_1", "value_1")
), 10.0);
ParameterValue.ExperimentValue experimentValueThree =
ParameterValue.ofExperiment("experiment_2", ImmutableList.of(
ExperimentVariantValue.of("variant_1", "value_1")
), 10.0);
ParameterValue.ExperimentValue experimentValueFour =
ParameterValue.ofExperiment("experiment_1", ImmutableList.of(
ExperimentVariantValue.of("variant_2", "value_2")
), 10.0);
assertEquals(experimentValueOne, experimentValueTwo);
assertNotEquals(experimentValueOne, experimentValueThree);
assertNotEquals(experimentValueOne, experimentValueFour);
}
}