Repository: quarkusio/quarkus
Issue: JUnit @Nested Inner Classes with @BeforeAll and @Transactional annotations fail on initialization after upgrading to 2.16.3.Final

### Describe the bug

After upgrading from version `2.15.3.Final` to `2.16.3.Final`, Tests on Inner Classes annotated with `@Nested` and methods annotated with `@BeforeAll` and `@Transactional` fail on initialization.

### Expected behavior

Tests on Inner Classes annotated with JUnit @Nested annotation should keep working as in the previous version (`2.15.3.Final`).

### Actual behavior

After upgrading from version 2.15.3.Final to 2.16.3.Final, Tests on Inner Classes annotated with `@Nested` and methods annotated with `@BeforeAll` and `@Transactional` fail on initialization.

```shell
java.lang.RuntimeException: java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.arc.deployment.ArcProcessor#generateResources threw an exception: javax.enterprise.inject.spi.DeploymentException: Found 2 deployment problems: 
[1] The INNER class org.acme.FruitResourceTest$AnotherFruitInnerClass declares an interceptor binding but it must be ignored per CDI rules
[2] The INNER class org.acme.FruitResourceTest$AFruitInnerClass declares an interceptor binding but it must be ignored per CDI rules
	at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1231)
	at io.quarkus.arc.processor.BeanProcessor.processValidationErrors(BeanProcessor.java:161)
	at io.quarkus.arc.deployment.ArcProcessor.generateResources(ArcProcessor.java:559)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:281)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at java.base/java.lang.Thread.run(Thread.java:833)
	at org.jboss.threads.JBossThread.run(JBossThread.java:501)
	Suppressed: java.lang.IllegalStateException: The INNER class org.acme.FruitResourceTest$AnotherFruitInnerClass declares an interceptor binding but it must be ignored per CDI rules
		at io.quarkus.arc.deployment.WrongAnnotationUsageProcessor.detect(WrongAnnotationUsageProcessor.java:100)
		... 11 more
	Suppressed: java.lang.IllegalStateException: The INNER class org.acme.FruitResourceTest$AFruitInnerClass declares an interceptor binding but it must be ignored per CDI rules
		at io.quarkus.arc.deployment.WrongAnnotationUsageProcessor.detect(WrongAnnotationUsageProcessor.java:100)
		... 11 more
```

## Test Class:
```java
package org.acme;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

import javax.transaction.Transactional;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.jupiter.api.TestInstance.Lifecycle.PER_CLASS;

@QuarkusTest
@QuarkusTestResource(PostgresTestResource.class)
@TestInstance(PER_CLASS)
class FruitResourceTest {

    @BeforeAll
    void doSomeImportantStuffBeforeAllTests() {
        //
    }

    @Nested
    @DisplayName("This is a special Test in an Inner class")
    @TestInstance(PER_CLASS)
    class AFruitInnerClass {

        @BeforeAll
        // Commenting out @Transactional annotations makes tests to pass.
        @Transactional
        static void doSomeImportantStuffBeforeAllTests() {
            //
        }

        @Test
        void testGetFruitByIdEndpoint() {
            given()
                    .when().get("/fruits/1")
                    .then()
                    .statusCode(200)
                    .body(containsString("Banana"));
        }
    }

    @Nested
    @DisplayName("This is a special Test in an Inner class")
    @TestInstance(PER_CLASS)
    class AnotherFruitInnerClass {

        @BeforeAll
        // Commenting out @Transactional annotations makes tests to pass.
        @Transactional
        static void doSomeImportantStuffBeforeAllTests() {
            //
        }

        @Test
        void testGetFruitByIdEndpointAgain() {
            given()
                    .when().get("/fruits/1")
                    .then()
                    .statusCode(200)
                    .body(containsString("Banana"));
        }
    }
}

```

### How to Reproduce?

Steps to reproduce the issue:
Reproducer repository: https://github.com/fernandobalieiro/quarkus-nested-test-error

