@Test(expected = IllegalArgumentException.class) public void testNullMapIsNotTolerated() { toJson((Map<?, ?>) null); }
public static String toJson(Collection<?> collection) { if (collection == null) { throw new IllegalArgumentException("Method parameter collection must not be null"); } return collection.stream() .map(JsonUtil::toJson) .reduce((l, r) -> l + "," + r) .map(s -> '[' + s + ']') .orElse("[]"); }
JsonUtil { public static String toJson(Collection<?> collection) { if (collection == null) { throw new IllegalArgumentException("Method parameter collection must not be null"); } return collection.stream() .map(JsonUtil::toJson) .reduce((l, r) -> l + "," + r) .map(s -> '[' + s + ']') .orElse("[]"); } }
JsonUtil { public static String toJson(Collection<?> collection) { if (collection == null) { throw new IllegalArgumentException("Method parameter collection must not be null"); } return collection.stream() .map(JsonUtil::toJson) .reduce((l, r) -> l + "," + r) .map(s -> '[' + s + ']') .orElse("[]"); } private  JsonUtil(); }
JsonUtil { public static String toJson(Collection<?> collection) { if (collection == null) { throw new IllegalArgumentException("Method parameter collection must not be null"); } return collection.stream() .map(JsonUtil::toJson) .reduce((l, r) -> l + "," + r) .map(s -> '[' + s + ']') .orElse("[]"); } private  JsonUtil(); static String toJson(Collection<?> collection); static String toJson(Map<?, ?> map); }
JsonUtil { public static String toJson(Collection<?> collection) { if (collection == null) { throw new IllegalArgumentException("Method parameter collection must not be null"); } return collection.stream() .map(JsonUtil::toJson) .reduce((l, r) -> l + "," + r) .map(s -> '[' + s + ']') .orElse("[]"); } private  JsonUtil(); static String toJson(Collection<?> collection); static String toJson(Map<?, ?> map);  }