From 19c63949172a485e7492cea0bf0965a5977956af Mon Sep 17 00:00:00 2001 From: Lahiru Maramba Date: Fri, 23 Oct 2020 18:30:25 -0400 Subject: [PATCH 1/4] Introduce Parameter Groups --- .../firebase/remoteconfig/Parameter.java | 22 ++- .../firebase/remoteconfig/ParameterGroup.java | 138 ++++++++++++++++++ .../firebase/remoteconfig/ParameterValue.java | 34 ++++- .../firebase/remoteconfig/Template.java | 41 +++++- .../internal/TemplateResponse.java | 45 ++++++ .../firebase/remoteconfig/ConditionTest.java | 48 ++++++ .../FirebaseRemoteConfigClientImplTest.java | 17 +++ .../remoteconfig/ParameterGroupTest.java | 82 +++++++++++ .../firebase/remoteconfig/ParameterTest.java | 85 +++++++++++ .../remoteconfig/ParameterValueTest.java | 50 +++++++ src/test/resources/getRemoteConfig.json | 14 +- 11 files changed, 570 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/google/firebase/remoteconfig/ParameterGroup.java create mode 100644 src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java create mode 100644 src/test/java/com/google/firebase/remoteconfig/ParameterTest.java create mode 100644 src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java diff --git a/src/main/java/com/google/firebase/remoteconfig/Parameter.java b/src/main/java/com/google/firebase/remoteconfig/Parameter.java index 7198e2afa..d61816b43 100644 --- a/src/main/java/com/google/firebase/remoteconfig/Parameter.java +++ b/src/main/java/com/google/firebase/remoteconfig/Parameter.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.Map; +import java.util.Objects; /** * Represents a Remote Config parameter that can be included in a {@link Template}. @@ -73,7 +74,7 @@ public ParameterValue getDefaultValue() { /** * Gets the description of the parameter. * - * @return The {@link String} description of the parameter or null. + * @return The description of the parameter or null. */ @Nullable public String getDescription() { @@ -144,4 +145,23 @@ ParameterResponse toParameterResponse() { .setDescription(description) .setConditionalValues(conditionalResponseValues); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Parameter parameter = (Parameter) o; + return Objects.equals(defaultValue, parameter.defaultValue) + && Objects.equals(description, parameter.description) + && Objects.equals(conditionalValues, parameter.conditionalValues); + } + + @Override + public int hashCode() { + return Objects.hash(defaultValue, description, conditionalValues); + } } diff --git a/src/main/java/com/google/firebase/remoteconfig/ParameterGroup.java b/src/main/java/com/google/firebase/remoteconfig/ParameterGroup.java new file mode 100644 index 000000000..724665909 --- /dev/null +++ b/src/main/java/com/google/firebase/remoteconfig/ParameterGroup.java @@ -0,0 +1,138 @@ +/* + * 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 com.google.common.base.Preconditions.checkNotNull; + +import com.google.firebase.internal.NonNull; +import com.google.firebase.internal.Nullable; +import com.google.firebase.remoteconfig.internal.TemplateResponse; +import com.google.firebase.remoteconfig.internal.TemplateResponse.ParameterGroupResponse; +import com.google.firebase.remoteconfig.internal.TemplateResponse.ParameterResponse; + +import java.util.HashMap; +import java.util.Map; +import java.util.Objects; + +/** + * Represents a Remote Config parameter group that can be included in a {@link Template}. + * Grouping parameters is only for management purposes and does not affect client-side + * fetching of parameter values. + */ +public final class ParameterGroup { + + private String description; + private Map parameters; + + /** + * Creates a new {@link ParameterGroup}. + */ + public ParameterGroup() { + parameters = new HashMap<>(); + } + + ParameterGroup(@NonNull ParameterGroupResponse parameterGroupResponse) { + checkNotNull(parameterGroupResponse); + this.parameters = new HashMap<>(); + if (parameterGroupResponse.getParameters() != null) { + for (Map.Entry entry + : parameterGroupResponse.getParameters().entrySet()) { + this.parameters.put(entry.getKey(), new Parameter(entry.getValue())); + } + } + this.description = parameterGroupResponse.getDescription(); + } + + /** + * Gets the description of the parameter group. + * + * @return The description of the parameter or null. + */ + @Nullable + public String getDescription() { + return description; + } + + /** + * Gets the map of parameters that belong to this group. + * + * @return A non-null map of parameter keys to their optional default values and optional + * conditional values. + */ + @NonNull + public Map getParameters() { + return parameters; + } + + /** + * Sets the description of the parameter group. + * Should not be over 256 characters and may contain any Unicode characters. + * + * @param description The description of the parameter group. + * @return This {@link ParameterGroup}. + */ + public ParameterGroup setDescription(@Nullable String description) { + this.description = description; + return this; + } + + /** + * Sets the map of parameters that belong to this group. + * + *

A parameter only appears once per Remote Config template. + * An ungrouped parameter appears at the top level, whereas a + * parameter organized within a group appears within its group's map of parameters. + * + * @param parameters A non-null map of parameter keys to their optional default values and + * optional conditional values. + * @return This {@link ParameterGroup} instance. + */ + public ParameterGroup setParameters( + @NonNull Map parameters) { + checkNotNull(parameters, "parameters must not be null."); + this.parameters = parameters; + return this; + } + + ParameterGroupResponse toParameterGroupResponse() { + Map parameterResponses = new HashMap<>(); + for (Map.Entry entry : this.parameters.entrySet()) { + parameterResponses.put(entry.getKey(), entry.getValue().toParameterResponse()); + } + return new ParameterGroupResponse() + .setDescription(this.description) + .setParameters(parameterResponses); + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + ParameterGroup that = (ParameterGroup) o; + return Objects.equals(description, that.description) + && Objects.equals(parameters, that.parameters); + } + + @Override + public int hashCode() { + return Objects.hash(description, parameters); + } +} diff --git a/src/main/java/com/google/firebase/remoteconfig/ParameterValue.java b/src/main/java/com/google/firebase/remoteconfig/ParameterValue.java index b2a182e5d..90bf0e5df 100644 --- a/src/main/java/com/google/firebase/remoteconfig/ParameterValue.java +++ b/src/main/java/com/google/firebase/remoteconfig/ParameterValue.java @@ -21,6 +21,8 @@ import com.google.firebase.internal.NonNull; import com.google.firebase.remoteconfig.internal.TemplateResponse.ParameterValueResponse; +import java.util.Objects; + /** * Represents a Remote Config parameter value that can be used in a {@link Template}. */ @@ -57,7 +59,7 @@ static ParameterValue fromParameterValueResponse( } /** - * Represents an explicit Remote Config parameter value with a {@link String} value that the + * Represents an explicit Remote Config parameter value with a value that the * parameter is set to. */ public static final class Explicit extends ParameterValue { @@ -71,7 +73,7 @@ private Explicit(String value) { /** * Gets the value of {@link ParameterValue.Explicit}. * - * @return The {@link String} value. + * @return The value. */ public String getValue() { return this.value; @@ -82,6 +84,23 @@ ParameterValueResponse toParameterValueResponse() { return new ParameterValueResponse() .setValue(this.value); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Explicit explicit = (Explicit) o; + return Objects.equals(value, explicit.value); + } + + @Override + public int hashCode() { + return Objects.hash(value); + } } /** @@ -93,5 +112,16 @@ public static final class InAppDefault extends ParameterValue { ParameterValueResponse toParameterValueResponse() { return new ParameterValueResponse().setUseInAppDefault(true); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + return true; + } } } diff --git a/src/main/java/com/google/firebase/remoteconfig/Template.java b/src/main/java/com/google/firebase/remoteconfig/Template.java index 902273aa0..660893167 100644 --- a/src/main/java/com/google/firebase/remoteconfig/Template.java +++ b/src/main/java/com/google/firebase/remoteconfig/Template.java @@ -34,6 +34,7 @@ public final class Template { private String etag; private Map parameters; private List conditions; + private Map parameterGroups; /** * Creates a new {@link Template}. @@ -41,12 +42,14 @@ public final class Template { public Template() { parameters = new HashMap<>(); conditions = new ArrayList<>(); + parameterGroups = new HashMap<>(); } Template(@NonNull TemplateResponse templateResponse) { checkNotNull(templateResponse); this.parameters = new HashMap<>(); this.conditions = new ArrayList<>(); + this.parameterGroups = new HashMap<>(); if (templateResponse.getParameters() != null) { for (Map.Entry entry : templateResponse.getParameters().entrySet()) { @@ -59,6 +62,12 @@ public Template() { this.conditions.add(new Condition(conditionResponse)); } } + if (templateResponse.getParameterGroups() != null) { + for (Map.Entry entry + : templateResponse.getParameterGroups().entrySet()) { + this.parameterGroups.put(entry.getKey(), new ParameterGroup(entry.getValue())); + } + } } /** @@ -84,13 +93,23 @@ public Map getParameters() { /** * Gets the list of conditions of the template. * - * @return A non-null list of conditions + * @return A non-null list of conditions. */ @NonNull public List getConditions() { return conditions; } + /** + * Gets the map of parameter groups of the template. + * + * @return A non-null map of parameter group names to their parameter group instances. + */ + @NonNull + public Map getParameterGroups() { + return parameterGroups; + } + /** * Sets the map of parameters of the template. * @@ -118,6 +137,19 @@ public Template setConditions( return this; } + /** + * Sets the map of parameter groups of the template. + * + * @param parameterGroups A non-null map of parameter group names to their + * parameter group instances. + * @return This {@link Template} instance. + */ + public Template setParameterGroups( + Map parameterGroups) { + this.parameterGroups = parameterGroups; + return this; + } + Template setETag(String etag) { this.etag = etag; return this; @@ -132,8 +164,13 @@ TemplateResponse toTemplateResponse() { for (Condition condition : this.conditions) { conditionResponses.add(condition.toConditionResponse()); } + Map parameterGroupResponse = new HashMap<>(); + for (Map.Entry entry : this.parameterGroups.entrySet()) { + parameterGroupResponse.put(entry.getKey(), entry.getValue().toParameterGroupResponse()); + } return new TemplateResponse() .setParameters(parameterResponses) - .setConditions(conditionResponses); + .setConditions(conditionResponses) + .setParameterGroups(parameterGroupResponse); } } diff --git a/src/main/java/com/google/firebase/remoteconfig/internal/TemplateResponse.java b/src/main/java/com/google/firebase/remoteconfig/internal/TemplateResponse.java index cd1463e15..199536250 100644 --- a/src/main/java/com/google/firebase/remoteconfig/internal/TemplateResponse.java +++ b/src/main/java/com/google/firebase/remoteconfig/internal/TemplateResponse.java @@ -33,6 +33,9 @@ public final class TemplateResponse { @Key("conditions") private List conditions; + @Key("parameterGroups") + private Map parameterGroups; + public Map getParameters() { return parameters; } @@ -41,6 +44,10 @@ public List getConditions() { return conditions; } + public Map getParameterGroups() { + return parameterGroups; + } + public TemplateResponse setParameters( Map parameters) { this.parameters = parameters; @@ -53,6 +60,12 @@ public TemplateResponse setConditions( return this; } + public TemplateResponse setParameterGroups( + Map parameterGroups) { + this.parameterGroups = parameterGroups; + return this; + } + /** * The Data Transfer Object for parsing Remote Config parameter responses from the * Remote Config service. @@ -171,4 +184,36 @@ public ConditionResponse setTagColor(String tagColor) { return this; } } + + /** + * The Data Transfer Object for parsing Remote Config parameter groups responses from the + * Remote Config service. + **/ + public static final class ParameterGroupResponse { + + @Key("description") + private String description; + + @Key("parameters") + private Map parameters; + + public Map getParameters() { + return parameters; + } + + public String getDescription() { + return description; + } + + public ParameterGroupResponse setParameters( + Map parameters) { + this.parameters = parameters; + return this; + } + + public ParameterGroupResponse setDescription(String description) { + this.description = description; + return this; + } + } } diff --git a/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java b/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java index 1c8b8cd57..efe1b7b99 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java @@ -18,11 +18,59 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNull; import org.junit.Test; public class ConditionTest { + @Test + public void testConstructor() { + Condition c1 = new Condition("ios_en_1", "expression1"); + assertEquals("ios_en_1", c1.getName()); + assertEquals("expression1", c1.getExpression()); + assertNull(c1.getTagColor()); + + Condition c2 = new Condition("ios_en_2", "expression2", TagColor.BLUE); + assertEquals("ios_en_2", c2.getName()); + assertEquals("expression2", c2.getExpression()); + assertEquals(TagColor.BLUE, c2.getTagColor()); + } + + @Test(expected = IllegalArgumentException.class) + public void testIllegalConstructor() { + Condition c = new Condition(null, null); + } + + @Test(expected = NullPointerException.class) + public void testConstructorWithNullConditionResponse() { + Condition c = new Condition(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetNullName() { + Condition c = new Condition("ios", "exp"); + c.setName(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetEmptyName() { + Condition c = new Condition("ios", "exp"); + c.setName(""); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetNullExpression() { + Condition c = new Condition("ios", "exp"); + c.setExpression(null); + } + + @Test(expected = IllegalArgumentException.class) + public void testSetEmptyExpression() { + Condition c = new Condition("ios", "exp"); + c.setExpression(""); + } + @Test public void testEquality() { final Condition conditionOne = new Condition("ios", "device.os == 'ios'", TagColor.GREEN); diff --git a/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java b/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java index aabc98a26..26cf437fd 100644 --- a/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java @@ -45,6 +45,7 @@ import com.google.firebase.testing.TestUtils; import java.io.IOException; +import java.util.HashMap; import java.util.List; import java.util.Map; @@ -122,6 +123,22 @@ public void testGetTemplate() throws Exception { for (int i = 0; i < expectedConditions.size(); i++) { assertEquals(expectedConditions.get(i), actualConditions.get(i)); } + + // Check Parameter Groups + Map parameterGroups = template.getParameterGroups(); + assertEquals(1, parameterGroups.size()); + + Map cv = new HashMap<>(); + cv.put("ios_en", ParameterValue.of("welcome to app en")); + + Parameter p = new Parameter() + .setDefaultValue(ParameterValue.of("welcome to app")) + .setConditionalValues(cv) + .setDescription("text for welcome message!"); + Parameter p1 = new Parameter() + .setDefaultValue(ParameterValue.inAppDefault()); + assertEquals(p, welcomeMessageParameter); + assertEquals(p1, headerParameter); } @Test diff --git a/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java b/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java new file mode 100644 index 000000000..e57fcc96b --- /dev/null +++ b/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java @@ -0,0 +1,82 @@ +/* + * 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.assertNotNull; +import static org.junit.Assert.assertNull; + +import com.google.common.collect.ImmutableMap; + +import java.util.Map; + +import org.junit.Test; + +public class ParameterGroupTest { + + @Test + public void testConstructor() { + final ParameterGroup pg = new ParameterGroup(); + assertNotNull(pg.getParameters()); + assertEquals(0, pg.getParameters().size()); + assertNull(pg.getDescription()); + } + + @Test(expected = NullPointerException.class) + public void testConstructorWithNullParameterGroupResponse() { + ParameterGroup pg = new ParameterGroup(null); + } + + @Test(expected = NullPointerException.class) + public void testSetNullParameters() { + ParameterGroup pg = new ParameterGroup(); + pg.setParameters(null); + } + + @Test + public void testEquality() { + final ParameterGroup p1 = new ParameterGroup(); + final ParameterGroup p2 = new ParameterGroup(); + assertEquals(p1, p2); + + final ParameterGroup p3 = new ParameterGroup() + .setDescription("description"); + final ParameterGroup p4 = new ParameterGroup() + .setDescription("description"); + assertEquals(p3, p4); + + final Map parameters = ImmutableMap.of( + "header_text", new Parameter().setDefaultValue(ParameterValue.of("Welcome")), + "promo", new Parameter() + .setDefaultValue(ParameterValue.inAppDefault()) + .setConditionalValues(ImmutableMap.of( + "ios", ParameterValue.of("ios header text") + )) + ); + final ParameterGroup p5 = new ParameterGroup() + .setDescription("description") + .setParameters(parameters); + final ParameterGroup p6 = new ParameterGroup() + .setDescription("description") + .setParameters(parameters); + assertEquals(p5, p6); + assertNotEquals(p1, p3); + assertNotEquals(p1, p5); + assertNotEquals(p3, p5); + } +} diff --git a/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java b/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java new file mode 100644 index 000000000..facde719d --- /dev/null +++ b/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java @@ -0,0 +1,85 @@ +/* + * 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.assertNotNull; +import static org.junit.Assert.assertNull; + +import java.util.HashMap; +import java.util.Map; + +import org.junit.Test; + +public class ParameterTest { + + @Test + public void testConstructor() { + final Parameter p = new Parameter(); + assertNotNull(p.getConditionalValues()); + assertEquals(0, p.getConditionalValues().size()); + assertNull(p.getDefaultValue()); + assertNull(p.getDescription()); + } + + @Test(expected = NullPointerException.class) + public void testConstructorWithNullParameterResponse() { + Parameter p = new Parameter(null); + } + + @Test(expected = NullPointerException.class) + public void testSetNullConditionalValues() { + Parameter p = new Parameter(); + p.setConditionalValues(null); + } + + @Test + public void testEquality() { + final Parameter p1 = new Parameter() + .setDefaultValue(ParameterValue.of("hello")); + final Parameter p2 = new Parameter() + .setDefaultValue(ParameterValue.of("hello")); + assertEquals(p1, p2); + + final Parameter p3 = new Parameter() + .setDefaultValue(ParameterValue.inAppDefault()) + .setDescription("greeting text"); + final Parameter p4 = new Parameter() + .setDefaultValue(ParameterValue.inAppDefault()) + .setDescription("greeting text"); + assertEquals(p3, p4); + + final Map conditionalValues = new HashMap(); + conditionalValues.put("ios", ParameterValue.of("hello ios")); + conditionalValues.put("android", ParameterValue.of("hello android")); + conditionalValues.put("promo", ParameterValue.inAppDefault()); + final Parameter p5 = new Parameter() + .setDefaultValue(ParameterValue.inAppDefault()) + .setDescription("greeting text") + .setConditionalValues(conditionalValues); + final Parameter p6 = new Parameter() + .setDefaultValue(ParameterValue.inAppDefault()) + .setDescription("greeting text") + .setConditionalValues(conditionalValues); + assertEquals(p5, p6); + assertNotEquals(p1, p3); + assertNotEquals(p1, p5); + assertNotEquals(p3, p5); + } + +} diff --git a/src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java b/src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java new file mode 100644 index 000000000..f6e4bd09c --- /dev/null +++ b/src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java @@ -0,0 +1,50 @@ +/* + * 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 org.junit.Test; + +public class ParameterValueTest { + + @Test + public void testCreateExplicitValue() { + final ParameterValue.Explicit pv = ParameterValue.of("title text"); + assertEquals("title text", pv.getValue()); + } + + @Test + public void testCreateInAppDefault() { + final ParameterValue.InAppDefault pv = ParameterValue.inAppDefault(); + assertEquals(ParameterValue.InAppDefault.class, pv.getClass()); + } + + @Test + public void testEquality() { + ParameterValue.Explicit pv1 = ParameterValue.of("value"); + ParameterValue.Explicit pv2 = ParameterValue.of("value"); + ParameterValue.Explicit pv3 = ParameterValue.of("title"); + assertEquals(pv1, pv2); + assertNotEquals(pv1, pv3); + + ParameterValue.InAppDefault pv4 = ParameterValue.inAppDefault(); + ParameterValue.InAppDefault pv5 = ParameterValue.inAppDefault(); + assertEquals(pv4, pv5); + } +} diff --git a/src/test/resources/getRemoteConfig.json b/src/test/resources/getRemoteConfig.json index df54117bb..8b0f66479 100644 --- a/src/test/resources/getRemoteConfig.json +++ b/src/test/resources/getRemoteConfig.json @@ -28,7 +28,19 @@ } } }, - "parameterGroups": {}, + "parameterGroups": { + "new menu": { + "description": "New Menu", + "parameters": { + "pumpkin_spice_season": { + "defaultValue": { + "value": "true" + }, + "description": "Whether it's currently pumpkin spice season." + } + } + } + }, "version": { "versionNumber": "17", "updateOrigin": "ADMIN_SDK_NODE", From acafdf890b46bd30eb324f001a6a3f0645409918 Mon Sep 17 00:00:00 2001 From: Lahiru Maramba Date: Wed, 28 Oct 2020 14:26:47 -0400 Subject: [PATCH 2/4] Refactor unit tests --- .../firebase/remoteconfig/Template.java | 19 ++- .../firebase/remoteconfig/ConditionTest.java | 2 + .../FirebaseRemoteConfigClientImplTest.java | 77 ++++------ .../remoteconfig/ParameterGroupTest.java | 4 + .../firebase/remoteconfig/ParameterTest.java | 12 +- .../remoteconfig/ParameterValueTest.java | 4 + .../firebase/remoteconfig/TemplateTest.java | 136 ++++++++++++++++++ 7 files changed, 201 insertions(+), 53 deletions(-) create mode 100644 src/test/java/com/google/firebase/remoteconfig/TemplateTest.java diff --git a/src/main/java/com/google/firebase/remoteconfig/Template.java b/src/main/java/com/google/firebase/remoteconfig/Template.java index 660893167..30b94a23d 100644 --- a/src/main/java/com/google/firebase/remoteconfig/Template.java +++ b/src/main/java/com/google/firebase/remoteconfig/Template.java @@ -25,6 +25,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; /** * Represents a Remote Config template. @@ -145,7 +146,8 @@ public Template setConditions( * @return This {@link Template} instance. */ public Template setParameterGroups( - Map parameterGroups) { + @NonNull Map parameterGroups) { + checkNotNull(parameterGroups, "parameter groups must not be null."); this.parameterGroups = parameterGroups; return this; } @@ -173,4 +175,19 @@ TemplateResponse toTemplateResponse() { .setConditions(conditionResponses) .setParameterGroups(parameterGroupResponse); } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + Template template = (Template) o; + return Objects.equals(etag, template.etag) + && Objects.equals(parameters, template.parameters) + && Objects.equals(conditions, template.conditions) + && Objects.equals(parameterGroups, template.parameterGroups); + } } diff --git a/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java b/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java index efe1b7b99..6b668cff1 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java @@ -27,11 +27,13 @@ public class ConditionTest { @Test public void testConstructor() { Condition c1 = new Condition("ios_en_1", "expression1"); + assertEquals("ios_en_1", c1.getName()); assertEquals("expression1", c1.getExpression()); assertNull(c1.getTagColor()); Condition c2 = new Condition("ios_en_2", "expression2", TagColor.BLUE); + assertEquals("ios_en_2", c2.getName()); assertEquals("expression2", c2.getExpression()); assertEquals(TagColor.BLUE, c2.getTagColor()); diff --git a/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java b/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java index 26cf437fd..c6e9081ee 100644 --- a/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java @@ -85,33 +85,27 @@ public void testGetTemplate() throws Exception { response.addHeader("etag", TEST_ETAG); response.setContent(MOCK_TEMPLATE_RESPONSE); - Template template = client.getTemplate(); - - // Check Parameters - assertEquals(TEST_ETAG, template.getETag()); - Map parameters = template.getParameters(); - assertEquals(2, parameters.size()); - assertTrue(parameters.containsKey("welcome_message_text")); - Parameter welcomeMessageParameter = parameters.get("welcome_message_text"); - assertEquals("text for welcome message!", welcomeMessageParameter.getDescription()); - ParameterValue.Explicit explicitDefaultValue = - (ParameterValue.Explicit) welcomeMessageParameter.getDefaultValue(); - assertEquals("welcome to app", explicitDefaultValue.getValue()); - Map conditionalValues = welcomeMessageParameter - .getConditionalValues(); - assertEquals(1, conditionalValues.size()); - assertTrue(conditionalValues.containsKey("ios_en")); - ParameterValue.Explicit value = - (ParameterValue.Explicit) conditionalValues.get("ios_en"); - assertEquals("welcome to app en", value.getValue()); - assertTrue(parameters.containsKey("header_text")); - Parameter headerParameter = parameters.get("header_text"); - assertTrue( - headerParameter.getDefaultValue() instanceof ParameterValue.InAppDefault); - checkGetRequestHeader(interceptor.getLastRequest()); - - // Check Conditions - List actualConditions = template.getConditions(); + Template receivedTemplate = client.getTemplate(); + Map expectedParameters = ImmutableMap.of( + "welcome_message_text", new Parameter() + .setDefaultValue(ParameterValue.of("welcome to app")) + .setConditionalValues(ImmutableMap.of( + "ios_en", ParameterValue.of("welcome to app en") + )) + .setDescription("text for welcome message!"), + "header_text", new Parameter() + .setDefaultValue(ParameterValue.inAppDefault()) + ); + Map expectedParameterGroups = ImmutableMap.of( + "new menu", new ParameterGroup() + .setDescription("New Menu") + .setParameters(ImmutableMap.of( + "pumpkin_spice_season", new Parameter() + .setDefaultValue(ParameterValue.of("true")) + .setDescription("Whether it's currently pumpkin spice season.") + ) + ) + ); List expectedConditions = ImmutableList.of( new Condition("ios_en", "device.os == 'ios' && device.country in ['us', 'uk']") .setTagColor(TagColor.INDIGO), @@ -119,26 +113,15 @@ public void testGetTemplate() throws Exception { "device.os == 'android' && device.country in ['us', 'uk']") .setTagColor(TagColor.UNSPECIFIED) ); - assertEquals(expectedConditions.size(), actualConditions.size()); - for (int i = 0; i < expectedConditions.size(); i++) { - assertEquals(expectedConditions.get(i), actualConditions.get(i)); - } - - // Check Parameter Groups - Map parameterGroups = template.getParameterGroups(); - assertEquals(1, parameterGroups.size()); - - Map cv = new HashMap<>(); - cv.put("ios_en", ParameterValue.of("welcome to app en")); - - Parameter p = new Parameter() - .setDefaultValue(ParameterValue.of("welcome to app")) - .setConditionalValues(cv) - .setDescription("text for welcome message!"); - Parameter p1 = new Parameter() - .setDefaultValue(ParameterValue.inAppDefault()); - assertEquals(p, welcomeMessageParameter); - assertEquals(p1, headerParameter); + Template expectedTemplate = new Template() + .setParameters(expectedParameters) + .setParameterGroups(expectedParameterGroups) + .setConditions(expectedConditions) + .setETag(TEST_ETAG); + + assertEquals(TEST_ETAG, receivedTemplate.getETag()); + assertEquals(expectedTemplate, receivedTemplate); + checkGetRequestHeader(interceptor.getLastRequest()); } @Test diff --git a/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java b/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java index e57fcc96b..a0c0981c5 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java @@ -32,6 +32,7 @@ public class ParameterGroupTest { @Test public void testConstructor() { final ParameterGroup pg = new ParameterGroup(); + assertNotNull(pg.getParameters()); assertEquals(0, pg.getParameters().size()); assertNull(pg.getDescription()); @@ -52,12 +53,14 @@ public void testSetNullParameters() { public void testEquality() { final ParameterGroup p1 = new ParameterGroup(); final ParameterGroup p2 = new ParameterGroup(); + assertEquals(p1, p2); final ParameterGroup p3 = new ParameterGroup() .setDescription("description"); final ParameterGroup p4 = new ParameterGroup() .setDescription("description"); + assertEquals(p3, p4); final Map parameters = ImmutableMap.of( @@ -74,6 +77,7 @@ public void testEquality() { final ParameterGroup p6 = new ParameterGroup() .setDescription("description") .setParameters(parameters); + assertEquals(p5, p6); assertNotEquals(p1, p3); assertNotEquals(p1, p5); diff --git a/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java b/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java index facde719d..2761dd68b 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java @@ -21,7 +21,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; -import java.util.HashMap; +import com.google.common.collect.ImmutableMap; + import java.util.Map; import org.junit.Test; @@ -64,10 +65,11 @@ public void testEquality() { .setDescription("greeting text"); assertEquals(p3, p4); - final Map conditionalValues = new HashMap(); - conditionalValues.put("ios", ParameterValue.of("hello ios")); - conditionalValues.put("android", ParameterValue.of("hello android")); - conditionalValues.put("promo", ParameterValue.inAppDefault()); + final Map conditionalValues = ImmutableMap.of( + "ios", ParameterValue.of("hello ios"), + "android", ParameterValue.of("hello android"), + "promo", ParameterValue.inAppDefault() + ); final Parameter p5 = new Parameter() .setDefaultValue(ParameterValue.inAppDefault()) .setDescription("greeting text") diff --git a/src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java b/src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java index f6e4bd09c..c33158676 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java @@ -26,12 +26,14 @@ public class ParameterValueTest { @Test public void testCreateExplicitValue() { final ParameterValue.Explicit pv = ParameterValue.of("title text"); + assertEquals("title text", pv.getValue()); } @Test public void testCreateInAppDefault() { final ParameterValue.InAppDefault pv = ParameterValue.inAppDefault(); + assertEquals(ParameterValue.InAppDefault.class, pv.getClass()); } @@ -40,11 +42,13 @@ public void testEquality() { ParameterValue.Explicit pv1 = ParameterValue.of("value"); ParameterValue.Explicit pv2 = ParameterValue.of("value"); ParameterValue.Explicit pv3 = ParameterValue.of("title"); + assertEquals(pv1, pv2); assertNotEquals(pv1, pv3); ParameterValue.InAppDefault pv4 = ParameterValue.inAppDefault(); ParameterValue.InAppDefault pv5 = ParameterValue.inAppDefault(); + assertEquals(pv4, pv5); } } diff --git a/src/test/java/com/google/firebase/remoteconfig/TemplateTest.java b/src/test/java/com/google/firebase/remoteconfig/TemplateTest.java new file mode 100644 index 000000000..841976165 --- /dev/null +++ b/src/test/java/com/google/firebase/remoteconfig/TemplateTest.java @@ -0,0 +1,136 @@ +/* + * 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.assertNotNull; +import static org.junit.Assert.assertNull; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.junit.Test; + +public class TemplateTest { + + @Test + public void testConstructor() { + Template t = new Template(); + + assertNotNull(t.getParameters()); + assertNotNull(t.getConditions()); + assertNotNull(t.getParameterGroups()); + assertEquals(0, t.getParameters().size()); + assertEquals(0, t.getConditions().size()); + assertEquals(0, t.getParameterGroups().size()); + assertNull(t.getETag()); + } + + @Test(expected = NullPointerException.class) + public void testConstructorWithNullTemplateResponse() { + Template t = new Template(null); + } + + @Test(expected = NullPointerException.class) + public void testSetNullParameters() { + Template t = new Template(); + t.setParameters(null); + } + + @Test(expected = NullPointerException.class) + public void testSetNullConditions() { + Template t = new Template(); + t.setConditions(null); + } + + @Test(expected = NullPointerException.class) + public void testSetNullParameterGroups() { + Template t = new Template(); + t.setParameterGroups(null); + } + + @Test + public void testEquality() { + final Template t1 = new Template(); + final Template t2 = new Template(); + + assertEquals(t1, t2); + + final List conditions = ImmutableList.of( + new Condition("ios_en", "exp ios") + .setTagColor(TagColor.INDIGO), + new Condition("android_en", "exp android") + ); + final Map conditionalValues = ImmutableMap.of( + "ios", ParameterValue.of("hello ios"), + "android", ParameterValue.of("hello android"), + "promo", ParameterValue.inAppDefault() + ); + final Map parameters = ImmutableMap.of( + "greeting_header", new Parameter() + .setDefaultValue(ParameterValue.inAppDefault()) + .setDescription("greeting header text") + .setConditionalValues(conditionalValues), + "greeting_text", new Parameter() + .setDefaultValue(ParameterValue.inAppDefault()) + .setDescription("greeting text") + .setConditionalValues(conditionalValues) + ); + final Template t3 = new Template() + .setConditions(conditions) + .setParameters(parameters); + final Template t4 = new Template() + .setConditions(conditions) + .setParameters(parameters); + + assertEquals(t3, t4); + + final Map parameterGroups = ImmutableMap.of( + "greetings_group", new ParameterGroup() + .setDescription("description") + .setParameters(parameters) + ); + final Template t5 = new Template() + .setConditions(conditions) + .setParameters(parameters) + .setParameterGroups(parameterGroups); + final Template t6 = new Template() + .setConditions(conditions) + .setParameters(parameters) + .setParameterGroups(parameterGroups); + + assertEquals(t5, t6); + + final Template t7 = new Template() + .setETag("etag-123456789097-20"); + final Template t8 = new Template() + .setETag("etag-123456789097-20"); + + assertEquals(t7, t8); + assertNotEquals(t1, t3); + assertNotEquals(t1, t5); + assertNotEquals(t1, t7); + assertNotEquals(t3, t5); + assertNotEquals(t3, t7); + assertNotEquals(t5, t7); + } +} From 635fd8484d3b1c122b31c814ea3c916d9daff8b2 Mon Sep 17 00:00:00 2001 From: Lahiru Maramba Date: Thu, 29 Oct 2020 13:12:06 -0400 Subject: [PATCH 3/4] PR fixes --- .../firebase/remoteconfig/Template.java | 5 ++++ .../firebase/remoteconfig/ConditionTest.java | 23 +++++++++++-------- .../FirebaseRemoteConfigClientImplTest.java | 1 - .../remoteconfig/ParameterGroupTest.java | 5 ++-- .../firebase/remoteconfig/ParameterTest.java | 9 ++++++-- .../firebase/remoteconfig/TemplateTest.java | 10 ++++---- 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/main/java/com/google/firebase/remoteconfig/Template.java b/src/main/java/com/google/firebase/remoteconfig/Template.java index 30b94a23d..f54cc801f 100644 --- a/src/main/java/com/google/firebase/remoteconfig/Template.java +++ b/src/main/java/com/google/firebase/remoteconfig/Template.java @@ -190,4 +190,9 @@ public boolean equals(Object o) { && Objects.equals(conditions, template.conditions) && Objects.equals(parameterGroups, template.parameterGroups); } + + @Override + public int hashCode() { + return Objects.hash(etag, parameters, conditions, parameterGroups); + } } diff --git a/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java b/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java index 6b668cff1..29e7aa789 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java @@ -26,27 +26,30 @@ public class ConditionTest { @Test public void testConstructor() { - Condition c1 = new Condition("ios_en_1", "expression1"); + Condition c = new Condition("ios_en_1", "expression1"); - assertEquals("ios_en_1", c1.getName()); - assertEquals("expression1", c1.getExpression()); - assertNull(c1.getTagColor()); + assertEquals("ios_en_1", c.getName()); + assertEquals("expression1", c.getExpression()); + assertNull(c.getTagColor()); + } - Condition c2 = new Condition("ios_en_2", "expression2", TagColor.BLUE); + @Test + public void testConstructorWithColor() { + Condition c = new Condition("ios_en_2", "expression2", TagColor.BLUE); - assertEquals("ios_en_2", c2.getName()); - assertEquals("expression2", c2.getExpression()); - assertEquals(TagColor.BLUE, c2.getTagColor()); + assertEquals("ios_en_2", c.getName()); + assertEquals("expression2", c.getExpression()); + assertEquals(TagColor.BLUE, c.getTagColor()); } @Test(expected = IllegalArgumentException.class) public void testIllegalConstructor() { - Condition c = new Condition(null, null); + new Condition(null, null); } @Test(expected = NullPointerException.class) public void testConstructorWithNullConditionResponse() { - Condition c = new Condition(null); + new Condition(null); } @Test(expected = IllegalArgumentException.class) diff --git a/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java b/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java index c6e9081ee..910cc0416 100644 --- a/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/FirebaseRemoteConfigClientImplTest.java @@ -45,7 +45,6 @@ import com.google.firebase.testing.TestUtils; import java.io.IOException; -import java.util.HashMap; import java.util.List; import java.util.Map; diff --git a/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java b/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java index a0c0981c5..bf0bd6f04 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableMap; @@ -34,13 +35,13 @@ public void testConstructor() { final ParameterGroup pg = new ParameterGroup(); assertNotNull(pg.getParameters()); - assertEquals(0, pg.getParameters().size()); + assertTrue(pg.getParameters().isEmpty()); assertNull(pg.getDescription()); } @Test(expected = NullPointerException.class) public void testConstructorWithNullParameterGroupResponse() { - ParameterGroup pg = new ParameterGroup(null); + new ParameterGroup(null); } @Test(expected = NullPointerException.class) diff --git a/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java b/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java index 2761dd68b..414276229 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java @@ -20,6 +20,7 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableMap; @@ -32,15 +33,16 @@ public class ParameterTest { @Test public void testConstructor() { final Parameter p = new Parameter(); + assertNotNull(p.getConditionalValues()); - assertEquals(0, p.getConditionalValues().size()); + assertTrue(p.getConditionalValues().isEmpty()); assertNull(p.getDefaultValue()); assertNull(p.getDescription()); } @Test(expected = NullPointerException.class) public void testConstructorWithNullParameterResponse() { - Parameter p = new Parameter(null); + new Parameter(null); } @Test(expected = NullPointerException.class) @@ -55,6 +57,7 @@ public void testEquality() { .setDefaultValue(ParameterValue.of("hello")); final Parameter p2 = new Parameter() .setDefaultValue(ParameterValue.of("hello")); + assertEquals(p1, p2); final Parameter p3 = new Parameter() @@ -63,6 +66,7 @@ public void testEquality() { final Parameter p4 = new Parameter() .setDefaultValue(ParameterValue.inAppDefault()) .setDescription("greeting text"); + assertEquals(p3, p4); final Map conditionalValues = ImmutableMap.of( @@ -78,6 +82,7 @@ public void testEquality() { .setDefaultValue(ParameterValue.inAppDefault()) .setDescription("greeting text") .setConditionalValues(conditionalValues); + assertEquals(p5, p6); assertNotEquals(p1, p3); assertNotEquals(p1, p5); diff --git a/src/test/java/com/google/firebase/remoteconfig/TemplateTest.java b/src/test/java/com/google/firebase/remoteconfig/TemplateTest.java index 841976165..be2961e61 100644 --- a/src/test/java/com/google/firebase/remoteconfig/TemplateTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/TemplateTest.java @@ -20,11 +20,11 @@ import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; -import java.util.HashMap; import java.util.List; import java.util.Map; @@ -39,15 +39,15 @@ public void testConstructor() { assertNotNull(t.getParameters()); assertNotNull(t.getConditions()); assertNotNull(t.getParameterGroups()); - assertEquals(0, t.getParameters().size()); - assertEquals(0, t.getConditions().size()); - assertEquals(0, t.getParameterGroups().size()); + assertTrue(t.getParameters().isEmpty()); + assertTrue(t.getConditions().isEmpty()); + assertTrue(t.getParameterGroups().isEmpty()); assertNull(t.getETag()); } @Test(expected = NullPointerException.class) public void testConstructorWithNullTemplateResponse() { - Template t = new Template(null); + new Template(null); } @Test(expected = NullPointerException.class) From 44aa0c94dbb53cd27b50e66d1153e4a33ab1bb2b Mon Sep 17 00:00:00 2001 From: Lahiru Maramba Date: Thu, 29 Oct 2020 15:07:17 -0400 Subject: [PATCH 4/4] Fix variable names in unit tests --- .../firebase/remoteconfig/ConditionTest.java | 32 ++++----- .../remoteconfig/ParameterGroupTest.java | 36 +++++----- .../firebase/remoteconfig/ParameterTest.java | 39 ++++++----- .../remoteconfig/ParameterValueTest.java | 24 +++---- .../firebase/remoteconfig/TemplateTest.java | 66 +++++++++---------- 5 files changed, 98 insertions(+), 99 deletions(-) diff --git a/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java b/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java index 29e7aa789..aba01ead2 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ConditionTest.java @@ -26,20 +26,20 @@ public class ConditionTest { @Test public void testConstructor() { - Condition c = new Condition("ios_en_1", "expression1"); + Condition condition = new Condition("ios_en_1", "expression1"); - assertEquals("ios_en_1", c.getName()); - assertEquals("expression1", c.getExpression()); - assertNull(c.getTagColor()); + assertEquals("ios_en_1", condition.getName()); + assertEquals("expression1", condition.getExpression()); + assertNull(condition.getTagColor()); } @Test public void testConstructorWithColor() { - Condition c = new Condition("ios_en_2", "expression2", TagColor.BLUE); + Condition condition = new Condition("ios_en_2", "expression2", TagColor.BLUE); - assertEquals("ios_en_2", c.getName()); - assertEquals("expression2", c.getExpression()); - assertEquals(TagColor.BLUE, c.getTagColor()); + assertEquals("ios_en_2", condition.getName()); + assertEquals("expression2", condition.getExpression()); + assertEquals(TagColor.BLUE, condition.getTagColor()); } @Test(expected = IllegalArgumentException.class) @@ -54,26 +54,26 @@ public void testConstructorWithNullConditionResponse() { @Test(expected = IllegalArgumentException.class) public void testSetNullName() { - Condition c = new Condition("ios", "exp"); - c.setName(null); + Condition condition = new Condition("ios", "exp"); + condition.setName(null); } @Test(expected = IllegalArgumentException.class) public void testSetEmptyName() { - Condition c = new Condition("ios", "exp"); - c.setName(""); + Condition condition = new Condition("ios", "exp"); + condition.setName(""); } @Test(expected = IllegalArgumentException.class) public void testSetNullExpression() { - Condition c = new Condition("ios", "exp"); - c.setExpression(null); + Condition condition = new Condition("ios", "exp"); + condition.setExpression(null); } @Test(expected = IllegalArgumentException.class) public void testSetEmptyExpression() { - Condition c = new Condition("ios", "exp"); - c.setExpression(""); + Condition condition = new Condition("ios", "exp"); + condition.setExpression(""); } @Test diff --git a/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java b/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java index bf0bd6f04..8a7344168 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ParameterGroupTest.java @@ -32,11 +32,11 @@ public class ParameterGroupTest { @Test public void testConstructor() { - final ParameterGroup pg = new ParameterGroup(); + final ParameterGroup parameterGroup = new ParameterGroup(); - assertNotNull(pg.getParameters()); - assertTrue(pg.getParameters().isEmpty()); - assertNull(pg.getDescription()); + assertNotNull(parameterGroup.getParameters()); + assertTrue(parameterGroup.getParameters().isEmpty()); + assertNull(parameterGroup.getDescription()); } @Test(expected = NullPointerException.class) @@ -46,23 +46,23 @@ public void testConstructorWithNullParameterGroupResponse() { @Test(expected = NullPointerException.class) public void testSetNullParameters() { - ParameterGroup pg = new ParameterGroup(); - pg.setParameters(null); + ParameterGroup parameterGroup = new ParameterGroup(); + parameterGroup.setParameters(null); } @Test public void testEquality() { - final ParameterGroup p1 = new ParameterGroup(); - final ParameterGroup p2 = new ParameterGroup(); + final ParameterGroup parameterGroupOne = new ParameterGroup(); + final ParameterGroup parameterGroupTwo = new ParameterGroup(); - assertEquals(p1, p2); + assertEquals(parameterGroupOne, parameterGroupTwo); - final ParameterGroup p3 = new ParameterGroup() + final ParameterGroup parameterGroupThree = new ParameterGroup() .setDescription("description"); - final ParameterGroup p4 = new ParameterGroup() + final ParameterGroup parameterGroupFour = new ParameterGroup() .setDescription("description"); - assertEquals(p3, p4); + assertEquals(parameterGroupThree, parameterGroupFour); final Map parameters = ImmutableMap.of( "header_text", new Parameter().setDefaultValue(ParameterValue.of("Welcome")), @@ -72,16 +72,16 @@ public void testEquality() { "ios", ParameterValue.of("ios header text") )) ); - final ParameterGroup p5 = new ParameterGroup() + final ParameterGroup parameterGroupFive = new ParameterGroup() .setDescription("description") .setParameters(parameters); - final ParameterGroup p6 = new ParameterGroup() + final ParameterGroup parameterGroupSix = new ParameterGroup() .setDescription("description") .setParameters(parameters); - assertEquals(p5, p6); - assertNotEquals(p1, p3); - assertNotEquals(p1, p5); - assertNotEquals(p3, p5); + assertEquals(parameterGroupFive, parameterGroupSix); + assertNotEquals(parameterGroupOne, parameterGroupThree); + assertNotEquals(parameterGroupOne, parameterGroupFive); + assertNotEquals(parameterGroupThree, parameterGroupFive); } } diff --git a/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java b/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java index 414276229..952ea8b82 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ParameterTest.java @@ -32,12 +32,12 @@ public class ParameterTest { @Test public void testConstructor() { - final Parameter p = new Parameter(); + final Parameter parameter = new Parameter(); - assertNotNull(p.getConditionalValues()); - assertTrue(p.getConditionalValues().isEmpty()); - assertNull(p.getDefaultValue()); - assertNull(p.getDescription()); + assertNotNull(parameter.getConditionalValues()); + assertTrue(parameter.getConditionalValues().isEmpty()); + assertNull(parameter.getDefaultValue()); + assertNull(parameter.getDescription()); } @Test(expected = NullPointerException.class) @@ -47,46 +47,45 @@ public void testConstructorWithNullParameterResponse() { @Test(expected = NullPointerException.class) public void testSetNullConditionalValues() { - Parameter p = new Parameter(); - p.setConditionalValues(null); + Parameter parameter = new Parameter(); + parameter.setConditionalValues(null); } @Test public void testEquality() { - final Parameter p1 = new Parameter() + final Parameter parameterOne = new Parameter() .setDefaultValue(ParameterValue.of("hello")); - final Parameter p2 = new Parameter() + final Parameter parameterTwo = new Parameter() .setDefaultValue(ParameterValue.of("hello")); - assertEquals(p1, p2); + assertEquals(parameterOne, parameterTwo); - final Parameter p3 = new Parameter() + final Parameter parameterThree = new Parameter() .setDefaultValue(ParameterValue.inAppDefault()) .setDescription("greeting text"); - final Parameter p4 = new Parameter() + final Parameter parameterFour = new Parameter() .setDefaultValue(ParameterValue.inAppDefault()) .setDescription("greeting text"); - assertEquals(p3, p4); + assertEquals(parameterThree, parameterFour); final Map conditionalValues = ImmutableMap.of( "ios", ParameterValue.of("hello ios"), "android", ParameterValue.of("hello android"), "promo", ParameterValue.inAppDefault() ); - final Parameter p5 = new Parameter() + final Parameter parameterFive = new Parameter() .setDefaultValue(ParameterValue.inAppDefault()) .setDescription("greeting text") .setConditionalValues(conditionalValues); - final Parameter p6 = new Parameter() + final Parameter parameterSix = new Parameter() .setDefaultValue(ParameterValue.inAppDefault()) .setDescription("greeting text") .setConditionalValues(conditionalValues); - assertEquals(p5, p6); - assertNotEquals(p1, p3); - assertNotEquals(p1, p5); - assertNotEquals(p3, p5); + assertEquals(parameterFive, parameterSix); + assertNotEquals(parameterOne, parameterThree); + assertNotEquals(parameterOne, parameterFive); + assertNotEquals(parameterThree, parameterFive); } - } diff --git a/src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java b/src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java index c33158676..842fd808f 100644 --- a/src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/ParameterValueTest.java @@ -25,30 +25,30 @@ public class ParameterValueTest { @Test public void testCreateExplicitValue() { - final ParameterValue.Explicit pv = ParameterValue.of("title text"); + final ParameterValue.Explicit parameterValue = ParameterValue.of("title text"); - assertEquals("title text", pv.getValue()); + assertEquals("title text", parameterValue.getValue()); } @Test public void testCreateInAppDefault() { - final ParameterValue.InAppDefault pv = ParameterValue.inAppDefault(); + final ParameterValue.InAppDefault parameterValue = ParameterValue.inAppDefault(); - assertEquals(ParameterValue.InAppDefault.class, pv.getClass()); + assertEquals(ParameterValue.InAppDefault.class, parameterValue.getClass()); } @Test public void testEquality() { - ParameterValue.Explicit pv1 = ParameterValue.of("value"); - ParameterValue.Explicit pv2 = ParameterValue.of("value"); - ParameterValue.Explicit pv3 = ParameterValue.of("title"); + ParameterValue.Explicit parameterValueOne = ParameterValue.of("value"); + ParameterValue.Explicit parameterValueTwo = ParameterValue.of("value"); + ParameterValue.Explicit parameterValueThree = ParameterValue.of("title"); - assertEquals(pv1, pv2); - assertNotEquals(pv1, pv3); + assertEquals(parameterValueOne, parameterValueTwo); + assertNotEquals(parameterValueOne, parameterValueThree); - ParameterValue.InAppDefault pv4 = ParameterValue.inAppDefault(); - ParameterValue.InAppDefault pv5 = ParameterValue.inAppDefault(); + ParameterValue.InAppDefault parameterValueFour = ParameterValue.inAppDefault(); + ParameterValue.InAppDefault parameterValueFive = ParameterValue.inAppDefault(); - assertEquals(pv4, pv5); + assertEquals(parameterValueFour, parameterValueFive); } } diff --git a/src/test/java/com/google/firebase/remoteconfig/TemplateTest.java b/src/test/java/com/google/firebase/remoteconfig/TemplateTest.java index be2961e61..ce272301d 100644 --- a/src/test/java/com/google/firebase/remoteconfig/TemplateTest.java +++ b/src/test/java/com/google/firebase/remoteconfig/TemplateTest.java @@ -34,15 +34,15 @@ public class TemplateTest { @Test public void testConstructor() { - Template t = new Template(); - - assertNotNull(t.getParameters()); - assertNotNull(t.getConditions()); - assertNotNull(t.getParameterGroups()); - assertTrue(t.getParameters().isEmpty()); - assertTrue(t.getConditions().isEmpty()); - assertTrue(t.getParameterGroups().isEmpty()); - assertNull(t.getETag()); + Template template = new Template(); + + assertNotNull(template.getParameters()); + assertNotNull(template.getConditions()); + assertNotNull(template.getParameterGroups()); + assertTrue(template.getParameters().isEmpty()); + assertTrue(template.getConditions().isEmpty()); + assertTrue(template.getParameterGroups().isEmpty()); + assertNull(template.getETag()); } @Test(expected = NullPointerException.class) @@ -52,28 +52,28 @@ public void testConstructorWithNullTemplateResponse() { @Test(expected = NullPointerException.class) public void testSetNullParameters() { - Template t = new Template(); - t.setParameters(null); + Template template = new Template(); + template.setParameters(null); } @Test(expected = NullPointerException.class) public void testSetNullConditions() { - Template t = new Template(); - t.setConditions(null); + Template template = new Template(); + template.setConditions(null); } @Test(expected = NullPointerException.class) public void testSetNullParameterGroups() { - Template t = new Template(); - t.setParameterGroups(null); + Template template = new Template(); + template.setParameterGroups(null); } @Test public void testEquality() { - final Template t1 = new Template(); - final Template t2 = new Template(); + final Template templateOne = new Template(); + final Template templateTwo = new Template(); - assertEquals(t1, t2); + assertEquals(templateOne, templateTwo); final List conditions = ImmutableList.of( new Condition("ios_en", "exp ios") @@ -95,42 +95,42 @@ public void testEquality() { .setDescription("greeting text") .setConditionalValues(conditionalValues) ); - final Template t3 = new Template() + final Template templateThree = new Template() .setConditions(conditions) .setParameters(parameters); - final Template t4 = new Template() + final Template templateFour = new Template() .setConditions(conditions) .setParameters(parameters); - assertEquals(t3, t4); + assertEquals(templateThree, templateFour); final Map parameterGroups = ImmutableMap.of( "greetings_group", new ParameterGroup() .setDescription("description") .setParameters(parameters) ); - final Template t5 = new Template() + final Template templateFive = new Template() .setConditions(conditions) .setParameters(parameters) .setParameterGroups(parameterGroups); - final Template t6 = new Template() + final Template templateSix = new Template() .setConditions(conditions) .setParameters(parameters) .setParameterGroups(parameterGroups); - assertEquals(t5, t6); + assertEquals(templateFive, templateSix); - final Template t7 = new Template() + final Template templateSeven = new Template() .setETag("etag-123456789097-20"); - final Template t8 = new Template() + final Template templateEight = new Template() .setETag("etag-123456789097-20"); - assertEquals(t7, t8); - assertNotEquals(t1, t3); - assertNotEquals(t1, t5); - assertNotEquals(t1, t7); - assertNotEquals(t3, t5); - assertNotEquals(t3, t7); - assertNotEquals(t5, t7); + assertEquals(templateSeven, templateEight); + assertNotEquals(templateOne, templateThree); + assertNotEquals(templateOne, templateFive); + assertNotEquals(templateOne, templateSeven); + assertNotEquals(templateThree, templateFive); + assertNotEquals(templateThree, templateSeven); + assertNotEquals(templateFive, templateSeven); } }