ResourceUtils { public static Optional<String> getOptionalForParameter(String parameterStr) { if (parameterStr == null || parameterStr.isEmpty()) { return Optional.absent(); } else { return Optional.of(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 testGetOptionalForParameter() { Optional<String> result = ResourceUtils.getOptionalForParameter(null); assertEquals(Optional.absent(), result); result = ResourceUtils.getOptionalForParameter(""); assertEquals(Optional.absent(), result); String param = "some-param"; result = ResourceUtils.getOptionalForParameter(param); assertEquals(param, result.get()); }