Skip to content

Commit

Permalink
Merge pull request #4 from configcat/user-improvements
Browse files Browse the repository at this point in the history
Allow empty string as id
  • Loading branch information
z4kn4fein authored Aug 14, 2020
2 parents 352e6d8 + 3ac9fa5 commit f24601d
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=5.1.0
version=5.1.1
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,10 @@ class MainActivity : AppCompatActivity() {

this@MainActivity.runOnUiThread {
var textField = findViewById<TextView>(R.id.editText)
textField.text = "isPOCFeatureEnabled: ${this.client.getValue(
textField.text = "isPOCFeatureEnabled: ${this.client.getKeyAndValue(
Boolean::class.java,
"isPOCFeatureEnabled",
user,
false
)}"
"ca36009d"
).value}"
}
}
}
7 changes: 2 additions & 5 deletions src/main/java/com/configcat/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ public class User {
private Map<String, String> attributes;

private User(String identifier, String email, String country, Map<String, String> custom) {
if(identifier == null || identifier.isEmpty())
throw new IllegalArgumentException("identifier is null or empty");

this.identifier = identifier;
this.identifier = identifier == null ? "" : identifier;
this.attributes = new TreeMap<>();
this.attributes.put("Identifier", identifier);

Expand Down Expand Up @@ -43,7 +40,7 @@ public static Builder newBuilder() {
}

String getAttribute(String key) {
if(key == null || key.isEmpty())
if(key == null)
throw new IllegalArgumentException("key is null or empty");

return this.attributes.get(key);
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/configcat/RolloutIntegrationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void testMatrixTest(String file, String sdkKey, String kind) throws FileN
String[] testObject = csvScanner.nextLine().split(";");

User user = null;
if(!testObject[0].isEmpty() && !testObject[0].equals("##null##"))
if(!testObject[0].equals("##null##"))
{
String email = "";
String country = "";
Expand Down
10 changes: 6 additions & 4 deletions src/test/java/com/configcat/UserTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
public class UserTests {

@Test
public void builderThrowsWhenArgumentInvalid() {
assertThrows(IllegalArgumentException.class, () -> User.newBuilder().build(null));
assertThrows(IllegalArgumentException.class, () -> User.newBuilder().build(""));
public void builderWorksWithEmptyOrNullId() {
User u1 = User.newBuilder().build(null);
assertEquals("", u1.getIdentifier());
User u2 = User.newBuilder().build("");
assertEquals("", u2.getIdentifier());
}

@Test
public void getAttributeThrowsWhenArgumentInvalid() {
User user = User.newBuilder().build("a");
assertThrows(IllegalArgumentException.class, () -> user.getAttribute(null));
assertThrows(IllegalArgumentException.class, () -> user.getAttribute(""));
assertNull(user.getAttribute(""));
}

@Test
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/testmatrix.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Identifier;Email;Country;Custom1;bool30TrueAdvancedRules;boolDefaultFalse;boolDefaultTrue;double25Pi25E25Gr25Zero;doubleDefaultPi;integer25One25Two25Three25FourAdvancedRules;integerDefaultOne;string25Cat25Dog25Falcon25Horse;string25Cat25Dog25Falcon25HorseAdvancedRules;string75Cat0Dog25Falcon0Horse;stringContainsDogDefaultCat;stringDefaultCat;stringIsInDogDefaultCat;stringIsNotInDogDefaultCat;stringNotContainsDogDefaultCat
##null##;;;;True;False;True;-1.0;3.1415;-1;1;Chicken;Chicken;Chicken;Cat;Cat;Cat;Cat;Cat
;;;;False;False;True;2.7182;3.1415;4;1;Dog;Dog;Cat;Cat;Cat;Cat;Cat;Cat
a@configcat.com;a@configcat.com;Hungary;admin;False;False;True;5.561;3.1415;5;1;Cat;Dolphin;Cat;Dog;Cat;Dog;Cat;Cat
b@configcat.com;b@configcat.com;Hungary;;False;False;True;5.561;3.1415;5;1;Falcon;Dolphin;Cat;Dog;Cat;Dog;Cat;Cat
c@configcat.com;c@configcat.com;United Kingdom;admin;False;False;True;5.561;3.1415;5;1;Dog;Dolphin;Falcon;Dog;Cat;Dog;Dog;Cat
Expand Down

0 comments on commit f24601d

Please sign in to comment.