Skip to content

Commit 6af5312

Browse files
committed
Allowed numbers to parse
1 parent 61f42fc commit 6af5312

File tree

6 files changed

+31
-22
lines changed

6 files changed

+31
-22
lines changed

core-api/src/main/java/com/optimizely/ab/config/audience/match/SemanticVersionEqualsMatch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ protected SemanticVersionEqualsMatch(String value) {
2828
@Nullable
2929
public Boolean eval(Object attributeValue) {
3030
try {
31-
if (this.value != null && attributeValue instanceof String) {
31+
if (this.value != null && attributeValue != null) {
3232
SemanticVersion conditionalVersion = new SemanticVersion(value);
33-
SemanticVersion userSemanticVersion = new SemanticVersion((String) attributeValue);
33+
SemanticVersion userSemanticVersion = new SemanticVersion(attributeValue.toString());
3434
return userSemanticVersion.compareTo(conditionalVersion) == 0;
3535
}
3636
} catch (Exception e) {

core-api/src/main/java/com/optimizely/ab/config/audience/match/SemanticVersionGEMatch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ protected SemanticVersionGEMatch(String value) {
2828
@Nullable
2929
public Boolean eval(Object attributeValue) {
3030
try {
31-
if (this.value != null && attributeValue instanceof String) {
31+
if (this.value != null && attributeValue != null) {
3232
SemanticVersion conditionalVersion = new SemanticVersion(value);
33-
SemanticVersion userSemanticVersion = new SemanticVersion((String) attributeValue);
33+
SemanticVersion userSemanticVersion = new SemanticVersion(attributeValue.toString());
3434
return userSemanticVersion.compareTo(conditionalVersion) >= 0;
3535
}
3636
} catch (Exception e) {

core-api/src/main/java/com/optimizely/ab/config/audience/match/SemanticVersionGTMatch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ protected SemanticVersionGTMatch(String target) {
2828
@Nullable
2929
public Boolean eval(Object attributeValue) {
3030
try {
31-
if (this.value != null && attributeValue instanceof String) {
31+
if (this.value != null && attributeValue != null) {
3232
SemanticVersion conditionalVersion = new SemanticVersion(value);
33-
SemanticVersion userSemanticVersion = new SemanticVersion((String) attributeValue);
33+
SemanticVersion userSemanticVersion = new SemanticVersion(attributeValue.toString());
3434
return userSemanticVersion.compareTo(conditionalVersion) > 0;
3535
}
3636
} catch (Exception e) {

core-api/src/main/java/com/optimizely/ab/config/audience/match/SemanticVersionLEMatch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ protected SemanticVersionLEMatch(String target) {
2828
@Nullable
2929
public Boolean eval(Object attributeValue) {
3030
try {
31-
if (this.value != null && attributeValue instanceof String) {
31+
if (this.value != null && attributeValue != null) {
3232
SemanticVersion conditionalVersion = new SemanticVersion(value);
33-
SemanticVersion userSemanticVersion = new SemanticVersion((String) attributeValue);
33+
SemanticVersion userSemanticVersion = new SemanticVersion(attributeValue.toString());
3434
return userSemanticVersion.compareTo(conditionalVersion) <= 0;
3535
}
3636
} catch (Exception e) {

core-api/src/main/java/com/optimizely/ab/config/audience/match/SemanticVersionLTMatch.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ protected SemanticVersionLTMatch(String target) {
2828
@Nullable
2929
public Boolean eval(Object attributeValue) {
3030
try {
31-
if (this.value != null && attributeValue instanceof String) {
31+
if (this.value != null && attributeValue != null) {
3232
SemanticVersion conditionalVersion = new SemanticVersion(value);
33-
SemanticVersion userSemanticVersion = new SemanticVersion((String) attributeValue);
33+
SemanticVersion userSemanticVersion = new SemanticVersion(attributeValue.toString());
3434
return userSemanticVersion.compareTo(conditionalVersion) < 0;
3535
}
3636
} catch (Exception e) {

core-api/src/test/java/com/optimizely/ab/config/audience/AudienceConditionEvaluationTest.java

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -876,11 +876,11 @@ public void substringMatchConditionEvaluatesNull() {
876876

877877
// Test SemanticVersionEqualsMatch returns null if given invalid value type
878878
@Test
879-
public void testSemanticVersionEqualsMatchInvalidInput() {
879+
public void testSemanticVersionEqualsMatchNumberInput() {
880880
Map testAttributes = new HashMap<String, String>();
881-
testAttributes.put("version", 2.0);
882-
UserAttribute testInstanceString = new UserAttribute("version", "custom_attribute", "semver_eq", "2.0.0");
883-
assertNull(testInstanceString.evaluate(null, testAttributes));
881+
testAttributes.put("version", 2.1);
882+
UserAttribute testInstanceString = new UserAttribute("version", "custom_attribute", "semver_eq", "2.1");
883+
assertTrue(testInstanceString.evaluate(null, testAttributes));
884884
}
885885

886886
// Test SemanticVersionEqualsMatch returns null if given invalid UserCondition Variable type
@@ -903,28 +903,37 @@ public void testSemanticVersionGTMatchInvalidInput() {
903903

904904
// Test SemanticVersionGEMatch returns null if given invalid value type
905905
@Test
906-
public void testSemanticVersionGEMatchInvalidInput() {
906+
public void testSemanticVersionGEMatchNumberInput() {
907907
Map testAttributes = new HashMap<String, String>();
908-
testAttributes.put("version", 2);
909-
UserAttribute testInstanceString = new UserAttribute("version", "custom_attribute", "semver_ge", "2.0.0");
910-
assertNull(testInstanceString.evaluate(null, testAttributes));
908+
testAttributes.put("version", 3);
909+
UserAttribute testInstanceString = new UserAttribute("version", "custom_attribute", "semver_ge", "2");
910+
assertTrue(testInstanceString.evaluate(null, testAttributes));
911911
}
912912

913913
// Test SemanticVersionLTMatch returns null if given invalid value type
914914
@Test
915-
public void testSemanticVersionLTMatchInvalidInput() {
915+
public void testSemanticVersionLTMatchNumberInput() {
916916
Map testAttributes = new HashMap<String, String>();
917917
testAttributes.put("version", 2);
918918
UserAttribute testInstanceString = new UserAttribute("version", "custom_attribute", "semver_lt", "2.0.0");
919-
assertNull(testInstanceString.evaluate(null, testAttributes));
919+
assertTrue(testInstanceString.evaluate(null, testAttributes));
920+
}
921+
922+
// Test SemanticVersionLEMatch returns null if given invalid value type
923+
@Test
924+
public void testSemanticVersionLEMatchNumberInput() {
925+
Map testAttributes = new HashMap<String, String>();
926+
testAttributes.put("version", 2.1);
927+
UserAttribute testInstanceString = new UserAttribute("version", "custom_attribute", "semver_le", "2.1.0");
928+
assertTrue(testInstanceString.evaluate(null, testAttributes));
920929
}
921930

922931
// Test SemanticVersionLEMatch returns null if given invalid value type
923932
@Test
924933
public void testSemanticVersionLEMatchInvalidInput() {
925934
Map testAttributes = new HashMap<String, String>();
926-
testAttributes.put("version", 2);
927-
UserAttribute testInstanceString = new UserAttribute("version", "custom_attribute", "semver_le", "2.0.0");
935+
testAttributes.put("version", true);
936+
UserAttribute testInstanceString = new UserAttribute("version", "custom_attribute", "semver_le", "2.1.0");
928937
assertNull(testInstanceString.evaluate(null, testAttributes));
929938
}
930939

0 commit comments

Comments
 (0)