From 734ace918d9e22422261f4a4e1fa22893e3f4b7c Mon Sep 17 00:00:00 2001 From: Nguyen Nam Thai Date: Tue, 6 Mar 2018 17:58:13 +0700 Subject: [PATCH] Refactor the tests --- .../test/java/com/baeldung/tika/TikaUnitTest.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/apache-tika/src/test/java/com/baeldung/tika/TikaUnitTest.java b/apache-tika/src/test/java/com/baeldung/tika/TikaUnitTest.java index 555a796d59..f8c2372d1f 100644 --- a/apache-tika/src/test/java/com/baeldung/tika/TikaUnitTest.java +++ b/apache-tika/src/test/java/com/baeldung/tika/TikaUnitTest.java @@ -13,11 +13,9 @@ import org.junit.Test; import org.xml.sax.SAXException; public class TikaUnitTest { - private ClassLoader loader = this.getClass().getClassLoader(); - @Test 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); assertEquals("application/pdf", mediaType); @@ -27,7 +25,7 @@ public class TikaUnitTest { @Test 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); assertEquals("application/pdf", mediaType); @@ -37,7 +35,7 @@ public class TikaUnitTest { @Test 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); assertThat(content, containsString("Apache Tika - a content analysis toolkit")); @@ -48,7 +46,7 @@ public class TikaUnitTest { @Test 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); assertThat(content, containsString("Apache Tika - a content analysis toolkit")); @@ -59,7 +57,7 @@ public class TikaUnitTest { @Test 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); assertEquals("org.apache.tika.parser.DefaultParser", metadata.get("X-Parsed-By")); @@ -70,7 +68,7 @@ public class TikaUnitTest { @Test 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); assertEquals("org.apache.tika.parser.DefaultParser", metadata.get("X-Parsed-By"));