openrewrite / rewrite-testing-frameworks

OpenRewrite recipes that perform common Java testing migration tasks.
Apache License 2.0
68 stars 60 forks source link

CategoryToTag - ClassCastException on fully-qualified class as category #305

Open nmck257 opened 1 year ago

nmck257 commented 1 year ago

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)

unconditional commented 6 months ago

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