Skip to content

Commit 827ab31

Browse files
committed
Better testing of errors.
1 parent 40dd4ea commit 827ab31

1 file changed

Lines changed: 32 additions & 3 deletions

File tree

lib/src/test/test.java

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ private void testArchive(TestArchive archive)
116116

117117
assertFalse(archive.getRandomEntry().getTitle().isEmpty());
118118

119+
// Test different iterators
119120
{
120121
TestEntryIterator iter = archive.iterByPath();
121122
assertTrue(iter.hasNext());
@@ -153,7 +154,20 @@ private void testArchive(TestArchive archive)
153154
assertEquals("main.html", iter.next().getPath());
154155
assertFalse(iter.hasNext());
155156
}
156-
}
157+
158+
// Test invalid path
159+
try {
160+
archive.getEntryByTitle("Wrong title");
161+
} catch(Exception e) {
162+
assertEquals("Cannot find entry", e.getMessage());
163+
}
164+
165+
try {
166+
archive.getEntryByPath("wrong_path.html");
167+
} catch(Exception e) {
168+
assertEquals("Cannot find entry", e.getMessage());
169+
}
170+
}
157171

158172
@Test
159173
public void testArchiveDirect()
@@ -163,9 +177,12 @@ public void testArchiveDirect()
163177
assertTrue(archive.check());
164178
assertEquals("small.zim", archive.getFilename());
165179
archive.dispose();
180+
}
166181

167-
// test reader with invalid zim file
168-
String zimFile = "test.zim";
182+
@Test
183+
public void testNonExistant() {
184+
// test reader with non existant zim file
185+
String zimFile = "non_existant.zim";
169186
try {
170187
TestArchive archive1 = new TestArchive(zimFile);
171188
fail("ERROR: Archive created with invalid Zim file!");
@@ -174,6 +191,18 @@ public void testArchiveDirect()
174191
}
175192
}
176193

194+
@Test
195+
public void testNotValid() {
196+
// test reader with non existant zim file
197+
String zimFile = "test.java";
198+
try {
199+
TestArchive archive1 = new TestArchive(zimFile);
200+
fail("ERROR: Archive created with invalid Zim file!");
201+
} catch (ZimFileFormatException e) {
202+
assertEquals("Invalid magic number", e.getMessage());
203+
}
204+
}
205+
177206
@Test
178207
public void testArchiveByFd()
179208
throws JNIKiwixException, IOException, ZimFileFormatException {

0 commit comments

Comments
 (0)