From 8379404ae870ad09b7fdb8108577fae341a51526 Mon Sep 17 00:00:00 2001 From: Trask Stalnaker Date: Tue, 11 May 2021 11:22:11 -0700 Subject: [PATCH] Uncomment and fix JAX-RS default method tests (#2930) --- .../ApacheCamelInstrumentationModule.java | 4 +- .../grizzly/HttpHandlerInstrumentation.java | 4 +- .../GrpcServerBuilderInstrumentation.java | 4 +- ...axRsAnnotations1InstrumentationTest.groovy | 5 +- .../src/test/java/JavaInterfaces.java | 47 ++++++++++--------- ...JaxRsAnnotationsInstrumentationTest.groovy | 5 +- .../src/main/java/JavaInterfaces.java | 47 ++++++++++--------- .../khttp/KHttpInstrumentationModule.java | 4 +- .../vertx/VertxWebInstrumentationModule.java | 6 +-- .../matcher/AgentElementMatchers.java | 6 +-- .../tooling/context/FieldBackedProvider.java | 4 +- .../matcher/HasInterfaceMatcherTest.groovy | 8 ++-- .../ImplementsInterfaceMatcherTest.groovy | 15 +++--- .../SafeHasSuperTypeMatcherTest.groovy | 15 +++--- 14 files changed, 87 insertions(+), 87 deletions(-) diff --git a/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/ApacheCamelInstrumentationModule.java b/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/ApacheCamelInstrumentationModule.java index 5e39ba7e02dc..9f36ce920993 100644 --- a/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/ApacheCamelInstrumentationModule.java +++ b/instrumentation/apache-camel-2.20/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/apachecamel/ApacheCamelInstrumentationModule.java @@ -8,10 +8,8 @@ import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; import static io.opentelemetry.javaagent.extension.matcher.ClassLoaderMatcher.hasClassesNamed; import static java.util.Collections.singletonList; -import static net.bytebuddy.matcher.ElementMatchers.isAbstract; import static net.bytebuddy.matcher.ElementMatchers.isPublic; import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.not; import static net.bytebuddy.matcher.ElementMatchers.takesArguments; import com.google.auto.service.AutoService; @@ -51,7 +49,7 @@ public ElementMatcher classLoaderOptimization() { @Override public ElementMatcher typeMatcher() { - return not(isAbstract()).and(implementsInterface(named("org.apache.camel.CamelContext"))); + return implementsInterface(named("org.apache.camel.CamelContext")); } @Override diff --git a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/HttpHandlerInstrumentation.java b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/HttpHandlerInstrumentation.java index b17def54e582..942bdd5871d5 100644 --- a/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/HttpHandlerInstrumentation.java +++ b/instrumentation/grizzly-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grizzly/HttpHandlerInstrumentation.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.grizzly; -import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.safeHasSuperType; +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.extendsClass; import static io.opentelemetry.javaagent.extension.matcher.ClassLoaderMatcher.hasClassesNamed; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.isPublic; @@ -28,7 +28,7 @@ public ElementMatcher classLoaderOptimization() { @Override public ElementMatcher typeMatcher() { - return safeHasSuperType(named("org.glassfish.grizzly.http.server.HttpHandler")); + return extendsClass(named("org.glassfish.grizzly.http.server.HttpHandler")); } @Override diff --git a/instrumentation/grpc-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grpc/v1_6/GrpcServerBuilderInstrumentation.java b/instrumentation/grpc-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grpc/v1_6/GrpcServerBuilderInstrumentation.java index d15462a6620c..2d132d868544 100644 --- a/instrumentation/grpc-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grpc/v1_6/GrpcServerBuilderInstrumentation.java +++ b/instrumentation/grpc-1.6/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/grpc/v1_6/GrpcServerBuilderInstrumentation.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.grpc.v1_6; -import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.safeHasSuperType; +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.extendsClass; import static io.opentelemetry.javaagent.extension.matcher.ClassLoaderMatcher.hasClassesNamed; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.isPublic; @@ -31,7 +31,7 @@ public ElementMatcher classLoaderOptimization() { @Override public ElementMatcher typeMatcher() { - return safeHasSuperType(named("io.grpc.ServerBuilder")); + return extendsClass(named("io.grpc.ServerBuilder")); } @Override diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy index f5804a78cc2b..6b9a5ea0356a 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/groovy/JaxRsAnnotations1InstrumentationTest.groovy @@ -45,7 +45,7 @@ class JaxRsAnnotations1InstrumentationTest extends AgentInstrumentationSpecifica } @Unroll - def "span named '#paramName' from annotations on class when is not root span"() { + def "span named '#paramName' from annotations on class '#className' when is not root span"() { setup: runUnderServerTrace("test") { obj.call() @@ -128,8 +128,7 @@ class JaxRsAnnotations1InstrumentationTest extends AgentInstrumentationSpecifica } "/child/call" | new ChildClassWithPath() "/child/call" | new JavaInterfaces.ChildClassOnInterface() - // TODO: uncomment when we drop support for Java 7 - // "/child/invoke" | new JavaInterfaces.DefaultChildClassOnInterface() + "/child/call" | new JavaInterfaces.DefaultChildClassOnInterface() className = getClassName(obj.class) } diff --git a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/java/JavaInterfaces.java b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/java/JavaInterfaces.java index 891d2b5f5d07..ed0e594b9942 100644 --- a/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/java/JavaInterfaces.java +++ b/instrumentation/jaxrs/jaxrs-1.0/javaagent/src/test/java/JavaInterfaces.java @@ -23,7 +23,8 @@ interface InterfaceWithClassMethodPath extends Jax { } @Path("abstract") - abstract class AbstractClassOnInterfaceWithClassPath implements InterfaceWithClassMethodPath { + abstract static class AbstractClassOnInterfaceWithClassPath + implements InterfaceWithClassMethodPath { @GET @Path("call") @@ -36,7 +37,7 @@ public void call() { } @Path("child") - class ChildClassOnInterface extends AbstractClassOnInterfaceWithClassPath { + static class ChildClassOnInterface extends AbstractClassOnInterfaceWithClassPath { @Override void actual() { @@ -44,25 +45,25 @@ void actual() { } } - // TODO: uncomment when we drop support for Java 7 - // @Path("interface") - // interface DefaultInterfaceWithClassMethodPath extends Jax { - // - // @GET - // @Path("invoke") - // default void call() { - // actual(); - // } - // - // void actual(); - // } - // - // @Path("child") - // class DefaultChildClassOnInterface implements DefaultInterfaceWithClassMethodPath { - // - // @Override - // public void actual() { - // // do nothing - // } - // } + @Path("interface") + interface DefaultInterfaceWithClassMethodPath extends Jax { + + @Override + @GET + @Path("call") + default void call() { + actual(); + } + + void actual(); + } + + @Path("child") + static class DefaultChildClassOnInterface implements DefaultInterfaceWithClassMethodPath { + + @Override + public void actual() { + // do nothing + } + } } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsAnnotationsInstrumentationTest.groovy b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsAnnotationsInstrumentationTest.groovy index 94be17057859..8f2dd2c40fba 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsAnnotationsInstrumentationTest.groovy +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/groovy/JaxRsAnnotationsInstrumentationTest.groovy @@ -45,7 +45,7 @@ abstract class JaxRsAnnotationsInstrumentationTest extends AgentInstrumentationS } @Unroll - def "span named '#paramName' from annotations on class when is not root span"() { + def "span named '#paramName' from annotations on class '#className' when is not root span"() { setup: runUnderServerTrace("test") { obj.call() @@ -128,8 +128,7 @@ abstract class JaxRsAnnotationsInstrumentationTest extends AgentInstrumentationS } "/child/call" | new ChildClassWithPath() "/child/call" | new JavaInterfaces.ChildClassOnInterface() - // TODO: uncomment when we drop support for Java 7 -// "GET /child/invoke" | new JavaInterfaces.DefaultChildClassOnInterface() + "/child/call" | new JavaInterfaces.DefaultChildClassOnInterface() className = getClassName(obj.class) } diff --git a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/java/JavaInterfaces.java b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/java/JavaInterfaces.java index 891d2b5f5d07..ed0e594b9942 100644 --- a/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/java/JavaInterfaces.java +++ b/instrumentation/jaxrs/jaxrs-2.0/jaxrs-2.0-testing/src/main/java/JavaInterfaces.java @@ -23,7 +23,8 @@ interface InterfaceWithClassMethodPath extends Jax { } @Path("abstract") - abstract class AbstractClassOnInterfaceWithClassPath implements InterfaceWithClassMethodPath { + abstract static class AbstractClassOnInterfaceWithClassPath + implements InterfaceWithClassMethodPath { @GET @Path("call") @@ -36,7 +37,7 @@ public void call() { } @Path("child") - class ChildClassOnInterface extends AbstractClassOnInterfaceWithClassPath { + static class ChildClassOnInterface extends AbstractClassOnInterfaceWithClassPath { @Override void actual() { @@ -44,25 +45,25 @@ void actual() { } } - // TODO: uncomment when we drop support for Java 7 - // @Path("interface") - // interface DefaultInterfaceWithClassMethodPath extends Jax { - // - // @GET - // @Path("invoke") - // default void call() { - // actual(); - // } - // - // void actual(); - // } - // - // @Path("child") - // class DefaultChildClassOnInterface implements DefaultInterfaceWithClassMethodPath { - // - // @Override - // public void actual() { - // // do nothing - // } - // } + @Path("interface") + interface DefaultInterfaceWithClassMethodPath extends Jax { + + @Override + @GET + @Path("call") + default void call() { + actual(); + } + + void actual(); + } + + @Path("child") + static class DefaultChildClassOnInterface implements DefaultInterfaceWithClassMethodPath { + + @Override + public void actual() { + // do nothing + } + } } diff --git a/instrumentation/khttp-0.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/khttp/KHttpInstrumentationModule.java b/instrumentation/khttp-0.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/khttp/KHttpInstrumentationModule.java index f45f3b5a1f16..ee41a6c3fbc9 100644 --- a/instrumentation/khttp-0.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/khttp/KHttpInstrumentationModule.java +++ b/instrumentation/khttp-0.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/khttp/KHttpInstrumentationModule.java @@ -5,7 +5,7 @@ package io.opentelemetry.javaagent.instrumentation.khttp; -import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.safeHasSuperType; +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.extendsClass; import static io.opentelemetry.javaagent.extension.matcher.ClassLoaderMatcher.hasClassesNamed; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; @@ -45,7 +45,7 @@ public ElementMatcher classLoaderOptimization() { @Override public ElementMatcher typeMatcher() { - return safeHasSuperType(named("khttp.KHttp")); + return extendsClass(named("khttp.KHttp")); } @Override diff --git a/instrumentation/vertx-web-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/VertxWebInstrumentationModule.java b/instrumentation/vertx-web-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/VertxWebInstrumentationModule.java index 5eb83c1f865d..65ade1fe4006 100644 --- a/instrumentation/vertx-web-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/VertxWebInstrumentationModule.java +++ b/instrumentation/vertx-web-3.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/VertxWebInstrumentationModule.java @@ -5,14 +5,12 @@ package io.opentelemetry.javaagent.instrumentation.vertx; -import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.safeHasSuperType; +import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; import static io.opentelemetry.javaagent.extension.matcher.ClassLoaderMatcher.hasClassesNamed; import static java.util.Collections.singletonList; import static java.util.Collections.singletonMap; -import static net.bytebuddy.matcher.ElementMatchers.isInterface; import static net.bytebuddy.matcher.ElementMatchers.isMethod; import static net.bytebuddy.matcher.ElementMatchers.named; -import static net.bytebuddy.matcher.ElementMatchers.not; import static net.bytebuddy.matcher.ElementMatchers.takesArgument; import com.google.auto.service.AutoService; @@ -47,7 +45,7 @@ public ElementMatcher classLoaderOptimization() { @Override public ElementMatcher typeMatcher() { - return not(isInterface()).and(safeHasSuperType(named("io.vertx.ext.web.Route"))); + return implementsInterface(named("io.vertx.ext.web.Route")); } @Override diff --git a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/matcher/AgentElementMatchers.java b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/matcher/AgentElementMatchers.java index e57e0e14734d..dd79c30fe8f5 100644 --- a/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/matcher/AgentElementMatchers.java +++ b/javaagent-extension-api/src/main/java/io/opentelemetry/javaagent/extension/matcher/AgentElementMatchers.java @@ -25,8 +25,7 @@ public static ElementMatcher.Junction extendsClass( public static ElementMatcher.Junction implementsInterface( ElementMatcher matcher) { - return not(isInterface()) - .and(new SafeHasSuperTypeMatcher(new SafeErasureMatcher<>(matcher), true)); + return new SafeHasSuperTypeMatcher(new SafeErasureMatcher<>(matcher), true); } public static ElementMatcher.Junction hasInterface( @@ -36,8 +35,7 @@ public static ElementMatcher.Junction hasInterface( public static ElementMatcher.Junction safeHasSuperType( ElementMatcher matcher) { - return not(isInterface()) - .and(new SafeHasSuperTypeMatcher(new SafeErasureMatcher<>(matcher), false)); + return new SafeHasSuperTypeMatcher(new SafeErasureMatcher<>(matcher), false); } /** diff --git a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/context/FieldBackedProvider.java b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/context/FieldBackedProvider.java index 628757510844..458fa4891dc5 100644 --- a/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/context/FieldBackedProvider.java +++ b/javaagent-tooling/src/main/java/io/opentelemetry/javaagent/tooling/context/FieldBackedProvider.java @@ -7,7 +7,9 @@ import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.safeHasSuperType; import static io.opentelemetry.javaagent.extension.matcher.ClassLoaderMatcher.BOOTSTRAP_CLASSLOADER; +import static net.bytebuddy.matcher.ElementMatchers.isAbstract; import static net.bytebuddy.matcher.ElementMatchers.named; +import static net.bytebuddy.matcher.ElementMatchers.not; import io.opentelemetry.instrumentation.api.caching.Cache; import io.opentelemetry.instrumentation.api.config.Config; @@ -385,7 +387,7 @@ public AgentBuilder.Identified.Extendable additionalInstrumentation( */ builder = builder - .type(safeHasSuperType(named(entry.getKey()))) + .type(not(isAbstract()).and(safeHasSuperType(named(entry.getKey())))) .and(safeToInjectFieldsMatcher()) .and(ActualInstrumentationExtensionImplementation.NOT_DECORATOR_MATCHER) .transform(NoOpTransformer.INSTANCE); diff --git a/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/HasInterfaceMatcherTest.groovy b/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/HasInterfaceMatcherTest.groovy index 90ff04eaad14..17a57d6ade4e 100644 --- a/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/HasInterfaceMatcherTest.groovy +++ b/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/HasInterfaceMatcherTest.groovy @@ -10,10 +10,13 @@ import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers. import static net.bytebuddy.matcher.ElementMatchers.named import io.opentelemetry.javaagent.tooling.AgentTooling -import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.* +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.A +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.B +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.E +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.F +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.G import net.bytebuddy.description.type.TypeDescription import net.bytebuddy.description.type.TypeList -import net.bytebuddy.jar.asm.Opcodes import spock.lang.Shared import spock.lang.Specification @@ -57,7 +60,6 @@ class HasInterfaceMatcherTest extends Specification { then: !result // default to false noExceptionThrown() - 1 * type.getModifiers() >> Opcodes.ACC_ABSTRACT 1 * type.isInterface() >> true 1 * type.asGenericType() >> typeGeneric 1 * typeGeneric.asErasure() >> { throw new Exception("asErasure exception") } diff --git a/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/ImplementsInterfaceMatcherTest.groovy b/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/ImplementsInterfaceMatcherTest.groovy index 091b17fd716a..d73269869b4f 100644 --- a/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/ImplementsInterfaceMatcherTest.groovy +++ b/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/ImplementsInterfaceMatcherTest.groovy @@ -9,10 +9,13 @@ import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers. import static net.bytebuddy.matcher.ElementMatchers.named import io.opentelemetry.javaagent.tooling.AgentTooling -import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.* +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.A +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.B +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.E +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.F +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.G import net.bytebuddy.description.type.TypeDescription import net.bytebuddy.description.type.TypeList -import net.bytebuddy.jar.asm.Opcodes import spock.lang.Shared import spock.lang.Specification @@ -28,10 +31,10 @@ class ImplementsInterfaceMatcherTest extends Specification { where: matcherClass | type | result - A | A | false - A | B | false + A | A | true + A | B | true B | A | false - A | E | false + A | E | true A | F | true A | G | true F | A | false @@ -54,7 +57,6 @@ class ImplementsInterfaceMatcherTest extends Specification { then: !result // default to false noExceptionThrown() - 1 * type.getModifiers() >> Opcodes.ACC_ABSTRACT 1 * type.isInterface() >> true 1 * type.asGenericType() >> typeGeneric 1 * typeGeneric.asErasure() >> { throw new Exception("asErasure exception") } @@ -79,7 +81,6 @@ class ImplementsInterfaceMatcherTest extends Specification { then: !result // default to false noExceptionThrown() - 1 * type.getModifiers() >> Opcodes.ACC_ABSTRACT 1 * type.isInterface() >> true 1 * type.asGenericType() >> typeGeneric 1 * typeGeneric.asErasure() >> { throw new Exception("asErasure exception") } diff --git a/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/SafeHasSuperTypeMatcherTest.groovy b/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/SafeHasSuperTypeMatcherTest.groovy index e4d446541bfd..bb0c7388c863 100644 --- a/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/SafeHasSuperTypeMatcherTest.groovy +++ b/javaagent-tooling/src/test/groovy/io/opentelemetry/javaagent/tooling/bytebuddy/matcher/SafeHasSuperTypeMatcherTest.groovy @@ -9,10 +9,13 @@ import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers. import static net.bytebuddy.matcher.ElementMatchers.named import io.opentelemetry.javaagent.tooling.AgentTooling -import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.* +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.A +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.B +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.E +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.F +import io.opentelemetry.javaagent.tooling.bytebuddy.matcher.testclasses.G import net.bytebuddy.description.type.TypeDescription import net.bytebuddy.description.type.TypeList -import net.bytebuddy.jar.asm.Opcodes import spock.lang.Shared import spock.lang.Specification @@ -28,10 +31,10 @@ class SafeHasSuperTypeMatcherTest extends Specification { where: matcherClass | type | result - A | A | false - A | B | false + A | A | true + A | B | true B | A | false - A | E | false + A | E | true A | F | true B | G | true F | A | false @@ -54,7 +57,6 @@ class SafeHasSuperTypeMatcherTest extends Specification { then: !result // default to false noExceptionThrown() - 1 * type.getModifiers() >> Opcodes.ACC_ABSTRACT 1 * type.asGenericType() >> typeGeneric 1 * typeGeneric.asErasure() >> { throw new Exception("asErasure exception") } 1 * typeGeneric.getTypeName() >> "typeGeneric-name" @@ -78,7 +80,6 @@ class SafeHasSuperTypeMatcherTest extends Specification { then: !result // default to false noExceptionThrown() - 1 * type.getModifiers() >> Opcodes.ACC_ABSTRACT 1 * type.getInterfaces() >> interfaces 1 * interfaces.iterator() >> it 1 * type.asGenericType() >> typeGeneric