Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,19 @@ public class DependencyInsight extends Recipe {
@Nullable
String scope;

@Override
public String getInstanceNameSuffix() {
// Null when rendering the descriptor of an unconfigured recipe; a "null:null" suffix
// would then be shown wherever recipes are listed.
if (groupIdPattern == null || artifactIdPattern == null) {
return "";
}
if (version == null) {
return String.format("`%s:%s`", groupIdPattern, artifactIdPattern);
}
return String.format("`%s:%s:%s`", groupIdPattern, artifactIdPattern, version);
}

@Override
public TreeVisitor<?, ExecutionContext> getVisitor() {
return new TreeVisitor<Tree, ExecutionContext>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

import static org.assertj.core.api.Assertions.assertThat;
import static org.openrewrite.maven.Assertions.pomXml;

class DependencyInsightTest implements RewriteTest {
Expand All @@ -29,6 +30,26 @@ public void defaults(RecipeSpec spec) {
spec.recipe(new DependencyInsight("org.springframework*", "*", null, null));
}

@Test
void instanceNameShowsWhatIsBeingSearchedFor() {
assertThat(new DependencyInsight("com.fasterxml.jackson*", "jackson-*", null, null).getInstanceName())
.isEqualTo("Dependency insight for Gradle and Maven `com.fasterxml.jackson*:jackson-*`");
}

@Test
void instanceNameIncludesVersionWhenGiven() {
assertThat(new DependencyInsight("com.fasterxml.jackson*", "jackson-*", "2.x", null).getInstanceName())
.isEqualTo("Dependency insight for Gradle and Maven `com.fasterxml.jackson*:jackson-*:2.x`");
}

@Test
void instanceNameOmitsTheSuffixWhenUnconfigured() {
// The descriptor of an unconfigured recipe is rendered wherever recipes are listed;
// it must not read "null:null".
assertThat(new DependencyInsight(null, null, null, null).getInstanceName())
.isEqualTo("Dependency insight for Gradle and Maven");
}

@DocumentExample
@Test
void maven() {
Expand Down
Loading