1. `git clone https://github.com/fernandobalieiro/quarkus-nested-test-error`
2. `cd quarkus-nested-test-error`
3. Run `./mvnw clean test `
4. Tests will fail with the following result:
```shell
[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Errors: 
[ERROR]   FruitResourceTest » Runtime java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
        [error]: Build step io.quarkus.arc.deployment.ArcProcessor#generateResources threw an exception: javax.enterprise.inject.spi.DeploymentException: Found 2 deployment problems: 
[1] The INNER class org.acme.FruitResourceTest$AnotherFruitInnerClass declares an interceptor binding but it must be ignored per CDI rules
[2] The INNER class org.acme.FruitResourceTest$AFruitInnerClass declares an interceptor binding but it must be ignored per CDI rules
        at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1231)
        at io.quarkus.arc.processor.BeanProcessor.processValidationErrors(BeanProcessor.java:161)
        at io.quarkus.arc.deployment.ArcProcessor.generateResources(ArcProcessor.java:559)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:909)
        at io.quarkus.builder.BuildContext.run(BuildContext.java:281)
        at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
        at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
        at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
        at java.base/java.lang.Thread.run(Thread.java:833)
        at org.jboss.threads.JBossThread.run(JBossThread.java:501)
        Suppressed: java.lang.IllegalStateException: The INNER class org.acme.FruitResourceTest$AnotherFruitInnerClass declares an interceptor binding but it must be ignored per CDI rules
                at io.quarkus.arc.deployment.WrongAnnotationUsageProcessor.detect(WrongAnnotationUsageProcessor.java:100)
                ... 11 more
        Suppressed: java.lang.IllegalStateException: The INNER class org.acme.FruitResourceTest$AFruitInnerClass declares an interceptor binding but it must be ignored per CDI rules
                at io.quarkus.arc.deployment.WrongAnnotationUsageProcessor.detect(WrongAnnotationUsageProcessor.java:100)
                ... 11 more

[INFO] 
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  15.029 s
[INFO] Finished at: 2023-03-02T17:26:30Z
[INFO] ------------------------------------------------------------------------
```

### Output of `uname -a` or `ver`

Linux neo 5.19.0-35-generic #36~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Fri Feb 17 15:17:25 UTC 2 x86_64 x86_64 x86_64 GNU/Linux

### Output of `java -version`

openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05)
OpenJDK 64-Bit Server VM GraalVM CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05, mixed mode, sharing)

### GraalVM version (if different from Java)

CE 21.3.0 (build 17.0.1+12-jvmci-21.3-b05, mixed mode, sharing)

### Quarkus version or git rev

2.16.3.Final

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

Apache Maven 3.8.4 (9b656c72d54e5bacbed989b64718c159fe39b537)
Maven home: /home/neo/.m2/wrapper/dists/apache-maven-3.8.4-bin/52ccbt68d252mdldqsfsn03jlf/apache-maven-3.8.4
Java version: 17.0.2, vendor: GraalVM Community, runtime: /home/neo/.asdf/installs/java/graalvm-22.0.0.2+java17
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "5.19.0-35-generic", arch: "amd64", family: "unix"

### Additional information

_No response_

Changed files:
extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/WrongAnnotationUsageProcessor.java

diff --git a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/WrongAnnotationUsageProcessor.java b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/WrongAnnotationUsageProcessor.java
index a68213e6271..5bbd2bdfcc3 100644
--- a/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/WrongAnnotationUsageProcessor.java
+++ b/extensions/arc/deployment/src/main/java/io/quarkus/arc/deployment/WrongAnnotationUsageProcessor.java
@@ -13,7 +13,9 @@
 import org.jboss.jandex.ClassInfo;
 import org.jboss.jandex.ClassInfo.NestingType;
 import org.jboss.jandex.DotName;
+import org.jboss.jandex.FieldInfo;
 import org.jboss.jandex.IndexView;
+import org.jboss.jandex.MethodInfo;
 
 import io.quarkus.arc.deployment.ValidationPhaseBuildItem.ValidationErrorBuildItem;
 import io.quarkus.arc.processor.Annotations;
