Skip to content

Commit 43f7b01

Browse files
committed
add more tests for reasons
1 parent f803cd7 commit 43f7b01

File tree

2 files changed

+252
-56
lines changed

2 files changed

+252
-56
lines changed

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public Boolean evaluate(ProjectConfig config,
8585
Object userAttributeValue = attributes.get(name);
8686

8787
if (!"custom_attribute".equals(type)) {
88-
logger.warn("Audience condition \"{}\" uses an unknown condition type. You may need to upgrade to a newer release of the Optimizely SDK.", this);
88+
String message = reasons.addInfoF("Audience condition \"%s\" uses an unknown condition type. You may need to upgrade to a newer release of the Optimizely SDK.", this);
89+
logger.warn(message);
8990
return null; // unknown type
9091
}
9192
// check user attribute value is equal
@@ -100,26 +101,27 @@ public Boolean evaluate(ProjectConfig config,
100101
} catch(UnknownValueTypeException e) {
101102
if (!attributes.containsKey(name)) {
102103
//Missing attribute value
103-
logger.debug("Audience condition \"{}\" evaluated to UNKNOWN because no value was passed for user attribute \"{}\"", this, name);
104+
String message = reasons.addInfoF("Audience condition \"%s\" evaluated to UNKNOWN because no value was passed for user attribute \"%s\"", this, name);
105+
logger.debug(message);
104106
} else {
105107
//if attribute value is not valid
106108
if (userAttributeValue != null) {
107-
logger.warn(
108-
"Audience condition \"{}\" evaluated to UNKNOWN because a value of type \"{}\" was passed for user attribute \"{}\"",
109+
String message = reasons.addInfoF("Audience condition \"%s\" evaluated to UNKNOWN because a value of type \"%s\" was passed for user attribute \"%s\"",
109110
this,
110111
userAttributeValue.getClass().getCanonicalName(),
111112
name);
113+
logger.warn(message);
112114
} else {
113-
logger.debug(
114-
"Audience condition \"{}\" evaluated to UNKNOWN because a null value was passed for user attribute \"{}\"",
115-
this,
116-
name);
115+
String message = reasons.addInfoF("Audience condition \"%s\" evaluated to UNKNOWN because a null value was passed for user attribute \"%s\"", this, name);
116+
logger.debug(message);
117117
}
118118
}
119119
} catch (UnknownMatchTypeException | UnexpectedValueTypeException e) {
120-
logger.warn("Audience condition \"{}\" " + e.getMessage(), this);
120+
String message = reasons.addInfoF("Audience condition \"%s\" " + e.getMessage(), this);
121+
logger.warn(message);
121122
} catch (NullPointerException e) {
122-
logger.error("attribute or value null for match {}", match != null ? match : "legacy condition", e);
123+
String message = reasons.addInfoF("attribute or value null for match %s", match != null ? match : "legacy condition");
124+
logger.error(message, e);
123125
}
124126
return null;
125127
}

0 commit comments

Comments
 (0)