bonii-xx commented on a change in pull request #696:
URL: https://github.com/apache/commons-lang/pull/696#discussion_r555729693
##########
File path: src/test/java/org/apache/commons/lang3/EnumUtilsTest.java
##########
@@ -163,6 +165,26 @@ public void test_getEnumIgnoreCase_defaultEnum() {
assertNull(EnumUtils.getEnumIgnoreCase(Traffic.class, "PURPLE", null));
}
+ @Test
+ public void test_getEnumByPredicate() {
+ assertEquals(WithExtraData.A,
EnumUtils.getEnumByPredicate(WithExtraData.class, WithExtraData::isA).get());
+ assertNotEquals(WithExtraData.A,
EnumUtils.getEnumByPredicate(WithExtraData.class, WithExtraData::isNotA).get());
+ assertEquals(WithExtraData.A,
EnumUtils.getEnumByPredicate(WithExtraData.class, value -> true).get());
+ assertEquals(Optional.empty(),
EnumUtils.getEnumByPredicate(WithExtraData.class, value -> false));
+ }
+
+ @Test
+ public void test_getEnumByPredicate_nullInputs() {
+ assertFalse(EnumUtils.getEnumByPredicate(null,
WithExtraData::isA).isPresent());
+ assertFalse(EnumUtils.getEnumByPredicate(WithExtraData.class,
null).isPresent());
+ }
+
+ @Test
+ public void test_getEnumByPredicate_nonEnumClass() {
+ final Class rawType = Object.class;
+ assertFalse(EnumUtils.getEnumByPredicate(rawType, null).isPresent());
Review comment:
Thanks, had it named differently before, but decided to align the naming
with the other enum tests 🤦
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]