### Question:
MediaTypeChecker { public boolean isAcceptValid(HttpHeaders headers) { String accept = headers.get(HttpHeaders.Names.ACCEPT); return ( Strings.isNullOrEmpty(accept) || accept.contains(ACCEPT_ALL) || accept.toLowerCase().contains(MEDIA_TYPE_APPLICATION_JSON)); }  boolean isContentTypeValid(HttpHeaders headers); boolean isAcceptValid(HttpHeaders headers);  }### Answer:
@Test public void acceptEmptyShouldBeValid() { HttpHeaders mockHeaders = mock(HttpHeaders.class); when(mockHeaders.get(HttpHeaders.Names.ACCEPT)).thenReturn(""); assertTrue("empty accept should be valid", mediaTypeChecker.isAcceptValid(mockHeaders)); }
@Test public void acceptAllShouldBeValid() { HttpHeaders mockHeaders = mock(HttpHeaders.class); when(mockHeaders.get(HttpHeaders.Names.ACCEPT)).thenReturn("** should be valid", mediaTypeChecker.isAcceptValid(mockHeaders)); }
@Test public void acceptJsonShouldBeValid() { HttpHeaders mockHeaders = mock(HttpHeaders.class); when(mockHeaders.get(HttpHeaders.Names.ACCEPT)).thenReturn("application/json"); assertTrue("accept application/json should be valid", mediaTypeChecker.isAcceptValid(mockHeaders)); }
@Test public void acceptAllWithCharsetQualityShouldBeValid() { HttpHeaders mockHeaders = mock(HttpHeaders.class); when(mockHeaders.get(HttpHeaders.Names.ACCEPT)).thenReturn("text/html,application/xhtml+xml,application/xml;q=0.9,**;q=0.8 should be valid", mediaTypeChecker.isAcceptValid(mockHeaders)); }
@Test public void acceptXmlShouldBeInvalid() { HttpHeaders mockHeaders = mock(HttpHeaders.class); when(mockHeaders.get(HttpHeaders.Names.ACCEPT)).thenReturn("text/html,application/xhtml+xml,application/xml;q=0.9"); assertFalse("accept text/html,application/xhtml+xml,application/xml;q=0.9 should be invalid", mediaTypeChecker.isAcceptValid(mockHeaders)); }