Skip to content

Commit 2f799fd

Browse files
committed
Fix log message
1 parent e8c015f commit 2f799fd

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/main/java/io/split/android/client/fallback/FallbackTreatmentsConfiguration.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.HashMap;
99
import java.util.Map;
1010
import java.util.Objects;
11+
1112
import io.split.android.client.utils.logger.Logger;
1213

1314
public final class FallbackTreatmentsConfiguration {
@@ -65,6 +66,9 @@ private Builder() {
6566
* @return this builder instance
6667
*/
6768
public Builder global(@Nullable FallbackTreatment global) {
69+
if (mGlobal != null && global != null) {
70+
Logger.w("Fallback treatments - You had previously set a global fallback. The new value will replace it");
71+
}
6872
mGlobal = global;
6973
return this;
7074
}
@@ -78,6 +82,9 @@ public Builder global(@Nullable FallbackTreatment global) {
7882
* @return this builder instance
7983
*/
8084
public Builder global(String treatment) {
85+
if (mGlobal != null) {
86+
Logger.w("Fallback treatments - You had previously set a global fallback. The new value will replace it");
87+
}
8188
mGlobal = new FallbackTreatment(treatment);
8289
return this;
8390
}
@@ -99,7 +106,7 @@ public Builder byFlag(@Nullable Map<String, FallbackTreatment> byFlag) {
99106
for (Map.Entry<String, FallbackTreatment> e : byFlag.entrySet()) {
100107
String key = e.getKey();
101108
if (mByFlag.containsKey(key)) {
102-
Logger.w(getLogMessage(key));
109+
Logger.w(getDuplicateFlagMessage(key));
103110
}
104111
mByFlag.put(key, e.getValue());
105112
}
@@ -123,7 +130,7 @@ public Builder byFlagStrings(@Nullable Map<String, String> byFlag) {
123130
for (Map.Entry<String, String> e : byFlag.entrySet()) {
124131
String key = e.getKey();
125132
if (mByFlag.containsKey(key)) {
126-
Logger.w(getLogMessage(key));
133+
Logger.w(getDuplicateFlagMessage(key));
127134
}
128135
mByFlag.put(key, new FallbackTreatment(e.getValue()));
129136
}
@@ -148,8 +155,8 @@ Builder sanitizer(FallbacksSanitizer sanitizer) {
148155
}
149156

150157
@NonNull
151-
private static String getLogMessage(String key) {
152-
return "Fallback treatments - Overriding existing fallback for flag '" + key + "' with latest value";
158+
private static String getDuplicateFlagMessage(String key) {
159+
return "Fallback treatments - Duplicate fallback for flag '" + key + "'. Overriding existing value.";
153160
}
154161
}
155162

src/test/java/io/split/android/client/fallback/FallbackTreatmentsConfigurationTest.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertFalse;
55
import static org.junit.Assert.assertNotEquals;
6-
import static org.junit.Assert.assertNull;
76
import static org.junit.Assert.assertSame;
7+
import static org.junit.Assert.assertNull;
88
import static org.junit.Assert.assertTrue;
99

1010
import org.junit.Test;
@@ -130,11 +130,10 @@ public void callingByFlagStringsAfterByFlagMergesResultsAndLogsWarning() {
130130
assertNull(cfg.getByFlag().get("flagA").getConfig());
131131
assertEquals("on", cfg.getByFlag().get("flagB").getTreatment());
132132
assertEquals("off", cfg.getByFlag().get("flagC").getTreatment());
133-
assertNull(cfg.getByFlag().get("flagC").getConfig());
134-
133+
// warning logged with expected content for overridden key
135134
ConcurrentLinkedDeque<String> warns = printer.getLoggedMessages().get(android.util.Log.WARN);
136135
assertFalse("Expected at least one warning", warns.isEmpty());
137-
boolean containsExpected = warns.stream().anyMatch(m -> m.contains("Overriding existing fallback for flag 'flagA'"));
136+
boolean containsExpected = warns.stream().anyMatch(m -> m.contains("Fallback treatments - Duplicate fallback for flag 'flagA'. Overriding existing value."));
138137
assertTrue("Expected warning mentioning overridden key 'flagA'", containsExpected);
139138
}
140139

0 commit comments

Comments
 (0)