### Question:
MediaTypeChecker { public boolean isContentTypeValid(HttpHeaders headers) { String contentType = headers.get(HttpHeaders.Names.CONTENT_TYPE); return (Strings.isNullOrEmpty(contentType) || contentType.toLowerCase().contains(MEDIA_TYPE_APPLICATION_JSON)); }  boolean isContentTypeValid(HttpHeaders headers); boolean isAcceptValid(HttpHeaders headers);  }### Answer:
@Test public void contentTypeEmptyShouldBeValid() { HttpHeaders mockHeaders = mock(HttpHeaders.class); when(mockHeaders.get(HttpHeaders.Names.CONTENT_TYPE)).thenReturn(""); assertTrue("empty content-type should be valid", mediaTypeChecker.isContentTypeValid(mockHeaders)); }
@Test public void contentTypeJsonShouldBeValid() { HttpHeaders mockHeaders = mock(HttpHeaders.class); when(mockHeaders.get(HttpHeaders.Names.CONTENT_TYPE)).thenReturn("application/json"); assertTrue("content-type application/json should be valid", mediaTypeChecker.isContentTypeValid(mockHeaders)); }
@Test public void contentTypeJsonMixedCaseShouldBeValid() { HttpHeaders mockHeaders = mock(HttpHeaders.class); when(mockHeaders.get(HttpHeaders.Names.CONTENT_TYPE)).thenReturn("aPpLiCaTiOn/JSON"); assertTrue("content-type aPpLiCaTiOn/JSON should be valid", mediaTypeChecker.isContentTypeValid(mockHeaders)); }
@Test public void contentTypeJsonWithCharsetShouldBeValid() { HttpHeaders mockHeaders = mock(HttpHeaders.class); when(mockHeaders.get(HttpHeaders.Names.CONTENT_TYPE)).thenReturn("application/json; charset=wtf-8"); assertTrue("content-type application/json should be valid", mediaTypeChecker.isContentTypeValid(mockHeaders)); }
@Test public void contentTypePdfShouldBeInvalid() { HttpHeaders mockHeaders = mock(HttpHeaders.class); when(mockHeaders.get(HttpHeaders.Names.CONTENT_TYPE)).thenReturn("application/pdf"); assertFalse("content-type application/pdf should be invalid", mediaTypeChecker.isContentTypeValid(mockHeaders)); }