|
8 | 8 | import java.net.URISyntaxException; |
9 | 9 | import java.net.URL; |
10 | 10 | import java.net.URLClassLoader; |
| 11 | +import java.nio.file.Path; |
11 | 12 | import java.security.CodeSource; |
12 | 13 | import java.security.ProtectionDomain; |
13 | 14 | import java.security.cert.Certificate; |
14 | 15 | import org.junit.jupiter.api.Test; |
| 16 | +import org.junit.jupiter.api.condition.EnabledOnOs; |
| 17 | +import org.junit.jupiter.api.condition.OS; |
15 | 18 |
|
16 | 19 | class JarScannerTest { |
17 | 20 | @Test |
@@ -50,4 +53,28 @@ public void extractJarPathFromNestedJar() throws URISyntaxException { |
50 | 53 | assertEquals( |
51 | 54 | jarFileUrl.getFile(), JarScanner.extractJarPath(protectionDomain, null).toString()); |
52 | 55 | } |
| 56 | + |
| 57 | + @Test |
| 58 | + @EnabledOnOs(OS.WINDOWS) |
| 59 | + public void extractJarPathFromFileOnWindows() throws URISyntaxException { |
| 60 | + URL mockLocation = mock(URL.class); |
| 61 | + when(mockLocation.toString()).thenReturn("file:/C:/apps/server/classes/"); |
| 62 | + CodeSource codeSource = new CodeSource(mockLocation, (Certificate[]) null); |
| 63 | + ProtectionDomain protectionDomain = new ProtectionDomain(codeSource, null); |
| 64 | + Path result = JarScanner.extractJarPath(protectionDomain, SymDBReport.NO_OP); |
| 65 | + assertNotNull(result); |
| 66 | + assertTrue(result.toString().contains("server")); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + @EnabledOnOs(OS.WINDOWS) |
| 71 | + public void extractJarPathFromJarOnWindows() throws URISyntaxException { |
| 72 | + URL mockLocation = mock(URL.class); |
| 73 | + when(mockLocation.toString()).thenReturn("jar:file:/C:/libs/app.jar!/com/example/"); |
| 74 | + CodeSource codeSource = new CodeSource(mockLocation, (Certificate[]) null); |
| 75 | + ProtectionDomain protectionDomain = new ProtectionDomain(codeSource, null); |
| 76 | + Path result = JarScanner.extractJarPath(protectionDomain, SymDBReport.NO_OP); |
| 77 | + assertNotNull(result); |
| 78 | + assertTrue(result.toString().contains("app.jar")); |
| 79 | + } |
53 | 80 | } |
0 commit comments