Skip to content

Commit

Permalink
Provide the correct classpath for each test
Browse files Browse the repository at this point in the history
  • Loading branch information
timtebeek committed Nov 1, 2024
1 parent 758df33 commit 135e760
Showing 1 changed file with 25 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MigrateAuditorAwareToOptionalTest implements RewriteTest {
@Override
public void defaults(RecipeSpec spec) {
spec
.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "spring-data-commons-1.13", "spring-data-commons-2.7"))
.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "spring-data-commons-1.13"))
.recipe(new MigrateAuditorAwareToOptional());
}

Expand Down Expand Up @@ -230,6 +230,7 @@ public Optional<String> getCurrentAuditor() {
@Test
void dontRewriteLambdaLiteral() {
rewriteRun(
spec -> spec.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "spring-data-commons-2")),
//language=java
java(
"""
Expand All @@ -250,6 +251,7 @@ public AuditorAware<String> auditorAware() {
@Test
void dontRewriteLambdaBlock() {
rewriteRun(
spec -> spec.parser(JavaParser.fromJavaVersion().classpathFromResources(new InMemoryExecutionContext(), "spring-data-commons-2")),
//language=java
java(
"""
Expand Down Expand Up @@ -304,11 +306,11 @@ void complexerObjects() {
import org.springframework.data.domain.AuditorAware;
public class Configuration {
public AuditorAware<User> auditorAware() {
return this::determineUser;
}
public User determineUser() {
return new User("admin");
}
Expand All @@ -323,22 +325,22 @@ public User(String name) {
}
""", """
import org.springframework.data.domain.AuditorAware;
import java.util.Optional;
public class Configuration {
public AuditorAware<User> auditorAware() {
return () -> Optional.ofNullable(this.determineUser());
}
public User determineUser() {
return new User("admin");
}
public static class User {
private final String name;
public User(String name) {
this.name = name;
}
Expand All @@ -356,15 +358,15 @@ void dontRewriteOptionalObjectMethodReference() {
java(
"""
import org.springframework.data.domain.AuditorAware;
import java.util.Optional;
public class Configuration {
public AuditorAware<User> auditorAware() {
return this::determineUser;
}
public Optional<User> determineUser() {
return Optional.of(new User("admin"));
}
Expand Down Expand Up @@ -415,14 +417,14 @@ void complexerObjectsCalls() {
import org.springframework.data.domain.AuditorAware;
public class Configuration {
public AuditorAware<String> auditorAware() {
return () -> {
User u = this.determineUser();
return u.getName();
};
}
public User determineUser() {
return new User("admin");
}
Expand All @@ -433,26 +435,26 @@ public static class User {
public User(String name) {
this.name = name;
}
public String getName() {
return name;
}
}
}
""", """
import org.springframework.data.domain.AuditorAware;
import java.util.Optional;
public class Configuration {
public AuditorAware<String> auditorAware() {
return () -> {
User u = this.determineUser();
return Optional.ofNullable(u.getName());
};
}
public User determineUser() {
return new User("admin");
}
Expand All @@ -463,7 +465,7 @@ public static class User {
public User(String name) {
this.name = name;
}
public String getName() {
return name;
}
Expand All @@ -481,18 +483,18 @@ void dontRewriteOptionalObjectMethodInvocations() {
java(
"""
import org.springframework.data.domain.AuditorAware;
import java.util.Optional;
public class Configuration {
public AuditorAware<String> auditorAware() {
return () -> {
User u = this.determineUser();
return u.getName();
};
}
public User determineUser() {
return new User("admin");
}
Expand All @@ -503,7 +505,7 @@ public static class User {
public User(String name) {
this.name = name;
}
public Optional<String> getName() {
return Optional.ofNullable(name);
}
Expand Down

0 comments on commit 135e760

Please sign in to comment.