|
19 | 19 | * under the License.
|
20 | 20 | */
|
21 | 21 |
|
22 |
| -import static org.hamcrest.MatcherAssert.assertThat; |
23 |
| -import static org.hamcrest.Matchers.is; |
24 |
| -import static org.junit.Assert.assertEquals; |
25 |
| -import static org.junit.Assert.assertNotNull; |
26 |
| -import static org.junit.Assert.assertSame; |
27 |
| -import static org.mockito.ArgumentMatchers.any; |
28 |
| -import static org.mockito.ArgumentMatchers.eq; |
29 |
| -import static org.mockito.ArgumentMatchers.isNull; |
30 |
| -import static org.mockito.Mockito.atLeastOnce; |
31 |
| -import static org.mockito.Mockito.mock; |
32 |
| -import static org.mockito.Mockito.times; |
33 |
| -import static org.mockito.Mockito.verify; |
34 |
| -import static org.mockito.Mockito.when; |
35 |
| - |
36 |
| -import java.io.File; |
37 |
| -import java.io.IOException; |
38 |
| -import java.nio.charset.Charset; |
39 |
| -import java.util.Arrays; |
40 |
| -import java.util.Collections; |
41 |
| -import java.util.HashSet; |
42 |
| -import java.util.Properties; |
43 |
| -import java.util.Set; |
44 |
| - |
| 22 | +import com.google.common.collect.ImmutableSet; |
45 | 23 | import org.apache.maven.artifact.Artifact;
|
46 | 24 | import org.apache.maven.artifact.handler.ArtifactHandler;
|
47 | 25 | import org.apache.maven.execution.MavenSession;
|
|
71 | 49 | import org.mockito.ArgumentCaptor;
|
72 | 50 | import org.mockito.junit.MockitoJUnitRunner;
|
73 | 51 |
|
| 52 | +import java.io.File; |
| 53 | +import java.io.IOException; |
| 54 | +import java.nio.charset.Charset; |
| 55 | +import java.util.Arrays; |
| 56 | +import java.util.Collections; |
| 57 | +import java.util.HashSet; |
| 58 | +import java.util.Properties; |
| 59 | +import java.util.Set; |
| 60 | + |
| 61 | +import static org.hamcrest.MatcherAssert.assertThat; |
| 62 | +import static org.hamcrest.Matchers.is; |
| 63 | +import static org.junit.Assert.assertEquals; |
| 64 | +import static org.junit.Assert.assertNotNull; |
| 65 | +import static org.junit.Assert.assertSame; |
| 66 | +import static org.mockito.ArgumentMatchers.any; |
| 67 | +import static org.mockito.ArgumentMatchers.eq; |
| 68 | +import static org.mockito.ArgumentMatchers.isNull; |
| 69 | +import static org.mockito.Mockito.atLeastOnce; |
| 70 | +import static org.mockito.Mockito.mock; |
| 71 | +import static org.mockito.Mockito.times; |
| 72 | +import static org.mockito.Mockito.verify; |
| 73 | +import static org.mockito.Mockito.when; |
| 74 | + |
74 | 75 | @RunWith( MockitoJUnitRunner.class )
|
75 | 76 | public class AddDependencySetsTaskTest
|
76 | 77 | {
|
@@ -425,6 +426,60 @@ public void testGetDependencyArtifacts_ShouldFilterOneDependencyArtifactViaInclu
|
425 | 426 | assertSame( am1, result.iterator().next() );
|
426 | 427 | }
|
427 | 428 |
|
| 429 | + @Test |
| 430 | + public void testGetDependencyArtifacts_ShouldFilterOptionalArtifactsByDefault() throws Exception |
| 431 | + { |
| 432 | + Artifact am1 = mockArtifact(1); |
| 433 | + when(am1.isOptional()).thenReturn(true); |
| 434 | + Artifact am2 = mockArtifact(2); |
| 435 | + Set<Artifact> resolvedArtifacts = resolveDependencyArtifacts(new DependencySet(), ImmutableSet.of(am1, am2)); |
| 436 | + assertEquals(1, resolvedArtifacts.size()); |
| 437 | + assertSame(am2, resolvedArtifacts.iterator().next()); |
| 438 | + } |
| 439 | + |
| 440 | + @Test |
| 441 | + public void testGetDependencyArtifacts_ShouldFilterOptionalArtifactsExplicitly() throws Exception |
| 442 | + { |
| 443 | + Artifact am1 = mockArtifact(1); |
| 444 | + when(am1.isOptional()).thenReturn(true); |
| 445 | + Artifact am2 = mockArtifact(2); |
| 446 | + DependencySet dependencySet = new DependencySet(); |
| 447 | + dependencySet.setUseOptionalDependencies(false); |
| 448 | + |
| 449 | + Set<Artifact> resolvedArtifacts = resolveDependencyArtifacts(dependencySet, ImmutableSet.of(am1, am2)); |
| 450 | + assertEquals(1, resolvedArtifacts.size()); |
| 451 | + assertSame(am2, resolvedArtifacts.iterator().next()); |
| 452 | + } |
| 453 | + |
| 454 | + @Test |
| 455 | + public void testGetDependencyArtifacts_ShouldNotFilterOptionalArtifactsExplicitly() throws Exception |
| 456 | + { |
| 457 | + Artifact am1 = mockArtifact(1); |
| 458 | + when(am1.isOptional()).thenReturn(true); |
| 459 | + Artifact am2 = mockArtifact(2); |
| 460 | + DependencySet dependencySet = new DependencySet(); |
| 461 | + dependencySet.setUseOptionalDependencies(true); |
| 462 | + |
| 463 | + Set<Artifact> resolvedArtifacts = resolveDependencyArtifacts(dependencySet, ImmutableSet.of(am1, am2)); |
| 464 | + assertEquals(2, resolvedArtifacts.size()); |
| 465 | + } |
| 466 | + |
| 467 | + private static Artifact mockArtifact( int id ) |
| 468 | + { |
| 469 | + Artifact a = mock(Artifact.class); |
| 470 | + when(a.getId()).thenReturn("group:artifact" + id + ":1.0:jar"); |
| 471 | + return a; |
| 472 | + } |
| 473 | + |
| 474 | + private Set<Artifact> resolveDependencyArtifacts( DependencySet dependencySet, Set<Artifact> artifacts ) throws Exception |
| 475 | + { |
| 476 | + MavenProject project = new MavenProject(new Model()); |
| 477 | + Logger logger = new ConsoleLogger(Logger.LEVEL_DEBUG, "test"); |
| 478 | + AddDependencySetsTask task = |
| 479 | + new AddDependencySetsTask(Collections.singletonList(dependencySet), artifacts, project, null, logger); |
| 480 | + return task.resolveDependencyArtifacts(dependencySet); |
| 481 | + } |
| 482 | + |
428 | 483 | @Test
|
429 | 484 | public void testGetDependencyArtifacts_ShouldIgnoreTransitivePathFilteringWhenIncludeNotTransitive()
|
430 | 485 | throws Exception
|
|
0 commit comments