MimeTypeDetectors { public static MimeTypeDetector createDetectorFor(String mimeTypeDetectionConfig, Environment environment) { switch (mimeTypeDetectionConfig.toLowerCase()) { case RepositoryConfiguration.FieldValue.MIMETYPE_DETECTION_CONTENT: { return TIKA_AVAILABLE ? new TikaContentDetector(environment) : new DefaultMimeTypeDetector(); } case RepositoryConfiguration.FieldValue.MIMETYPE_DETECTION_NAME: { return TIKA_AVAILABLE ? new TikaNameOnlyDetector(environment) : new DefaultMimeTypeDetector(); } case RepositoryConfiguration.FieldValue.MIMETYPE_DETECTION_NONE: { return NullMimeTypeDetector.INSTANCE; } default: { throw new IllegalArgumentException("Unknown mime-type detector setting: " + mimeTypeDetectionConfig); } } } private  MimeTypeDetectors(); static MimeTypeDetector createDetectorFor(String mimeTypeDetectionConfig, Environment environment);  }
@Test public void shouldReturnValidContentDetector() { assertNotNull(MimeTypeDetectors.createDetectorFor(RepositoryConfiguration.FieldValue.MIMETYPE_DETECTION_CONTENT, environment)); }
@Test public void shouldReturnValidNameDetector() { assertNotNull(MimeTypeDetectors.createDetectorFor(RepositoryConfiguration.FieldValue.MIMETYPE_DETECTION_NAME, environment)); }
@Test public void shouldReturnValidEmptyDetector() { MimeTypeDetector detector = MimeTypeDetectors.createDetectorFor( RepositoryConfiguration.FieldValue.MIMETYPE_DETECTION_NONE, environment); assertEquals(NullMimeTypeDetector.INSTANCE, detector); }
@Test( expected = IllegalArgumentException.class ) public void shouldFailForInvalidConfigurationValue() { MimeTypeDetectors.createDetectorFor("test", environment); }