|
31 | 31 | import org.junit.BeforeClass;
|
32 | 32 | import org.junit.Test;
|
33 | 33 | import org.junit.runner.RunWith;
|
| 34 | +import org.junit.runners.JUnit4; |
34 | 35 | import org.mockito.invocation.InvocationOnMock;
|
35 | 36 | import org.mockito.stubbing.Answer;
|
36 | 37 | import org.powermock.core.classloader.annotations.PowerMockIgnore;
|
37 | 38 | import org.powermock.core.classloader.annotations.PrepareForTest;
|
38 | 39 | import org.powermock.modules.junit4.PowerMockRunner;
|
| 40 | +import org.powermock.modules.junit4.PowerMockRunnerDelegate; |
39 | 41 |
|
40 | 42 | import static java.nio.charset.StandardCharsets.UTF_8;
|
41 | 43 | import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.escapeUri;
|
42 | 44 | import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.relativize;
|
43 | 45 | import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.toAbsoluteUri;
|
44 | 46 | import static org.apache.maven.plugin.surefire.booterclient.JarManifestForkConfiguration.toClasspathElementUri;
|
| 47 | +import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS; |
45 | 48 | import static org.assertj.core.api.Assertions.assertThat;
|
46 | 49 | import static org.assertj.core.util.Files.delete;
|
47 | 50 | import static org.assertj.core.util.Files.newTemporaryFolder;
|
| 51 | +import static org.junit.Assume.assumeTrue; |
48 | 52 | import static org.mockito.ArgumentMatchers.any;
|
49 | 53 | import static org.mockito.ArgumentMatchers.anyBoolean;
|
50 | 54 | import static org.mockito.ArgumentMatchers.anyString;
|
|
57 | 61 | * Unit tests for {@link JarManifestForkConfiguration}.
|
58 | 62 | */
|
59 | 63 | @RunWith(PowerMockRunner.class)
|
| 64 | +@PowerMockRunnerDelegate(JUnit4.class) |
60 | 65 | @PrepareForTest({JarManifestForkConfiguration.class, InPluginProcessDumpSingleton.class})
|
61 | 66 | @PowerMockIgnore({"org.jacoco.agent.rt.*", "com.vladium.emma.rt.*"})
|
62 | 67 | public class JarManifestForkConfigurationTest {
|
@@ -163,6 +168,33 @@ public URI answer(InvocationOnMock invocation) throws URISyntaxException {
|
163 | 168 | .isEqualTo("file:///X:/Users/me/.m2/repository/grp/art/1.0/art-1.0.jar");
|
164 | 169 | }
|
165 | 170 |
|
| 171 | + @Test |
| 172 | + public void uncWindows() throws Exception { |
| 173 | + assumeTrue(IS_OS_WINDOWS); |
| 174 | + mockStatic(JarManifestForkConfiguration.class); |
| 175 | + mockStatic(InPluginProcessDumpSingleton.class); |
| 176 | + when(InPluginProcessDumpSingleton.getSingleton()).thenReturn(mock(InPluginProcessDumpSingleton.class)); |
| 177 | + Path parent = mock(Path.class); |
| 178 | + when(parent.toString()).thenReturn("C:\\Windows\\Temp\\surefire"); |
| 179 | + Path classPathElement = mock(Path.class); |
| 180 | + when(classPathElement.toString()).thenReturn("\\\\server\\grp\\art\\1.0\\art-1.0.jar"); |
| 181 | + when(classPathElement.toFile()).thenAnswer(new Answer<File>() { |
| 182 | + @Override |
| 183 | + public File answer(InvocationOnMock invocation) { |
| 184 | + String path = invocation.getMock().toString(); |
| 185 | + return new File(path); |
| 186 | + } |
| 187 | + }); |
| 188 | + when(relativize(same(parent), same(classPathElement))) |
| 189 | + .thenThrow(new IllegalArgumentException("'other' has different root")); |
| 190 | + when(toClasspathElementUri(same(parent), same(classPathElement), same(dumpDirectory), anyBoolean())) |
| 191 | + .thenCallRealMethod(); |
| 192 | + when(escapeUri(anyString(), any(Charset.class))).thenCallRealMethod(); |
| 193 | + when(toAbsoluteUri(same(classPathElement))).thenCallRealMethod(); |
| 194 | + assertThat(toClasspathElementUri(parent, classPathElement, dumpDirectory, true).uri) |
| 195 | + .isEqualTo("file:////server/grp/art/1.0/art-1.0.jar"); |
| 196 | + } |
| 197 | + |
166 | 198 | @Test
|
167 | 199 | @SuppressWarnings("checkstyle:magicnumber")
|
168 | 200 | public void shouldEscapeUri() throws Exception {
|
|
0 commit comments