Skip to content

Commit

Permalink
Split up test into two sources, to show unchanged clearly
Browse files Browse the repository at this point in the history
Remove test that did not extend HandlerInterceptorAdapter at all
  • Loading branch information
timtebeek committed Nov 11, 2024
1 parent 6e92c6a commit 1f53c0f
Showing 1 changed file with 12 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.junit.jupiter.api.Test;
import org.openrewrite.DocumentExample;
import org.openrewrite.Issue;
import org.openrewrite.java.JavaParser;
import org.openrewrite.java.spring.framework.MigrateHandlerInterceptor;
import org.openrewrite.test.RecipeSpec;
Expand Down Expand Up @@ -67,23 +68,18 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
);
}

@Issue("https://github.com/openrewrite/rewrite-spring/issues/620")
@Test
void doesNotReplaceInterceptorsExtendingOwnInterceptors() {
//language=java
rewriteRun(
// Do change classes that directly extend HandlerInterceptorAdapter
java(
"""
import javax.servlet.http.*;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
class MyInterceptor extends MySuperInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
return super.preHandle(request, response, handler);
}
}
class MySuperInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
Expand All @@ -96,51 +92,28 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
import org.springframework.web.servlet.HandlerInterceptor;
class MyInterceptor extends MySuperInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
return super.preHandle(request, response, handler);
}
}
class MySuperInterceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
return HandlerInterceptor.super.preHandle(request, response, handler);
}
}
"""
)
);
}

@Test
void unusedImportOfHandlerInterceptorAdapterAndHasASuperCallShouldDoNothing() {
//language=java
rewriteRun(
),
// But do not change classes that transitively extend HandlerInterceptorAdapter
java(
"""
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
import javax.servlet.http.*;
class MyInterceptorLike extends MySuperInterceptor {
@Override
public boolean test() {
return super.test();
}
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; // Unused but untouched
class MyInterceptor extends MySuperInterceptor {
@Override
public boolean test2() {
return super.test();
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
return super.preHandle(request, response, handler);
}
}
class MySuperInterceptor {
public boolean test() {
return true;
}
public boolean test2() {
return true;
}
}"""
"""
)
);
}
Expand Down

0 comments on commit 1f53c0f

Please sign in to comment.