ContentType { public static ContentType createContentType(String contentTypeString) { ContentType contentType = getDefaultContentType(contentTypeString); if (contentType != null) { return contentType; } return new ContentType(contentTypeString); } private  ContentType(String contentTypeString); @Override String toString(); @Override boolean equals(Object object); @Override int hashCode(); static ContentType createContentType(String contentTypeString); static final ContentType CONTENT_TYPE_APPLICATION_JSON; static final ContentType CONTENT_TYPE_APPLICATION_XML; static final ContentType CONTENT_TYPE_TEXT_JSON; static final ContentType CONTENT_TYPE_TEXT_XML; static final ContentType CONTENT_TYPE_TEXT_PLAIN; }
@Test(expected = NullPointerException.class) public void createContentTypeShouldThrowNpeWhenContentTypeStringIsNull() { String nullContentTypeString = null; ContentType.createContentType(nullContentTypeString); }
@Test(expected = IllegalArgumentException.class) public void createContentTypeShouldThrowIllegalArgumentExceptionWhenContentTypeStringIsEmpty() { String emptyContentTypeString = ""; ContentType.createContentType(emptyContentTypeString); }
@Test public void createApplicationJsonContentTypeShouldReturnSameInstanceWhenDefaultBuiltInInstanceAlreadyExists() { String applicationJsonContentTypeString = "application/json"; ContentType applicationJsonContentType = ContentType.createContentType(applicationJsonContentTypeString); ContentType otherApplicationJsonContentType = ContentType.createContentType(applicationJsonContentTypeString); assertTrue(applicationJsonContentType == otherApplicationJsonContentType); }
@Test public void createApplicationXmlContentTypeShouldReturnSameInstanceWhenDefaultBuiltInInstanceAlreadyExists() { String applicationXmlContentTypeString = "application/xml"; ContentType applicationXmlContentType = ContentType.createContentType(applicationXmlContentTypeString); ContentType otherApplicationXmlContentType = ContentType.createContentType(applicationXmlContentTypeString); assertTrue(applicationXmlContentType == otherApplicationXmlContentType); }
@Test public void createTextJsonContentTypeShouldReturnSameInstanceWhenDefaultBuiltInInstanceAlreadyExists() { String textJsonContentTypeString = "text/json"; ContentType textJsonContentType = ContentType.createContentType(textJsonContentTypeString); ContentType otherTextJsonContentType = ContentType.createContentType(textJsonContentTypeString); assertTrue(textJsonContentType == otherTextJsonContentType); }
@Test public void createTextXmlContentTypeShouldReturnSameInstanceWhenDefaultBuiltInInstanceAlreadyExists() { String textXmlContentTypeString = "text/xml"; ContentType textXmlContentType = ContentType.createContentType(textXmlContentTypeString); ContentType otherTextXmlContentType = ContentType.createContentType(textXmlContentTypeString); assertTrue(textXmlContentType == otherTextXmlContentType); }
@Test public void createTextPlainContentTypeShouldReturnSameInstanceWhenDefaultBuiltInInstanceAlreadyExists() { String textPlainContentTypeString = "text/plain"; ContentType textPlainContentType = ContentType.createContentType(textPlainContentTypeString); ContentType otherTextPlainContentType = ContentType.createContentType(textPlainContentTypeString); assertTrue(textPlainContentType == otherTextPlainContentType); }