Skip to content

Commit

Permalink
Fix test; remove duplicated code
Browse files Browse the repository at this point in the history
gthea committed Sep 7, 2023
1 parent a0b9a08 commit d41b6ea
Showing 2 changed files with 26 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -149,13 +149,7 @@ public Map<String, String> getTreatmentsByFlagSet(@NonNull String flagSet, @Null
} catch (Exception exception) {
Logger.e(exception);

Map<String, String> result = new HashMap<>();
Set<String> 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<String, String> getTreatmentsByFlagSets(@NonNull List<String> flagSet
} catch (Exception exception) {
Logger.e(exception);

Map<String, String> result = new HashMap<>();
Set<String> namesByFlagSets = mSplitsStorage.getNamesByFlagSets(flagSets);
for (String featureFlagName : namesByFlagSets) {
result.put(featureFlagName, Treatments.CONTROL);
}

return result;
return buildExceptionResult(flagSets);
}
}

@@ -183,13 +171,7 @@ public Map<String, SplitResult> getTreatmentsWithConfigByFlagSet(@NonNull String
} catch (Exception exception) {
Logger.e(exception);

Map<String, SplitResult> result = new HashMap<>();
Set<String> 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<String, SplitResult> getTreatmentsWithConfigByFlagSets(@NonNull List<
} catch (Exception exception) {
Logger.e(exception);

Map<String, SplitResult> result = new HashMap<>();
Set<String> 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<String, String> buildExceptionResult(List<String> flagSets) {
Map<String, String> result = new HashMap<>();
Set<String> namesByFlagSets = mSplitsStorage.getNamesByFlagSets(flagSets);
for (String featureFlagName : namesByFlagSets) {
result.put(featureFlagName, Treatments.CONTROL);
}

return result;
}

private Map<String, SplitResult> buildExceptionResultWithConfig(List<String> flagSets) {
Map<String, SplitResult> result = new HashMap<>();
Set<String> namesByFlagSets = mSplitsStorage.getNamesByFlagSets(flagSets);
for (String featureFlagName : namesByFlagSets) {
result.put(featureFlagName, new SplitResult(Treatments.CONTROL));
}

return result;
}
}
Original file line number Diff line number Diff line change
@@ -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")))
);
}

0 comments on commit d41b6ea

Please sign in to comment.