1
1
package com .datadog .debugger .symbol ;
2
2
3
3
import static org .junit .jupiter .api .Assertions .*;
4
+ import static org .mockito .Mockito .mock ;
5
+ import static org .mockito .Mockito .when ;
4
6
5
7
import java .net .MalformedURLException ;
6
8
import java .net .URISyntaxException ;
7
9
import java .net .URL ;
8
10
import java .net .URLClassLoader ;
11
+ import java .security .CodeSource ;
12
+ import java .security .ProtectionDomain ;
13
+ import java .security .cert .Certificate ;
9
14
import org .junit .jupiter .api .Test ;
10
15
11
16
class JarScannerTest {
@@ -31,4 +36,15 @@ public void extractJarPathFromFile() throws ClassNotFoundException, URISyntaxExc
31
36
Class <?> testClass = urlClassLoader .loadClass (CLASS_NAME );
32
37
assertEquals (jarFileUrl .getFile (), JarScanner .extractJarPath (testClass ).toString ());
33
38
}
39
+
40
+ @ Test
41
+ public void extractJarPathFromNestedJar () throws URISyntaxException {
42
+ URL jarFileUrl = getClass ().getResource ("/debugger-symbol.jar" );
43
+ URL mockLocation = mock (URL .class );
44
+ when (mockLocation .toString ())
45
+ .thenReturn ("jar:nested:" + jarFileUrl .getFile () + "/!BOOT-INF/classes/!" );
46
+ CodeSource codeSource = new CodeSource (mockLocation , (Certificate []) null );
47
+ ProtectionDomain protectionDomain = new ProtectionDomain (codeSource , null );
48
+ assertEquals (jarFileUrl .getFile (), JarScanner .extractJarPath (protectionDomain ).toString ());
49
+ }
34
50
}
0 commit comments