Skip to content

Commit 3c115ba

Browse files
authored
feat: Adds test to create zip using reflection (#17)
* feat: Adds test to create zip using reflection * feat: Update test data for zip to dummy files
1 parent 37be0c0 commit 3c115ba

8 files changed

Lines changed: 56 additions & 0 deletions

File tree

‎src/test/java/se/lfv/reqstool/plugins/maven/RequirementsToolMojoTests.java‎

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
package se.lfv.reqstool.plugins.maven;
33

44
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
57
import java.io.File;
68
import java.io.IOException;
9+
import java.lang.reflect.Field;
10+
import java.lang.reflect.Method;
11+
import java.net.URL;
712
import java.nio.file.Files;
13+
import java.nio.file.Paths;
14+
import java.nio.file.Path;
15+
816
import org.junit.jupiter.api.Test;
917
import com.fasterxml.jackson.databind.JsonNode;
1018

@@ -38,4 +46,45 @@ void testCombine() throws IOException {
3846
assertEquals(combinedFileContentAsString, combinedResult, "The combined annotations files should match");
3947
}
4048

49+
@Test
50+
void testCreateZip() throws Exception {
51+
52+
ClassLoader classLoader = getClass().getClassLoader();
53+
URL resourcePath = classLoader.getResource("zip");
54+
Path zipResourcePath = Paths.get(resourcePath.getFile());
55+
File file = zipResourcePath.toFile();
56+
String zipFileNameString = "reqstool-test-zip";
57+
58+
RequirementsToolMojo mojo = new RequirementsToolMojo();
59+
60+
Field outputDirectory = RequirementsToolMojo.class.getDeclaredField("outputDirectory");
61+
Field datasetPath = RequirementsToolMojo.class.getDeclaredField("datasetPath");
62+
Field zipFileName = RequirementsToolMojo.class.getDeclaredField("zipFilename");
63+
Field failsafeReportsDir = RequirementsToolMojo.class.getDeclaredField("failsafeReportsDir");
64+
Field surefireReportsDir = RequirementsToolMojo.class.getDeclaredField("surefireReportsDir");
65+
66+
outputDirectory.setAccessible(true);
67+
datasetPath.setAccessible(true);
68+
zipFileName.setAccessible(true);
69+
failsafeReportsDir.setAccessible(true);
70+
surefireReportsDir.setAccessible(true);
71+
72+
outputDirectory.set(mojo, file);
73+
datasetPath.set(mojo, file);
74+
zipFileName.set(mojo, zipFileNameString);
75+
failsafeReportsDir.set(mojo, file);
76+
surefireReportsDir.set(mojo, file);
77+
78+
Method zipMethod = RequirementsToolMojo.class.getDeclaredMethod("createZipFile");
79+
zipMethod.setAccessible(true);
80+
81+
zipMethod.invoke(mojo);
82+
83+
Path zipfileTargetPath = Paths.get("target", "test-classes", "zip");
84+
Path expectedZipFilePath = zipfileTargetPath.resolve(zipFileNameString);
85+
86+
assertTrue(Files.exists(expectedZipFilePath));
87+
88+
}
89+
4190
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dummy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dummy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dummy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dummy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dummy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dummy
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
dummy

0 commit comments

Comments
 (0)