Skip to content

Commit 734ace9

Browse files
author
Nguyen Nam Thai
committed
Refactor the tests
1 parent bbe6f60 commit 734ace9

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

apache-tika/src/test/java/com/baeldung/tika/TikaUnitTest.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
import org.xml.sax.SAXException;
1414

1515
public class TikaUnitTest {
16-
private ClassLoader loader = this.getClass().getClassLoader();
17-
1816
@Test
1917
public void whenUsingDetector_thenDocumentTypeIsReturned() throws IOException {
20-
InputStream stream = loader.getResourceAsStream("tika.txt");
18+
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.txt");
2119
String mediaType = TikaAnalysis.detectDocTypeUsingDetector(stream);
2220

2321
assertEquals("application/pdf", mediaType);
@@ -27,7 +25,7 @@ public void whenUsingDetector_thenDocumentTypeIsReturned() throws IOException {
2725

2826
@Test
2927
public void whenUsingFacade_thenDocumentTypeIsReturned() throws IOException {
30-
InputStream stream = loader.getResourceAsStream("tika.txt");
28+
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.txt");
3129
String mediaType = TikaAnalysis.detectDocTypeUsingFacade(stream);
3230

3331
assertEquals("application/pdf", mediaType);
@@ -37,7 +35,7 @@ public void whenUsingFacade_thenDocumentTypeIsReturned() throws IOException {
3735

3836
@Test
3937
public void whenUsingParser_thenContentIsReturned() throws IOException, TikaException, SAXException {
40-
InputStream stream = loader.getResourceAsStream("tika.docx");
38+
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.docx");
4139
String content = TikaAnalysis.extractContentUsingParser(stream);
4240

4341
assertThat(content, containsString("Apache Tika - a content analysis toolkit"));
@@ -48,7 +46,7 @@ public void whenUsingParser_thenContentIsReturned() throws IOException, TikaExce
4846

4947
@Test
5048
public void whenUsingFacade_thenContentIsReturned() throws IOException, TikaException {
51-
InputStream stream = loader.getResourceAsStream("tika.docx");
49+
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.docx");
5250
String content = TikaAnalysis.extractContentUsingFacade(stream);
5351

5452
assertThat(content, containsString("Apache Tika - a content analysis toolkit"));
@@ -59,7 +57,7 @@ public void whenUsingFacade_thenContentIsReturned() throws IOException, TikaExce
5957

6058
@Test
6159
public void whenUsingParser_thenMetadataIsReturned() throws IOException, TikaException, SAXException {
62-
InputStream stream = loader.getResourceAsStream("tika.xlsx");
60+
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.xlsx");
6361
Metadata metadata = TikaAnalysis.extractMetadatatUsingParser(stream);
6462

6563
assertEquals("org.apache.tika.parser.DefaultParser", metadata.get("X-Parsed-By"));
@@ -70,7 +68,7 @@ public void whenUsingParser_thenMetadataIsReturned() throws IOException, TikaExc
7068

7169
@Test
7270
public void whenUsingFacade_thenMetadataIsReturned() throws IOException, TikaException {
73-
InputStream stream = loader.getResourceAsStream("tika.xlsx");
71+
InputStream stream = this.getClass().getClassLoader().getResourceAsStream("tika.xlsx");
7472
Metadata metadata = TikaAnalysis.extractMetadatatUsingFacade(stream);
7573

7674
assertEquals("org.apache.tika.parser.DefaultParser", metadata.get("X-Parsed-By"));

0 commit comments

Comments
 (0)