-
Notifications
You must be signed in to change notification settings - Fork 15
/
GitPropertiesLocatorUtilsTest.java
52 lines (44 loc) · 1.67 KB
/
GitPropertiesLocatorUtilsTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.teamscale.jacoco.agent.commit_resolution.git_properties;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.File;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
import static org.assertj.core.api.Assertions.assertThat;
class GitPropertiesLocatorUtilsTest {
/**
* Registers a protocol handler so the test can construct "nested:" URLs that are not supported by plain Java
* but Spring boot.
*/
@BeforeAll
public static void registerCatchAllUrlProtocol() {
URL.setURLStreamHandlerFactory(protocol -> {
if (!"nested".equals(protocol)) {
return null;
}
return new URLStreamHandler() {
/** Returns null, since opening the connection is never done in the test.: */
protected URLConnection openConnection(URL url) {
return null;
}
};
});
}
@Test
public void parseSpringBootCodeLocations() throws Exception {
assertThat(GitPropertiesLocatorUtils
.extractGitPropertiesSearchRoot(new URL("jar:file:/home/k/demo.jar!/BOOT-INF/classes!/")).getFirst())
.isEqualTo(new File("/home/k/demo.jar"));
URL springBoot3Url = new URL(
"jar:nested:/home/k/proj/spring-boot/demo/build/libs/demo-0.0.1-SNAPSHOT.jar/!BOOT-INF/classes/!/.");
assertThat(GitPropertiesLocatorUtils.extractGitPropertiesSearchRoot(springBoot3Url).getFirst())
.isEqualTo(new File("/home/k/proj/spring-boot/demo/build/libs/demo-0.0.1-SNAPSHOT.jar"));
}
@Test
public void parseFileCodeLocations() throws Exception {
assertThat(GitPropertiesLocatorUtils
.extractGitPropertiesSearchRoot(new URL("file:/home/k/demo.jar")).getFirst())
.isEqualTo(new File("/home/k/demo.jar"));
}
}