### Question:
StaticContentHandler { static void processEtag(String etag, RequestHeaders requestHeaders, ResponseHeaders responseHeaders) { if (etag == null || etag.isEmpty()) { return; } etag = unquoteETag(etag); responseHeaders.put(Http.Header.ETAG, '"' + etag + '"'); List<String> ifNoneMatches = requestHeaders.values(Http.Header.IF_NONE_MATCH); for (String ifNoneMatch : ifNoneMatches) { ifNoneMatch = unquoteETag(ifNoneMatch); if ("*".equals(ifNoneMatch) || ifNoneMatch.equals(etag)) { throw new HttpException("Accepted by If-None-Match header!", Http.Status.NOT_MODIFIED_304); } } List<String> ifMatches = requestHeaders.values(Http.Header.IF_MATCH); if (!ifMatches.isEmpty()) { boolean ifMatchChecked = false; for (String ifMatch : ifMatches) { ifMatch = unquoteETag(ifMatch); if ("*".equals(ifMatch) || ifMatch.equals(etag)) { ifMatchChecked = true; break; } } if (!ifMatchChecked) { throw new HttpException("Not accepted by If-Match header!", Http.Status.PRECONDITION_FAILED_412); } } } StaticContentHandler(String welcomeFilename, ContentTypeSelector contentTypeSelector);   }### Answer:
@Test public void etag_InNonMatch_NotAccept() throws Exception { RequestHeaders req = mock(RequestHeaders.class); when(req.values(Http.Header.IF_NONE_MATCH)).thenReturn(List.of("\"ccc\"", "\"ddd\"")); when(req.values(Http.Header.IF_MATCH)).thenReturn(Collections.emptyList()); ResponseHeaders res = mock(ResponseHeaders.class); StaticContentHandler.processEtag("aaa", req, res); verify(res).put(Http.Header.ETAG, "\"aaa\""); }
@Test public void etag_InNonMatch_Accept() throws Exception { RequestHeaders req = mock(RequestHeaders.class); when(req.values(Http.Header.IF_NONE_MATCH)).thenReturn(List.of("\"ccc\"", "W/\"aaa\"")); when(req.values(Http.Header.IF_MATCH)).thenReturn(Collections.emptyList()); ResponseHeaders res = mock(ResponseHeaders.class); assertHttpException(() -> StaticContentHandler.processEtag("aaa", req, res), Http.Status.NOT_MODIFIED_304); verify(res).put(Http.Header.ETAG, "\"aaa\""); }
@Test public void etag_InMatch_NotAccept() throws Exception { RequestHeaders req = mock(RequestHeaders.class); when(req.values(Http.Header.IF_MATCH)).thenReturn(List.of("\"ccc\"", "\"ddd\"")); when(req.values(Http.Header.IF_NONE_MATCH)).thenReturn(Collections.emptyList()); ResponseHeaders res = mock(ResponseHeaders.class); assertHttpException(() -> StaticContentHandler.processEtag("aaa", req, res), Http.Status.PRECONDITION_FAILED_412); verify(res).put(Http.Header.ETAG, "\"aaa\""); }
@Test public void etag_InMatch_Accept() throws Exception { RequestHeaders req = mock(RequestHeaders.class); when(req.values(Http.Header.IF_MATCH)).thenReturn(List.of("\"ccc\"", "\"aaa\"")); when(req.values(Http.Header.IF_NONE_MATCH)).thenReturn(Collections.emptyList()); ResponseHeaders res = mock(ResponseHeaders.class); StaticContentHandler.processEtag("aaa", req, res); verify(res).put(Http.Header.ETAG, "\"aaa\""); }