File tree Expand file tree Collapse file tree 2 files changed +14
-1
lines changed
main/java/fi/helsinki/cs/tmc/langs/io/zip
test/java/fi/helsinki/cs/tmc/langs/io/zip Expand file tree Collapse file tree 2 files changed +14
-1
lines changed Original file line number Diff line number Diff 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 );
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments