Open drewwills opened 6 years ago
I was trying to run this code, with the help of @ChristianMurphy, I am able to run through gradlew check
But we observed only test cases in the package runs through "check" are the ones defined in Groovy Test, the ones defined in
I'm not confident that the second criteria implemented by the ValueMissingTester
-- "Tests whether the attribute is null or none of the values of the attribute equal the specified attribute value" -- provides any value to anyone. (I had no idea it was there until I encountered this error.)
I think we could make this task simpler by changing the class to check for null or an empty array. No type awareness required.
`
@Override
public boolean test(IPerson person) {
// Get the list of values for the attribute
Object[] vals = person.getAttributeValues(getAttributeName());
// No values, test passed
if (vals == null) {
return true;
} else {
// Loop through the values of the attribute, if one is equal
// to the test case the test fails and returns false
for (int i = 0; i < vals.length; i++) {
Object obj = (Object) vals[i];
if (obj != null) {
String val = getStringCastedValue(obj);
if (val.equalsIgnoreCase(testValue)) {
return false;
}
}
}
// None of the values equaled the test case, test passed
return true;
}
}
private String getStringCastedValue(Object obj) {
if (obj instanceof String) {
return (String) obj;
} else if (obj instanceof Long || obj instanceof Double || obj instanceof Boolean || obj instanceof Byte
|| obj instanceof Character || obj instanceof Integer || obj instanceof Float || obj instanceof Short) {
return String.valueOf(obj);
}
return "";
}
`
The changed code methods are added here, it would be easy to merge only these 2 methods.
A good start -- could you put it in a pull request so we can do line-by-line commenting?
I am not able to create a Pull Request from the main branch, so I created my own repository from uPortal and created a branch from it and then created a Pull Request from that as below:
Describe the bug
In ancient times user attributes always had to be Strings. That hasn't been the case for a long time, but the
ValueMissingTester
missed the memo.To Reproduce
Stack Trace