13
13
import org .xml .sax .SAXException ;
14
14
15
15
public class TikaUnitTest {
16
- private ClassLoader loader = this .getClass ().getClassLoader ();
17
-
18
16
@ Test
19
17
public void whenUsingDetector_thenDocumentTypeIsReturned () throws IOException {
20
- InputStream stream = loader .getResourceAsStream ("tika.txt" );
18
+ InputStream stream = this . getClass (). getClassLoader () .getResourceAsStream ("tika.txt" );
21
19
String mediaType = TikaAnalysis .detectDocTypeUsingDetector (stream );
22
20
23
21
assertEquals ("application/pdf" , mediaType );
@@ -27,7 +25,7 @@ public void whenUsingDetector_thenDocumentTypeIsReturned() throws IOException {
27
25
28
26
@ Test
29
27
public void whenUsingFacade_thenDocumentTypeIsReturned () throws IOException {
30
- InputStream stream = loader .getResourceAsStream ("tika.txt" );
28
+ InputStream stream = this . getClass (). getClassLoader () .getResourceAsStream ("tika.txt" );
31
29
String mediaType = TikaAnalysis .detectDocTypeUsingFacade (stream );
32
30
33
31
assertEquals ("application/pdf" , mediaType );
@@ -37,7 +35,7 @@ public void whenUsingFacade_thenDocumentTypeIsReturned() throws IOException {
37
35
38
36
@ Test
39
37
public void whenUsingParser_thenContentIsReturned () throws IOException , TikaException , SAXException {
40
- InputStream stream = loader .getResourceAsStream ("tika.docx" );
38
+ InputStream stream = this . getClass (). getClassLoader () .getResourceAsStream ("tika.docx" );
41
39
String content = TikaAnalysis .extractContentUsingParser (stream );
42
40
43
41
assertThat (content , containsString ("Apache Tika - a content analysis toolkit" ));
@@ -48,7 +46,7 @@ public void whenUsingParser_thenContentIsReturned() throws IOException, TikaExce
48
46
49
47
@ Test
50
48
public void whenUsingFacade_thenContentIsReturned () throws IOException , TikaException {
51
- InputStream stream = loader .getResourceAsStream ("tika.docx" );
49
+ InputStream stream = this . getClass (). getClassLoader () .getResourceAsStream ("tika.docx" );
52
50
String content = TikaAnalysis .extractContentUsingFacade (stream );
53
51
54
52
assertThat (content , containsString ("Apache Tika - a content analysis toolkit" ));
@@ -59,7 +57,7 @@ public void whenUsingFacade_thenContentIsReturned() throws IOException, TikaExce
59
57
60
58
@ Test
61
59
public void whenUsingParser_thenMetadataIsReturned () throws IOException , TikaException , SAXException {
62
- InputStream stream = loader .getResourceAsStream ("tika.xlsx" );
60
+ InputStream stream = this . getClass (). getClassLoader () .getResourceAsStream ("tika.xlsx" );
63
61
Metadata metadata = TikaAnalysis .extractMetadatatUsingParser (stream );
64
62
65
63
assertEquals ("org.apache.tika.parser.DefaultParser" , metadata .get ("X-Parsed-By" ));
@@ -70,7 +68,7 @@ public void whenUsingParser_thenMetadataIsReturned() throws IOException, TikaExc
70
68
71
69
@ Test
72
70
public void whenUsingFacade_thenMetadataIsReturned () throws IOException , TikaException {
73
- InputStream stream = loader .getResourceAsStream ("tika.xlsx" );
71
+ InputStream stream = this . getClass (). getClassLoader () .getResourceAsStream ("tika.xlsx" );
74
72
Metadata metadata = TikaAnalysis .extractMetadatatUsingFacade (stream );
75
73
76
74
assertEquals ("org.apache.tika.parser.DefaultParser" , metadata .get ("X-Parsed-By" ));
0 commit comments