Skip to content

Commit ba7aaaa

Browse files
[Tests] Small refactor. Supply a list of pdf's to run tests on. Remove frivolous synchronized
1 parent f2228c5 commit ba7aaaa

1 file changed

Lines changed: 29 additions & 25 deletions

File tree

pdf2htmlEX/src/androidTest/java/com/viliussutkus89/android/pdf2htmlex/InstrumentedTests.java

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
@RunWith(AndroidJUnit4.class)
4444
public class InstrumentedTests {
4545

46+
// PDFs must be places in pdf2htmlEX/src/androidTest/assets/
47+
private final String[] m_PDFsToTest = new String[] {
48+
"fontfile3_opentype.pdf",
49+
"fontfile3_opentype.pdf"
50+
};
51+
4652
private File extractAssetPDF(String filename) throws IOException {
4753
Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
4854
Context appContext = instrumentation.getTargetContext();
@@ -78,35 +84,33 @@ private void copyFile(InputStream input, OutputStream output) throws IOException
7884
}
7985

8086
@Test
81-
public synchronized void conversionTest() throws IOException {
82-
pdf2htmlEX converter = new pdf2htmlEX(InstrumentationRegistry.getInstrumentation().getTargetContext());
83-
File pdfFile = extractAssetPDF("fontfile3_opentype.pdf");
84-
File htmlFile;
85-
try {
86-
htmlFile = converter.convert(pdfFile);
87-
} catch (IOException | pdf2htmlEX.ConversionFailedException e) {
88-
pdfFile.delete();
89-
e.printStackTrace();
90-
fail("Failed to convert PDF to HTML");
91-
return;
92-
}
87+
public void testAllSuppliedPDFs() throws IOException {
88+
Context ctx = InstrumentationRegistry.getInstrumentation().getTargetContext();
89+
90+
for (String i: m_PDFsToTest) {
91+
File pdfFile = extractAssetPDF(i);
92+
File htmlFile;
93+
94+
pdf2htmlEX pdf2htmlEX = new pdf2htmlEX(ctx);
95+
try {
96+
htmlFile = pdf2htmlEX.convert(pdfFile);
97+
} catch (IOException | pdf2htmlEX.ConversionFailedException e) {
98+
pdfFile.delete();
99+
e.printStackTrace();
100+
fail("Failed to convert PDF to HTML: " + i);
101+
continue;
102+
}
93103

94-
pdfFile.delete();
95-
assertTrue("Converted HTML file not found!", htmlFile.exists());
96-
assertTrue("Converted HTML file empty!", htmlFile.length() > 0);
97-
98-
htmlFile.delete();
99-
}
104+
pdfFile.delete();
105+
assertTrue("Converted HTML file not found! " + i, htmlFile.exists());
106+
assertTrue("Converted HTML file empty! " + i, htmlFile.length() > 0);
100107

101-
// https://github.com/ViliusSutkus89/pdf2htmlEX-Android/issues/4
102-
@Test
103-
public void conversionTwiceTest() throws IOException {
104-
conversionTest();
105-
conversionTest();
108+
htmlFile.delete();
109+
}
106110
}
107111

108112
@Test
109-
public synchronized void encryptedPdfTest() throws IOException {
113+
public void encryptedPdfTest() throws IOException {
110114
pdf2htmlEX converter = new pdf2htmlEX(InstrumentationRegistry.getInstrumentation().getTargetContext());
111115

112116
// encrypted_fontfile3_opentype.pdf generated using:
@@ -134,7 +138,7 @@ public synchronized void encryptedPdfTest() throws IOException {
134138
}
135139

136140
@Test
137-
public synchronized void encryptedPdfWrongPasswordTest() throws IOException {
141+
public void encryptedPdfWrongPasswordTest() throws IOException {
138142
pdf2htmlEX converter = new pdf2htmlEX(InstrumentationRegistry.getInstrumentation().getTargetContext());
139143

140144
// encrypted_fontfile3_opentype.pdf generated using:

0 commit comments

Comments
 (0)