Skip to content

Commit

Permalink
refactor: OpenRewrite best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek and TeamModerne committed Dec 3, 2024
1 parent 92e9ac5 commit 3045858
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import org.openrewrite.java.internal.JavaTypeCache;
import org.openrewrite.java.internal.AdaptiveRadixJavaTypeCache;
import org.openrewrite.java.internal.JavaTypeCache;

import java.net.URISyntaxException;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.openrewrite.java.Assertions.java;
import static org.openrewrite.java.tree.TypeUtils.TypePosition.*;
import static org.openrewrite.java.tree.TypeUtils.TypePosition.Invariant;
import static org.openrewrite.java.tree.TypeUtils.TypePosition.Out;
import static org.openrewrite.test.RewriteTest.toRecipe;

@SuppressWarnings("ConstantConditions")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.intellij.lang.annotations.Language;
import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.Issue;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
Expand All @@ -42,6 +43,7 @@ public void defaults(RecipeSpec spec) {
spec.parser(JavaParser.fromJavaVersion().dependsOn(b));
}

@DocumentExample
@Test
void deleteMiddleArgumentDeclarative() {
rewriteRun(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import org.openrewrite.java.table.TypeUses;
import org.openrewrite.java.tree.*;
import org.openrewrite.marker.SearchResult;
import org.openrewrite.trait.Trait;
import org.openrewrite.trait.Reference;
import org.openrewrite.trait.Trait;

import java.util.HashSet;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ public FindFilteredResourcePathsVisitor(Accumulator acc) {
public Xml.Tag visitTag(Xml.Tag tag, ExecutionContext ctx) {
if (resourceMatcher.matches(getCursor())) {
String directory = tag.getChildValue("directory").orElse(null);
if (tag.getChildValue("filtering").map(Boolean::valueOf).orElse(false)
&& directory != null) {
if (tag.getChildValue("filtering").map(Boolean::valueOf).orElse(false) &&
directory != null) {
Path path = getCursor().firstEnclosingOrThrow(SourceFile.class).getSourcePath();
try {
acc.filteredResourcePathsToDeclaringPoms.put(path.getParent().resolve(directory), getResolutionResult());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import org.openrewrite.Issue;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;
import org.openrewrite.test.TypeValidation;

import static org.openrewrite.maven.Assertions.pomXml;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.openrewrite.DocumentExample;
import org.openrewrite.test.RecipeSpec;
import org.openrewrite.test.RewriteTest;

Expand All @@ -33,6 +34,7 @@ public void defaults(final RecipeSpec spec) {
spec.recipe(new RemoveUnusedProperties(null));
}

@DocumentExample
@Test
void removesWholePropertiesSection() {
rewriteRun(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,9 @@

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.openrewrite.maven.utilities.MavenWrapper.ASF_LICENSE_HEADER;
import static org.openrewrite.maven.utilities.MavenWrapper.WRAPPER_BATCH_LOCATION;
import static org.openrewrite.maven.utilities.MavenWrapper.WRAPPER_DOWNLOADER_LOCATION;
import static org.openrewrite.maven.utilities.MavenWrapper.WRAPPER_JAR_LOCATION;
import static org.openrewrite.maven.utilities.MavenWrapper.WRAPPER_SCRIPT_LOCATION;
import static org.openrewrite.maven.utilities.MavenWrapper.*;
import static org.openrewrite.properties.Assertions.properties;
import static org.openrewrite.test.SourceSpecs.dir;
import static org.openrewrite.test.SourceSpecs.other;
import static org.openrewrite.test.SourceSpecs.text;
import static org.openrewrite.test.SourceSpecs.*;

class UpdateMavenWrapperTest implements RewriteTest {
private final UnaryOperator<@Nullable String> notEmpty = actual -> {
Expand Down

1 comment on commit 3045858

@niki256-po
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is really good

Please sign in to comment.