OrderedContentTypeDetector implements ContentTypeDetector { @Override public FilterEngine.ContentType detect(final WebResourceRequest request) { FilterEngine.ContentType contentType; for (final ContentTypeDetector detector : detectors) { contentType = detector.detect(request); if (contentType != null) { return contentType; } } return null; } OrderedContentTypeDetector(final ContentTypeDetector... detectors); @Override FilterEngine.ContentType detect(final WebResourceRequest request);  }
@Test public void testEmptyDetector() { assertNull(new OrderedContentTypeDetector().detect(mockRequest(URI_IMAGE, XML_HEADER))); }
@Test public void testProperDetectingOrder() { final OrderedContentTypeDetector regexFirst = new OrderedContentTypeDetector( new UrlFileExtensionTypeDetector(), new HeadersContentTypeDetector() ); final OrderedContentTypeDetector headersFirst = new OrderedContentTypeDetector( new HeadersContentTypeDetector(), new UrlFileExtensionTypeDetector() ); assertEquals(FilterEngine.ContentType.IMAGE, regexFirst.detect(mockRequest(URI_IMAGE, XML_HEADER))); assertEquals(FilterEngine.ContentType.XMLHTTPREQUEST, headersFirst.detect(mockRequest(URI_IMAGE, XML_HEADER))); assertEquals(FilterEngine.ContentType.SUBDOCUMENT, headersFirst.detect(mockRequest(URI_IMAGE, SUBDOCUMENT_HEADER))); }