ResourceUtils { public static Optional<Boolean> getOptionalForParameterAsBool(String parameterStr) { if (parameterStr == null || parameterStr.isEmpty()) { return Optional.absent(); } else { return Optional.of(Boolean.parseBoolean(parameterStr)); } }  static Optional<String> getOptionalForParameter(String parameterStr); static Optional<Integer> getOptionalForParameterAsInt(String parameterStr); static Optional<Boolean> getOptionalForParameterAsBool(String parameterStr); static List<T> getListFromNullable(@Nullable List<T> list);  }
@Test public void testGetOptionalForParameterAsBool() { Optional<Boolean> result = ResourceUtils.getOptionalForParameterAsBool(null); assertEquals(Optional.absent(), result); result = ResourceUtils.getOptionalForParameterAsBool(""); assertEquals(Optional.absent(), result); boolean value = false; result = ResourceUtils.getOptionalForParameterAsBool(Boolean.toString(value)); assertEquals(value, result.get().booleanValue()); }