From d41b6ea8cde6eed61439446be6ed7f1deea38973 Mon Sep 17 00:00:00 2001 From: Gaston Thea Date: Thu, 7 Sep 2023 14:33:47 -0300 Subject: [PATCH] Fix test; remove duplicated code --- .../localhost/LocalhostSplitClient.java | 52 +++++++++---------- .../synchronizer/WorkManagerWrapperTest.java | 3 +- 2 files changed, 26 insertions(+), 29 deletions(-) diff --git a/src/main/java/io/split/android/client/localhost/LocalhostSplitClient.java b/src/main/java/io/split/android/client/localhost/LocalhostSplitClient.java index e82e33f16..b4dfbdbf3 100644 --- a/src/main/java/io/split/android/client/localhost/LocalhostSplitClient.java +++ b/src/main/java/io/split/android/client/localhost/LocalhostSplitClient.java @@ -149,13 +149,7 @@ public Map getTreatmentsByFlagSet(@NonNull String flagSet, @Null } catch (Exception exception) { Logger.e(exception); - Map result = new HashMap<>(); - Set namesByFlagSets = mSplitsStorage.getNamesByFlagSets(Collections.singletonList(flagSet)); - for (String featureFlagName : namesByFlagSets) { - result.put(featureFlagName, Treatments.CONTROL); - } - - return result; + return buildExceptionResult(Collections.singletonList(flagSet)); } } @@ -166,13 +160,7 @@ public Map getTreatmentsByFlagSets(@NonNull List flagSet } catch (Exception exception) { Logger.e(exception); - Map result = new HashMap<>(); - Set namesByFlagSets = mSplitsStorage.getNamesByFlagSets(flagSets); - for (String featureFlagName : namesByFlagSets) { - result.put(featureFlagName, Treatments.CONTROL); - } - - return result; + return buildExceptionResult(flagSets); } } @@ -183,13 +171,7 @@ public Map getTreatmentsWithConfigByFlagSet(@NonNull String } catch (Exception exception) { Logger.e(exception); - Map result = new HashMap<>(); - Set namesByFlagSets = mSplitsStorage.getNamesByFlagSets(Collections.singletonList(flagSet)); - for (String featureFlagName : namesByFlagSets) { - result.put(featureFlagName, new SplitResult(Treatments.CONTROL)); - } - - return result; + return buildExceptionResultWithConfig(Collections.singletonList(flagSet)); } } @@ -200,13 +182,7 @@ public Map getTreatmentsWithConfigByFlagSets(@NonNull List< } catch (Exception exception) { Logger.e(exception); - Map result = new HashMap<>(); - Set namesByFlagSets = mSplitsStorage.getNamesByFlagSets(flagSets); - for (String featureFlagName : namesByFlagSets) { - result.put(featureFlagName, new SplitResult(Treatments.CONTROL)); - } - - return result; + return buildExceptionResultWithConfig(flagSets); } } @@ -324,4 +300,24 @@ public boolean removeAttribute(String attributeName) { public boolean clearAttributes() { return true; } + + private Map buildExceptionResult(List flagSets) { + Map result = new HashMap<>(); + Set namesByFlagSets = mSplitsStorage.getNamesByFlagSets(flagSets); + for (String featureFlagName : namesByFlagSets) { + result.put(featureFlagName, Treatments.CONTROL); + } + + return result; + } + + private Map buildExceptionResultWithConfig(List flagSets) { + Map result = new HashMap<>(); + Set namesByFlagSets = mSplitsStorage.getNamesByFlagSets(flagSets); + for (String featureFlagName : namesByFlagSets) { + result.put(featureFlagName, new SplitResult(Treatments.CONTROL)); + } + + return result; + } } diff --git a/src/test/java/io/split/android/client/service/synchronizer/WorkManagerWrapperTest.java b/src/test/java/io/split/android/client/service/synchronizer/WorkManagerWrapperTest.java index 913e77351..a79498fa4 100644 --- a/src/test/java/io/split/android/client/service/synchronizer/WorkManagerWrapperTest.java +++ b/src/test/java/io/split/android/client/service/synchronizer/WorkManagerWrapperTest.java @@ -21,6 +21,7 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.concurrent.TimeUnit; @@ -72,7 +73,7 @@ public void setUp() throws Exception { splitClientConfig, "api_key", "test_database_name", - SplitFilter.bySet(Arrays.asList("set_1", "set_2")) + Collections.singletonList(SplitFilter.bySet(Arrays.asList("set_1", "set_2"))) ); }