DependencyFilterMojoTests Class — spring-boot Architecture
Architecture documentation for the DependencyFilterMojoTests class in DependencyFilterMojoTests.java from the spring-boot codebase.
Entity Profile
Source Code
build-plugin/spring-boot-maven-plugin/src/test/java/org/springframework/boot/maven/DependencyFilterMojoTests.java lines 49–181
class DependencyFilterMojoTests {
@TempDir
@SuppressWarnings("NullAway.Init")
static Path temp;
@Test
void filterDependencies() throws MojoExecutionException {
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.emptyList(), "com.foo");
Artifact artifact = createArtifact("com.bar", "one");
Set<Artifact> artifacts = mojo.filterDependencies(createArtifact("com.foo", "one"),
createArtifact("com.foo", "two"), artifact);
assertThat(artifacts).hasSize(1);
assertThat(artifacts.iterator().next()).isSameAs(artifact);
}
@Test
void filterGroupIdExactMatch() throws MojoExecutionException {
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.emptyList(), "com.foo");
Artifact artifact = createArtifact("com.foo.bar", "one");
Set<Artifact> artifacts = mojo.filterDependencies(createArtifact("com.foo", "one"),
createArtifact("com.foo", "two"), artifact);
assertThat(artifacts).hasSize(1);
assertThat(artifacts.iterator().next()).isSameAs(artifact);
}
@Test
void filterScopeKeepOrder() throws MojoExecutionException {
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.emptyList(), "",
new ScopeFilter(null, Artifact.SCOPE_SYSTEM));
Artifact one = createArtifact("com.foo", "one");
Artifact two = createArtifact("com.foo", "two", Artifact.SCOPE_SYSTEM);
Artifact three = createArtifact("com.foo", "three", Artifact.SCOPE_RUNTIME);
Set<Artifact> artifacts = mojo.filterDependencies(one, two, three);
assertThat(artifacts).containsExactly(one, three);
}
@Test
void filterGroupIdKeepOrder() throws MojoExecutionException {
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.emptyList(), "com.foo");
Artifact one = createArtifact("com.foo", "one");
Artifact two = createArtifact("com.bar", "two");
Artifact three = createArtifact("com.bar", "three");
Artifact four = createArtifact("com.foo", "four");
Set<Artifact> artifacts = mojo.filterDependencies(one, two, three, four);
assertThat(artifacts).containsExactly(two, three);
}
@Test
void filterExcludeKeepOrder() throws MojoExecutionException {
Exclude exclude = new Exclude();
exclude.setGroupId("com.bar");
exclude.setArtifactId("two");
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.singletonList(exclude), "");
Artifact one = createArtifact("com.foo", "one");
Artifact two = createArtifact("com.bar", "two");
Artifact three = createArtifact("com.bar", "three");
Artifact four = createArtifact("com.foo", "four");
Set<Artifact> artifacts = mojo.filterDependencies(one, two, three, four);
assertThat(artifacts).containsExactly(one, three, four);
}
@Test
void excludeByJarType() throws MojoExecutionException {
TestableDependencyFilterMojo mojo = new TestableDependencyFilterMojo(Collections.emptyList(), "");
Artifact one = createArtifact("com.foo", "one", null, "dependencies-starter");
Artifact two = createArtifact("com.bar", "two");
Set<Artifact> artifacts = mojo.filterDependencies(one, two);
assertThat(artifacts).containsExactly(two);
}
private static Artifact createArtifact(String groupId, String artifactId) {
return createArtifact(groupId, artifactId, null);
}
private static Artifact createArtifact(String groupId, String artifactId, @Nullable String scope) {
return createArtifact(groupId, artifactId, scope, null);
}
private static Artifact createArtifact(String groupId, String artifactId, @Nullable String scope,
@Nullable String jarType) {
Artifact a = mock(Artifact.class);
given(a.getGroupId()).willReturn(groupId);
given(a.getArtifactId()).willReturn(artifactId);
if (scope != null) {
given(a.getScope()).willReturn(scope);
}
given(a.getFile()).willReturn(createArtifactFile(jarType));
return a;
}
private static File createArtifactFile(@Nullable String jarType) {
Path jarPath = temp.resolve(UUID.randomUUID() + ".jar");
Manifest manifest = new Manifest();
manifest.getMainAttributes().putValue("Manifest-Version", "1.0");
if (jarType != null) {
manifest.getMainAttributes().putValue("Spring-Boot-Jar-Type", jarType);
}
try {
new JarOutputStream(new FileOutputStream(jarPath.toFile()), manifest).close();
}
catch (IOException ex) {
throw new RuntimeException(ex);
}
return jarPath.toFile();
}
private static final class TestableDependencyFilterMojo extends AbstractDependencyFilterMojo {
private final ArtifactsFilter[] additionalFilters;
private TestableDependencyFilterMojo(List<Exclude> excludes, String excludeGroupIds,
ArtifactsFilter... additionalFilters) {
setExcludes(excludes);
setExcludeGroupIds(excludeGroupIds);
this.additionalFilters = additionalFilters;
}
Set<Artifact> filterDependencies(Artifact... artifacts) throws MojoExecutionException {
Set<Artifact> input = new LinkedHashSet<>(Arrays.asList(artifacts));
return filterDependencies(input, this.additionalFilters);
}
@Override
public void execute() {
}
}
}
Source
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free