|
2 | 2 | package se.lfv.reqstool.plugins.maven; |
3 | 3 |
|
4 | 4 | import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
| 6 | + |
5 | 7 | import java.io.File; |
6 | 8 | import java.io.IOException; |
| 9 | +import java.lang.reflect.Field; |
| 10 | +import java.lang.reflect.Method; |
| 11 | +import java.net.URL; |
7 | 12 | import java.nio.file.Files; |
| 13 | +import java.nio.file.Paths; |
| 14 | +import java.nio.file.Path; |
| 15 | + |
8 | 16 | import org.junit.jupiter.api.Test; |
9 | 17 | import com.fasterxml.jackson.databind.JsonNode; |
10 | 18 |
|
@@ -38,4 +46,45 @@ void testCombine() throws IOException { |
38 | 46 | assertEquals(combinedFileContentAsString, combinedResult, "The combined annotations files should match"); |
39 | 47 | } |
40 | 48 |
|
| 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 | + |
41 | 90 | } |
0 commit comments