rewrite-testing-frameworks icon indicating copy to clipboard operation
rewrite-testing-frameworks copied to clipboard

CategoryToTag - ClassCastException on fully-qualified class as category

Open nmck257 opened this issue 2 years ago • 1 comments

Test case:

    @Test
    void fullyQualifedClass() {
        rewriteRun(
          java(
            """
              package a;
              public interface FastTests {}
              """
          ),
          java(
            """
                  package b;
                  
                  import org.junit.experimental.categories.Category;
                  
                  @Category(a.FastTests.class)
                  public class B {
                  }
              """,
            """
                  package b;
                  
                  import org.junit.jupiter.api.Tag;
                  
                  @Tag("FastTests")
                  public class B {
                  }
              """
          )
        );
    }

yields:

java.lang.AssertionError: Failed to parse sources or run recipe Caused by: org.openrewrite.internal.RecipeRunException: Exception while visiting project file 'b\B.java (in B)', caused by: java.lang.ClassCastException: class org.openrewrite.java.tree.J$FieldAccess cannot be cast to class org.openrewrite.java.tree.J$Identifier (org.openrewrite.java.tree.J$FieldAccess and org.openrewrite.java.tree.J$Identifier are in unnamed module of loader 'app'), at org.openrewrite.java.testing.junit5.CategoryToTag$CategoryToTagVisitor.lambda$categoryAnnotationToTagAnnotations$0(CategoryToTag.java:115)

nmck257 avatar Jan 30 '23 15:01 nmck257

Stumbled upon this too. Any idea when this can be fixed?

unconditional avatar Jan 16 '24 09:01 unconditional