MediaType { public static MediaType valueOf(String value) { String[] tokens = value.split("\\s*;\\s*"); if (tokens.length > 0) { String mimeType = tokens[0].trim(); if (mimeType.isEmpty()) { throw newInvalidMediaTypeException("value"); } Map<String, String> parameters = new HashMap<>(); for (int i = 1; i < tokens.length; ++i) { String[] keyValue = tokens[i].split("\\s*=\\s*"); if (keyValue.length != 2) { throw newInvalidMediaTypeException("value"); } parameters.put(keyValue[0], keyValue[1]); } return new MediaType(mimeType, parameters); } throw newInvalidMediaTypeException("value"); } private  MediaType(String mimeType, Map<String, String> parameters); static MediaType valueOf(String value); String mimeType(); Map<String, String> parameters();  }
@Test public void valueOfShouldThrowExceptionIfEmpty() { Throwable thrown = catchThrowable(() -> { MediaType.valueOf(""); }); assertThat(thrown).isInstanceOf(IllegalArgumentException.class); }
@Test public void valueOfShouldThrowExceptionIfTypeIsEmpty() { Throwable thrown = catchThrowable(() -> { MediaType.valueOf("; charset=utf-8"); }); assertThat(thrown).isInstanceOf(IllegalArgumentException.class); }