Refactor the tests
This commit is contained in:
parent
bbe6f60916
commit
734ace918d
|
@ -13,11 +13,9 @@ import org.junit.Test;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
public class TikaUnitTest {
|
public class TikaUnitTest {
|
||||||
private ClassLoader loader = this.getClass().getClassLoader();
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingDetector_thenDocumentTypeIsReturned() throws IOException {
|
public void whenUsingDetector_thenDocumentTypeIsReturned() throws IOException {
|
||||||
InputStream stream = loader.getResourceAsStream("tika.txt");
|
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.txt");
|
||||||
String mediaType = TikaAnalysis.detectDocTypeUsingDetector(stream);
|
String mediaType = TikaAnalysis.detectDocTypeUsingDetector(stream);
|
||||||
|
|
||||||
assertEquals("application/pdf", mediaType);
|
assertEquals("application/pdf", mediaType);
|
||||||
|
@ -27,7 +25,7 @@ public class TikaUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingFacade_thenDocumentTypeIsReturned() throws IOException {
|
public void whenUsingFacade_thenDocumentTypeIsReturned() throws IOException {
|
||||||
InputStream stream = loader.getResourceAsStream("tika.txt");
|
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.txt");
|
||||||
String mediaType = TikaAnalysis.detectDocTypeUsingFacade(stream);
|
String mediaType = TikaAnalysis.detectDocTypeUsingFacade(stream);
|
||||||
|
|
||||||
assertEquals("application/pdf", mediaType);
|
assertEquals("application/pdf", mediaType);
|
||||||
|
@ -37,7 +35,7 @@ public class TikaUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingParser_thenContentIsReturned() throws IOException, TikaException, SAXException {
|
public void whenUsingParser_thenContentIsReturned() throws IOException, TikaException, SAXException {
|
||||||
InputStream stream = loader.getResourceAsStream("tika.docx");
|
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.docx");
|
||||||
String content = TikaAnalysis.extractContentUsingParser(stream);
|
String content = TikaAnalysis.extractContentUsingParser(stream);
|
||||||
|
|
||||||
assertThat(content, containsString("Apache Tika - a content analysis toolkit"));
|
assertThat(content, containsString("Apache Tika - a content analysis toolkit"));
|
||||||
|
@ -48,7 +46,7 @@ public class TikaUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingFacade_thenContentIsReturned() throws IOException, TikaException {
|
public void whenUsingFacade_thenContentIsReturned() throws IOException, TikaException {
|
||||||
InputStream stream = loader.getResourceAsStream("tika.docx");
|
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.docx");
|
||||||
String content = TikaAnalysis.extractContentUsingFacade(stream);
|
String content = TikaAnalysis.extractContentUsingFacade(stream);
|
||||||
|
|
||||||
assertThat(content, containsString("Apache Tika - a content analysis toolkit"));
|
assertThat(content, containsString("Apache Tika - a content analysis toolkit"));
|
||||||
|
@ -59,7 +57,7 @@ public class TikaUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingParser_thenMetadataIsReturned() throws IOException, TikaException, SAXException {
|
public void whenUsingParser_thenMetadataIsReturned() throws IOException, TikaException, SAXException {
|
||||||
InputStream stream = loader.getResourceAsStream("tika.xlsx");
|
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.xlsx");
|
||||||
Metadata metadata = TikaAnalysis.extractMetadatatUsingParser(stream);
|
Metadata metadata = TikaAnalysis.extractMetadatatUsingParser(stream);
|
||||||
|
|
||||||
assertEquals("org.apache.tika.parser.DefaultParser", metadata.get("X-Parsed-By"));
|
assertEquals("org.apache.tika.parser.DefaultParser", metadata.get("X-Parsed-By"));
|
||||||
|
@ -70,7 +68,7 @@ public class TikaUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenUsingFacade_thenMetadataIsReturned() throws IOException, TikaException {
|
public void whenUsingFacade_thenMetadataIsReturned() throws IOException, TikaException {
|
||||||
InputStream stream = loader.getResourceAsStream("tika.xlsx");
|
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.xlsx");
|
||||||
Metadata metadata = TikaAnalysis.extractMetadatatUsingFacade(stream);
|
Metadata metadata = TikaAnalysis.extractMetadatatUsingFacade(stream);
|
||||||
|
|
||||||
assertEquals("org.apache.tika.parser.DefaultParser", metadata.get("X-Parsed-By"));
|
assertEquals("org.apache.tika.parser.DefaultParser", metadata.get("X-Parsed-By"));
|
||||||
|
|
Loading…
Reference in New Issue