Skip to content

Commit

Permalink
#313 Add and adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srikanth-lingala committed May 24, 2021
1 parent a84daeb commit da55c58
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
14 changes: 14 additions & 0 deletions src/test/java/net/lingala/zip4j/AddFilesToZipIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public void testAddFileProgressMonitorThrowsExceptionWhenPerformingActionInBusyS
expectedException.expect(ZipException.class);

ZipFile zipFile = new ZipFile(generatedZipFile);
zipFile.setRunInThread(true);
ProgressMonitor progressMonitor = zipFile.getProgressMonitor();
progressMonitor.setState(ProgressMonitor.State.BUSY);

Expand Down Expand Up @@ -610,6 +611,19 @@ public void testAddFolderWithProgressMonitor() throws IOException, InterruptedEx
ZipFileVerifier.verifyZipFileByExtractingAllFiles(generatedZipFile, PASSWORD, outputFolder, 13);
}

@Test
public void testAddFolderProgressMonitorThrowsExceptionWhenPerformingActionInBusyState() throws ZipException {
expectedException.expectMessage("invalid operation - Zip4j is in busy state");
expectedException.expect(ZipException.class);

ZipFile zipFile = new ZipFile(generatedZipFile);
zipFile.setRunInThread(true);
ProgressMonitor progressMonitor = zipFile.getProgressMonitor();
progressMonitor.setState(ProgressMonitor.State.BUSY);

zipFile.addFile(TestUtils.getTestFileFromResources(""));
}

@Test
public void testAddFolderWithNotNormalizedPath() throws IOException {
ZipFile zipFile = new ZipFile(generatedZipFile);
Expand Down
26 changes: 25 additions & 1 deletion src/test/java/net/lingala/zip4j/ZipFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ public void testAddFileAsFileThrowsExceptionWhenParametersIsNull() throws ZipExc
@Test
public void testAddFileAsFileThrowsExceptionWhenProgressMonitorStateIsBusy() throws ZipException {
File fileToAdd = mockFile(true);
zipFile.setRunInThread(true);
zipFile.getProgressMonitor().setState(ProgressMonitor.State.BUSY);

expectedException.expect(ZipException.class);
Expand Down Expand Up @@ -182,6 +183,7 @@ public void testAddFilesThrowsExceptionWhenInputFilesIsEmpty() throws ZipExcepti
@Test
public void testAddFilesThrowsExceptionWhenProgressMonitorStateIsBusy() throws ZipException {
zipFile.getProgressMonitor().setState(ProgressMonitor.State.BUSY);
zipFile.setRunInThread(true);

expectedException.expect(ZipException.class);
expectedException.expectMessage("invalid operation - Zip4j is in busy state");
Expand Down Expand Up @@ -216,6 +218,7 @@ public void testAddFilesWithParametersThrowsExceptionWhenParametersAreNull() thr

@Test
public void testAddFilesWithParametersThrowsExceptionWhenProgressMonitorStateIsBusy() throws ZipException {
zipFile.setRunInThread(true);
zipFile.getProgressMonitor().setState(ProgressMonitor.State.BUSY);

expectedException.expect(ZipException.class);
Expand Down Expand Up @@ -318,6 +321,18 @@ public void testAddFolderWithParametersThrowsExceptionWhenInputParametersAreNull
zipFile.addFolder(folderToAdd, null);
}

@Test
public void testAddFolderThrowsExceptionWhenProgressMonitorStateIsBusy() throws ZipException {
File folderToAdd = mockFolder();
zipFile.setRunInThread(true);
zipFile.getProgressMonitor().setState(ProgressMonitor.State.BUSY);

expectedException.expect(ZipException.class);
expectedException.expectMessage("invalid operation - Zip4j is in busy state");

zipFile.addFolder(folderToAdd, new ZipParameters());
}

@Test
public void testAddStreamThrowsExceptionWhenInputStreamIsNull() throws ZipException {
expectedException.expectMessage("inputstream is null, cannot add file to zip");
Expand Down Expand Up @@ -376,6 +391,7 @@ public void testExtractFileWithFileHeaderWhenDestinationIsEmptyThrowsException()

@Test
public void testExtractFileWithFileHeaderWhenBusyStateThrowsException() throws ZipException {
zipFile.setRunInThread(true);
zipFile.getProgressMonitor().setState(ProgressMonitor.State.BUSY);

expectedException.expectMessage("invalid operation - Zip4j is in busy state");
Expand Down Expand Up @@ -625,4 +641,12 @@ private File mockFile(boolean fileExists) {
return file;
}

}
private File mockFolder() {
File folder = mock(File.class);
when(folder.exists()).thenReturn(true);
when(folder.toString()).thenReturn("SOME_PATH");
when(folder.isDirectory()).thenReturn(true);
when(folder.canRead()).thenReturn(true);
return folder;
}
}

0 comments on commit da55c58

Please sign in to comment.