|
2 | 2 |
|
3 | 3 | import static org.hamcrest.MatcherAssert.assertThat; |
4 | 4 | import static org.hamcrest.core.StringContains.containsString; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
5 | 6 | import static org.junit.jupiter.api.Assertions.assertFalse; |
6 | 7 | import static org.junit.jupiter.api.Assertions.assertThrows; |
7 | 8 | import static org.junit.jupiter.api.Assertions.assertTrue; |
8 | 9 | import static org.junit.jupiter.api.Assertions.fail; |
| 10 | +import static org.mockito.ArgumentMatchers.any; |
9 | 11 | import static org.mockito.Mockito.mock; |
| 12 | +import static org.mockito.Mockito.when; |
10 | 13 |
|
11 | 14 | import japicmp.cmp.ClassesHelper; |
12 | 15 | import japicmp.cmp.JarArchiveComparator; |
|
18 | 21 | import japicmp.maven.util.CtMethodBuilder; |
19 | 22 | import javassist.ClassPool; |
20 | 23 | import javassist.CtClass; |
| 24 | +import org.apache.maven.plugin.MojoExecution; |
21 | 25 | import org.apache.maven.plugin.MojoExecutionException; |
22 | 26 | import org.apache.maven.plugin.MojoFailureException; |
23 | 27 | import org.apache.maven.plugin.logging.Log; |
| 28 | +import org.apache.maven.project.MavenProject; |
| 29 | +import org.eclipse.aether.RepositorySystem; |
| 30 | +import org.eclipse.aether.RepositorySystemSession; |
| 31 | +import org.eclipse.aether.repository.RemoteRepository; |
| 32 | +import org.eclipse.aether.resolution.ArtifactResolutionException; |
24 | 33 | import org.junit.jupiter.api.Assertions; |
25 | 34 | import org.junit.jupiter.api.BeforeEach; |
26 | 35 | import org.junit.jupiter.api.Test; |
27 | 36 |
|
| 37 | +import java.lang.reflect.Method; |
28 | 38 | import java.util.*; |
29 | 39 |
|
30 | 40 | /** |
@@ -466,4 +476,33 @@ public List<CtClass> createNewClasses(ClassPool classPool) { |
466 | 476 | assertThat(msg, containsString("japicmp.Test:SUPERCLASS_REMOVED")); |
467 | 477 | } |
468 | 478 | } |
| 479 | + |
| 480 | + @Test |
| 481 | + void testSetUpClassPathUsingMavenProjectNoNPEWhenProjectArtifactUnresolvable() throws Exception { |
| 482 | + // Reproduce issue #504: when the project artifact cannot be resolved and the ignore flag |
| 483 | + // is set, resolveArtifact() returns null. Before the fix, that null was added to the set |
| 484 | + // and caused an NPE on the next artifact.getFile() call. |
| 485 | + configParams.setIgnoreNonResolvableArtifacts(Boolean.TRUE.toString()); |
| 486 | + |
| 487 | + RepositorySystem repoSystem = mock(RepositorySystem.class); |
| 488 | + when(repoSystem.resolveArtifact(any(), any())) |
| 489 | + .thenThrow(new ArtifactResolutionException(Collections.emptyList())); |
| 490 | + |
| 491 | + RemoteRepository remoteRepo = new RemoteRepository.Builder("default", "releases", |
| 492 | + "https://repo.maven.apache.org/maven2").build(); |
| 493 | + MavenParameters params = new MavenParameters(new ArrayList<>(), new MavenProject(), |
| 494 | + mock(MojoExecution.class), "", repoSystem, |
| 495 | + mock(RepositorySystemSession.class), |
| 496 | + Collections.singletonList(remoteRepo)); |
| 497 | + |
| 498 | + JApiCmpProcessor processor = new JApiCmpProcessor( |
| 499 | + createPluginParameters(configParams), params, logger); |
| 500 | + |
| 501 | + JarArchiveComparatorOptions options = new JarArchiveComparatorOptions(); |
| 502 | + Method method = JApiCmpProcessor.class.getDeclaredMethod( |
| 503 | + "setUpClassPathUsingMavenProject", JarArchiveComparatorOptions.class); |
| 504 | + method.setAccessible(true); |
| 505 | + |
| 506 | + assertDoesNotThrow(() -> method.invoke(processor, options)); |
| 507 | + } |
469 | 508 | } |
0 commit comments