Skip to content

Commit 7998eb0

Browse files
committed
Throw exception if zipping without setting file policy
1 parent fb388ba commit 7998eb0

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

tmc-langs-framework/src/main/java/fi/helsinki/cs/tmc/langs/io/zip/StudentFileAwareZipper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ public byte[] zip(Path rootDirectory) throws IOException {
9797
throw new IllegalArgumentException("Filesystem root zipping is not supported");
9898
}
9999

100+
if (filePolicy == null) {
101+
log.error("Attepted to zip before setting the filePolicy");
102+
throw new IllegalStateException(
103+
"The student file policy must be set before zipping files");
104+
}
105+
100106
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
101107
try (ZipArchiveOutputStream zipStream = new ZipArchiveOutputStream(buffer)) {
102108
zipRecursively(rootDirectory, zipStream, rootDirectory);

tmc-langs-framework/src/test/java/fi/helsinki/cs/tmc/langs/io/zip/StudentFileAwareZipperTest.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ public void zipperThrowsExceptionWhenZippingRoot() throws IOException {
8989
zipper.zip(Paths.get("/").toAbsolutePath());
9090
}
9191

92+
@Test(expected = IllegalStateException.class)
93+
public void zipperThrowsExceptionWhenZippingWithoutSettingPolicy() throws IOException {
94+
Path existingPath = TestUtils.getPath(StudentFileAwareUnzipperTest.class,
95+
"tmcnosubmit_test_case");
96+
new StudentFileAwareZipper().zip(existingPath);
97+
}
98+
9299
@Test
93100
public void zipperCorrectlyZipsSingleFile() throws IOException {
94101

@@ -108,7 +115,7 @@ public void zipperCorrectlyZipsSingleFile() throws IOException {
108115
@Test
109116
public void zipperCorrectlyZipsFolderWithFilesAndSubFolders() throws IOException {
110117
// Create empty dir that is not in git
111-
Path emptyDir = (TEST_DIR.resolve("dir"));
118+
Path emptyDir = TEST_DIR.resolve("dir");
112119
if (Files.notExists(emptyDir)) {
113120
Files.createDirectory(emptyDir);
114121
}

0 commit comments

Comments
 (0)