Skip to content

Commit

Permalink
[SDKS-7516] Pr suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
nmayorsplit committed Sep 11, 2023
1 parent 00dc5d5 commit d7386d5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 11 deletions.
4 changes: 2 additions & 2 deletions client/src/main/java/io/split/client/SplitClientConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Properties;
import java.util.concurrent.ThreadFactory;

import static io.split.client.utils.FlagSetSanitizer.sanitizeFlagSet;
import static io.split.client.utils.FlagSetsValidator.cleanup;

/**
* Configurations for the SplitClient.
Expand Down Expand Up @@ -922,7 +922,7 @@ public Builder customStorageWrapper(CustomStorageWrapper customStorageWrapper) {
* @return this builder
*/
public Builder flagSetsFilter(List<String> flagSetsFilter) {
_flagSetsFilter = sanitizeFlagSet(flagSetsFilter);
_flagSetsFilter = cleanup(flagSetsFilter);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@
import java.util.regex.Pattern;
import java.util.stream.Collectors;

public final class FlagSetSanitizer {
public final class FlagSetsValidator {

private static final String FLAG_SET_REGEX = "^[a-z0-9][_a-z0-9]{0,49}$";
private static final Logger _log = LoggerFactory.getLogger(FlagSetSanitizer.class);
private static final Logger _log = LoggerFactory.getLogger(FlagSetsValidator.class);

private FlagSetSanitizer() {
private FlagSetsValidator() {
throw new IllegalStateException("Utility class");
}

public static List<String> sanitizeFlagSet(List<String> flagSets) {
public static List<String> cleanup(List<String> flagSets) {
if (flagSets == null || flagSets.isEmpty()) {
_log.error("FlagSets must be a non-empty list.");
return new ArrayList<>();
Expand All @@ -43,4 +43,8 @@ public static List<String> sanitizeFlagSet(List<String> flagSets) {
}
return sanitizedFlagSets.stream().sorted().collect(Collectors.toList());
}

public static Boolean isValid(String value) {
return value != null && value.trim().matches(FLAG_SET_REGEX);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@
import java.util.ArrayList;
import java.util.List;

import static io.split.client.utils.FlagSetsValidator.cleanup;
import static io.split.client.utils.FlagSetsValidator.isValid;

public class FlagSetSanitizerTest {

@Test
public void testEmptyFlagSets() {
List<String> flagSets = new ArrayList<>();
List<String> cleanFlagSets = FlagSetSanitizer.sanitizeFlagSet(flagSets);
List<String> cleanFlagSets = cleanup(flagSets);
Assert.assertTrue(cleanFlagSets.isEmpty());
}

Expand All @@ -20,7 +23,7 @@ public void testUpperFlagSets() {
List<String> flagSets = new ArrayList<>();
flagSets.add("Test1");
flagSets.add("TEST2");
List<String> cleanFlagSets = FlagSetSanitizer.sanitizeFlagSet(flagSets);
List<String> cleanFlagSets = cleanup(flagSets);
Assert.assertEquals("test1", cleanFlagSets.get(0));
Assert.assertEquals("test2", cleanFlagSets.get(1));
}
Expand All @@ -30,7 +33,7 @@ public void testTrimFlagSets() {
List<String> flagSets = new ArrayList<>();
flagSets.add(" test1");
flagSets.add(" test2 ");
List<String> cleanFlagSets = FlagSetSanitizer.sanitizeFlagSet(flagSets);
List<String> cleanFlagSets = cleanup(flagSets);
Assert.assertEquals("test1", cleanFlagSets.get(0));
Assert.assertEquals("test2", cleanFlagSets.get(1));
}
Expand All @@ -40,7 +43,7 @@ public void testRegexFlagSets() {
List<String> flagSets = new ArrayList<>();
flagSets.add(" test1");
flagSets.add(" test-2 ");
List<String> cleanFlagSets = FlagSetSanitizer.sanitizeFlagSet(flagSets);
List<String> cleanFlagSets = cleanup(flagSets);
Assert.assertEquals(1, cleanFlagSets.size());
Assert.assertEquals("test1", cleanFlagSets.get(0));
}
Expand All @@ -50,8 +53,21 @@ public void testDuplicateFlagSets() {
List<String> flagSets = new ArrayList<>();
flagSets.add(" test1");
flagSets.add(" test1 ");
List<String> cleanFlagSets = FlagSetSanitizer.sanitizeFlagSet(flagSets);
List<String> cleanFlagSets = cleanup(flagSets);
Assert.assertEquals(1, cleanFlagSets.size());
Assert.assertEquals("test1", cleanFlagSets.get(0));
}

@Test
public void testIsValid(){
Assert.assertTrue(isValid(" test1 "));
}

@Test
public void testIsNotValid(){
Assert.assertFalse(isValid(" test 1 "));
Assert.assertFalse(isValid("Test1 "));
Assert.assertFalse(isValid(""));
Assert.assertFalse(isValid(null));
}
}

0 comments on commit d7386d5

Please sign in to comment.