Strings { public static Boolean toBoolean(String s) { String value = trimToNull(s); if (value == null) { return null; } value = value.toLowerCase(); if (trueValues.contains(value)) { return Boolean.TRUE; } if (falseValues.contains(value)) { return Boolean.FALSE; } throw new IllegalArgumentException("Invalid boolean value '" + s + "'"); }  static String join(Iterable<?> col, String separator); static boolean isBlank(String s); static boolean isNotBlank(String s); static boolean isEmpty(String s); static boolean isNotEmpty(String s); static List<String> splitAndTrim(String value, String regex); static String trim(String s); static String trimToNull(String s); static String joinClassNames(Iterable<?> iterable); static Boolean toBoolean(String s);  }
@Test void testToBoolean() { assertNull(Strings.toBoolean(null)); assertNull(Strings.toBoolean("")); assertNull(Strings.toBoolean(" ")); assertEquals(Boolean.TRUE, Strings.toBoolean("true")); assertEquals(Boolean.TRUE, Strings.toBoolean(" TRUE ")); assertEquals(Boolean.TRUE, Strings.toBoolean("on")); assertEquals(Boolean.TRUE, Strings.toBoolean(" ON ")); assertEquals(Boolean.TRUE, Strings.toBoolean("yes")); assertEquals(Boolean.TRUE, Strings.toBoolean(" YES ")); assertEquals(Boolean.TRUE, Strings.toBoolean("1")); assertEquals(Boolean.TRUE, Strings.toBoolean(" 1 ")); assertEquals(Boolean.FALSE, Strings.toBoolean("false")); assertEquals(Boolean.FALSE, Strings.toBoolean(" FALSE ")); assertEquals(Boolean.FALSE, Strings.toBoolean("off")); assertEquals(Boolean.FALSE, Strings.toBoolean(" OFF ")); assertEquals(Boolean.FALSE, Strings.toBoolean("no")); assertEquals(Boolean.FALSE, Strings.toBoolean(" NO ")); assertEquals(Boolean.FALSE, Strings.toBoolean("0")); assertEquals(Boolean.FALSE, Strings.toBoolean(" 0 ")); }
@Test void testToBooleanThrowsIfStringIsInvalid() { assertThrows(IllegalArgumentException.class, () -> Strings.toBoolean("foo")); }