@@ -72,35 +74,66 @@ void detect(ArcConfig config, ApplicationIndexBuildItem applicationIndex, Custom
             NestingType nestingType = clazz.nestingType();
             if (NestingType.ANONYMOUS == nestingType || NestingType.LOCAL == nestingType
                     || (NestingType.INNER == nestingType && !Modifier.isStatic(clazz.flags()))) {
-                // Annotations declared on the class, incl. the annotations added via transformers
-                Collection<AnnotationInstance> classAnnotations = transformedAnnotations.getAnnotations(clazz);
-                if (classAnnotations.isEmpty() && clazz.annotationsMap().isEmpty()) {
-                    continue;
-                }
-                if (scopeAnnotations.isScopeIn(classAnnotations)) {
+                // Annotations declared on the class level, incl. the annotations added via transformers
+                Collection<AnnotationInstance> classLevelAnnotations = transformedAnnotations.getAnnotations(clazz);
+                if (scopeAnnotations.isScopeIn(classLevelAnnotations)) {
                     validationErrors.produce(new ValidationErrorBuildItem(
                             new IllegalStateException(String.format(
                                     "The %s class %s has a scope annotation but it must be ignored per the CDI rules",
                                     clazz.nestingType().toString(), clazz.name().toString()))));
-                } else if (clazz.annotationsMap().containsKey(DotNames.OBSERVES)) {
-                    validationErrors.produce(new ValidationErrorBuildItem(
-                            new IllegalStateException(String.format(
-                                    "The %s class %s declares an observer method but it must be ignored per the CDI rules",
-                                    clazz.nestingType().toString(), clazz.name().toString()))));
-                } else if (clazz.annotationsMap().containsKey(DotNames.PRODUCES)) {
-                    validationErrors.produce(new ValidationErrorBuildItem(
-                            new IllegalStateException(String.format(
-                                    "The %s class %s declares a producer but it must be ignored per the CDI rules",
-                                    clazz.nestingType().toString(), clazz.name().toString()))));
-                } else if (Annotations.containsAny(classAnnotations, interceptorResolverBuildItem.getInterceptorBindings())
-                        || Annotations.containsAny(clazz.annotations(),
-                                interceptorResolverBuildItem.getInterceptorBindings())) {
-                    // detect interceptor bindings on nested classes
+                } else if (Annotations.containsAny(classLevelAnnotations,
+                        interceptorResolverBuildItem.getInterceptorBindings())) {
+                    // detect interceptor bindings declared at nested class level
                     validationErrors.produce(new ValidationErrorBuildItem(
                             new IllegalStateException(String.format(
                                     "The %s class %s declares an interceptor binding but it must be ignored per CDI rules",
                                     clazz.nestingType().toString(), clazz.name().toString()))));
                 }
+
+                // iterate over methods and verify those
+                // note that since JDK 16, you can have static method inside inner non-static class
+                for (MethodInfo methodInfo : clazz.methods()) {
+                    // annotations declared on method level, incl. the annotations added via transformers
+                    Collection<AnnotationInstance> methodAnnotations = transformedAnnotations.getAnnotations(methodInfo);
+                    if (methodAnnotations.isEmpty()) {
+                        continue;
+                    }
+                    if (Annotations.contains(methodAnnotations, DotNames.OBSERVES)
+                            || Annotations.contains(methodAnnotations, DotNames.OBSERVES_ASYNC)) {
+                        validationErrors.produce(new ValidationErrorBuildItem(
+                                new IllegalStateException(String.format(
+                                        "The method %s in the %s class %s declares an observer method but it must be ignored per the CDI rules",
+                                        methodInfo.name(), clazz.nestingType().toString(), clazz.name().toString()))));
+                    } else if (Annotations.contains(methodAnnotations, DotNames.PRODUCES)) {
+                        validationErrors.produce(new ValidationErrorBuildItem(
+                                new IllegalStateException(String.format(
+                                        "The method %s in the %s class %s declares a producer but it must be ignored per the CDI rules",
+                                        methodInfo.name(), clazz.nestingType().toString(), clazz.name().toString()))));
+                    } else if (!Modifier.isStatic(methodInfo.flags()) && Annotations.containsAny(methodAnnotations,
+                            interceptorResolverBuildItem.getInterceptorBindings())) {
+                        // detect interceptor bindings declared at nested class methods
+                        validationErrors.produce(new ValidationErrorBuildItem(
+                                new IllegalStateException(String.format(
+                                        "The method %s in the %s class %s declares an interceptor binding but it must be ignored per CDI rules",
+                                        methodInfo.name(), clazz.nestingType().toString(), clazz.name().toString()))));
+                    }
+
+                }
+
+                // iterate over all fields, check for incorrect producer declarations
+                for (FieldInfo fieldInfo : clazz.fields()) {
+                    // annotations declared on field level, incl. the annotations added via transformers
+                    Collection<AnnotationInstance> fieldAnnotations = transformedAnnotations.getAnnotations(fieldInfo);
+                    if (fieldAnnotations.isEmpty()) {
+                        continue;
+                    }
+                    if (Annotations.contains(fieldAnnotations, DotNames.PRODUCES)) {
+                        validationErrors.produce(new ValidationErrorBuildItem(
+                                new IllegalStateException(String.format(
+                                        "The field %s in the %s class %s declares a producer but it must be ignored per the CDI rules",
+                                        fieldInfo.name(), clazz.nestingType().toString(), clazz.name().toString()))));
+                    }
+                }
             }
         }
     }