From e1120260e0d63dd160c77b912ece05d6d4c7cc0d Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 30 Sep 2025 17:43:05 +0200 Subject: [PATCH 1/7] convert test --- .../muzzle/HelperReferenceWrapperTest.groovy | 152 ----------------- .../muzzle/HelperReferenceWrapperTest.java | 158 ++++++++++++++++++ .../HelperReferenceWrapperTestClasses.java | 4 +- 3 files changed, 160 insertions(+), 154 deletions(-) delete mode 100644 muzzle/src/test/groovy/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.groovy create mode 100644 muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java diff --git a/muzzle/src/test/groovy/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.groovy b/muzzle/src/test/groovy/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.groovy deleted file mode 100644 index 32d869e87afa..000000000000 --- a/muzzle/src/test/groovy/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.groovy +++ /dev/null @@ -1,152 +0,0 @@ -/* - * Copyright The OpenTelemetry Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package io.opentelemetry.javaagent.tooling.muzzle - -import io.opentelemetry.javaagent.tooling.muzzle.references.ClassRef -import io.opentelemetry.javaagent.tooling.muzzle.references.Flag -import io.opentelemetry.javaagent.tooling.muzzle.references.Source -import muzzle.HelperReferenceWrapperTestClasses -import net.bytebuddy.pool.TypePool -import org.objectweb.asm.Type -import spock.lang.Shared -import spock.lang.Specification - -import static io.opentelemetry.javaagent.tooling.muzzle.references.Flag.ManifestationFlag -import static java.util.stream.Collectors.toList - -class HelperReferenceWrapperTest extends Specification { - - @Shared - def baseHelperClass = ClassRef.builder(HelperReferenceWrapperTest.name + '$BaseHelper') - .setSuperClassName(HelperReferenceWrapperTestClasses.AbstractClasspathType.name) - .addFlag(ManifestationFlag.ABSTRACT) - .addMethod(new Source[0], new Flag[0], "foo", Type.VOID_TYPE) - .addMethod(new Source[0], [ManifestationFlag.ABSTRACT] as Flag[], "abstract", Type.INT_TYPE) - .build() - - @Shared - def helperClass = ClassRef.builder(HelperReferenceWrapperTest.name + '$Helper') - .setSuperClassName(baseHelperClass.className) - .addInterfaceName(HelperReferenceWrapperTestClasses.Interface2.name) - .addMethod(new Source[0], new Flag[0], "bar", Type.VOID_TYPE) - .addField(new Source[0], new Flag[0], "field", Type.getType("Ljava/lang/Object;"), false) - .addField(new Source[0], new Flag[0], "declaredField", Type.getType("Ljava/lang/Object;"), true) - .addField(new Source[0], [Flag.VisibilityFlag.PRIVATE] as Flag[], "privateFieldsAreSkipped", Type.getType("Ljava/lang/Object;"), true) - .build() - - def "should wrap helper types"() { - given: - def typePool = TypePool.Default.of(HelperReferenceWrapperTest.classLoader) - def references = [ - (helperClass.className) : helperClass, - (baseHelperClass.className): baseHelperClass - ] - - when: - def helperClassPredicate = new HelperClassPredicate({ false }) - def helperWrapper = new HelperReferenceWrapper.Factory(typePool, references, helperClassPredicate).create(helperClass) - - then: - with(helperWrapper) { helper -> - !helper.abstract - - with(helper.methods.collect(toList())) { - it.size() == 1 - with(it[0]) { - !it.abstract - it.name == "bar" - it.descriptor == "()V" - } - } - - with(helper.fields.collect(toList())) { - it.size() == 1 - with(it[0]) { - it.name == "declaredField" - it.descriptor == "Ljava/lang/Object;" - } - } - - helper.hasSuperTypes() - with(helper.superTypes.collect(toList())) { - it.size() == 2 - with(it[0]) { baseHelper -> - baseHelper.abstract - - with(baseHelper.methods.collect(toList())) { - it.size() == 2 - with(it[0]) { - !it.abstract - it.name == 'foo' - it.descriptor == '()V' - } - with(it[1]) { - it.abstract - it.name == 'abstract' - it.descriptor == '()I' - } - } - - baseHelper.hasSuperTypes() - with(baseHelper.superTypes.collect(toList())) { - it.size() == 1 - with(it[0]) { abstractClasspathType -> - abstractClasspathType.abstract - - abstractClasspathType.getMethods().collect(toList()).isEmpty() - - with(abstractClasspathType.fields.collect(toList())) { - it.size() == 1 - with(it[0]) { - it.name == "field" - it.descriptor == "Ljava/lang/Object;" - } - } - - abstractClasspathType.hasSuperTypes() - with(abstractClasspathType.superTypes.collect(toList())) { - it.size() == 2 - with(it[0]) { object -> - !object.hasSuperTypes() - } - with(it[1]) { interface1 -> - interface1.abstract - - with(interface1.methods.collect(toList())) { - it.size() == 1 - with(it[0]) { - it.abstract - it.name == "foo" - it.descriptor == "()V" - } - } - - !interface1.hasSuperTypes() - interface1.getSuperTypes().collect(toList()).isEmpty() - } - } - } - } - } - with(it[1]) { interface2 -> - interface2.abstract - - with(interface2.methods.collect(toList())) { - it.size() == 1 - with(it[0]) { - it.abstract - it.name == "bar" - it.descriptor == "()V" - } - } - - !interface2.hasSuperTypes() - interface2.getSuperTypes().collect(toList()).isEmpty() - } - } - } - } -} diff --git a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java new file mode 100644 index 000000000000..7423e32d2f86 --- /dev/null +++ b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java @@ -0,0 +1,158 @@ +/* + * Copyright The OpenTelemetry Authors + * SPDX-License-Identifier: Apache-2.0 + */ + +package io.opentelemetry.javaagent.tooling.muzzle; + +import io.opentelemetry.javaagent.tooling.muzzle.references.Flag.ManifestationFlag; +import static org.assertj.core.api.Assertions.assertThat; + +import io.opentelemetry.javaagent.tooling.muzzle.references.ClassRef; +import io.opentelemetry.javaagent.tooling.muzzle.references.Flag; +import io.opentelemetry.javaagent.tooling.muzzle.references.Source; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import muzzle.HelperReferenceWrapperTestClasses; +import net.bytebuddy.pool.TypePool; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.objectweb.asm.Type; + +class HelperReferenceWrapperTest { + + private static ClassRef baseHelperClass; + private static ClassRef helperClass; + + @BeforeAll + static void setup() { + baseHelperClass = + ClassRef.builder(HelperReferenceWrapperTest.class.getName() + "$BaseHelper") + .setSuperClassName( + HelperReferenceWrapperTestClasses.AbstractClasspathType.class.getName()) + .addFlag(ManifestationFlag.ABSTRACT) + .addMethod(new Source[0], new Flag[0], "foo", Type.VOID_TYPE) + .addMethod( + new Source[0], new Flag[] {ManifestationFlag.ABSTRACT}, "abstract", Type.INT_TYPE) + .build(); + + helperClass = + ClassRef.builder(HelperReferenceWrapperTest.class.getName() + "$Helper") + .setSuperClassName(baseHelperClass.getClassName()) + .addInterfaceName(HelperReferenceWrapperTestClasses.Interface2.class.getName()) + .addMethod(new Source[0], new Flag[0], "bar", Type.VOID_TYPE) + .addField( + new Source[0], new Flag[0], "field", Type.getType("Ljava/lang/Object;"), false) + .addField( + new Source[0], + new Flag[0], + "declaredField", + Type.getType("Ljava/lang/Object;"), + true) + .addField( + new Source[0], + new Flag[] {Flag.VisibilityFlag.PRIVATE}, + "privateFieldsAreSkipped", + Type.getType("Ljava/lang/Object;"), + true) + .build(); + } + + @Test + void shouldWrapHelperTypes() { + TypePool typePool = TypePool.Default.of(HelperReferenceWrapperTest.class.getClassLoader()); + Map references = new HashMap<>(); + references.put(helperClass.getClassName(), helperClass); + references.put(baseHelperClass.getClassName(), baseHelperClass); + + HelperClassPredicate helperClassPredicate = new HelperClassPredicate(cls -> false); + HelperReferenceWrapper helperWrapper = + new HelperReferenceWrapper.Factory(typePool, references, helperClassPredicate) + .create(helperClass); + + // helperWrapper assertions + assertThat(helperWrapper.isAbstract()).isFalse(); + + List helperMethods = + helperWrapper.getMethods().collect(Collectors.toList()); + assertThat(helperMethods).hasSize(1); + HelperReferenceWrapper.Method barMethod = helperMethods.get(0); + assertThat(barMethod.isAbstract()).isFalse(); + assertThat(barMethod.getName()).isEqualTo("bar"); + assertThat(barMethod.getDescriptor()).isEqualTo("()V"); + + List helperFields = + helperWrapper.getFields().collect(Collectors.toList()); + assertThat(helperFields).hasSize(1); + HelperReferenceWrapper.Field declaredField = helperFields.get(0); + assertThat(declaredField.getName()).isEqualTo("declaredField"); + assertThat(declaredField.getDescriptor()).isEqualTo("Ljava/lang/Object;"); + + assertThat(helperWrapper.hasSuperTypes()).isTrue(); + List superTypes = + helperWrapper.getSuperTypes().collect(Collectors.toList()); + assertThat(superTypes).hasSize(2); + + // baseHelper assertions + HelperReferenceWrapper baseHelper = superTypes.get(0); + assertThat(baseHelper.isAbstract()).isTrue(); + List baseHelperMethods = + baseHelper.getMethods().collect(Collectors.toList()); + assertThat(baseHelperMethods).hasSize(2); + HelperReferenceWrapper.Method fooMethod = baseHelperMethods.get(0); + assertThat(fooMethod.isAbstract()).isFalse(); + assertThat(fooMethod.getName()).isEqualTo("foo"); + assertThat(fooMethod.getDescriptor()).isEqualTo("()V"); + HelperReferenceWrapper.Method abstractMethod = baseHelperMethods.get(1); + assertThat(abstractMethod.isAbstract()).isTrue(); + assertThat(abstractMethod.getName()).isEqualTo("abstract"); + assertThat(abstractMethod.getDescriptor()).isEqualTo("()I"); + + assertThat(baseHelper.hasSuperTypes()).isTrue(); + List baseSuperTypes = + baseHelper.getSuperTypes().collect(Collectors.toList()); + assertThat(baseSuperTypes).hasSize(1); + HelperReferenceWrapper abstractClasspathType = baseSuperTypes.get(0); + assertThat(abstractClasspathType.isAbstract()).isTrue(); + assertThat(abstractClasspathType.getMethods().collect(Collectors.toList())).isEmpty(); + List abstractFields = + abstractClasspathType.getFields().collect(Collectors.toList()); + assertThat(abstractFields).hasSize(1); + HelperReferenceWrapper.Field field = abstractFields.get(0); + assertThat(field.getName()).isEqualTo("field"); + assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;"); + + assertThat(abstractClasspathType.hasSuperTypes()).isTrue(); + List abstractSuperTypes = + abstractClasspathType.getSuperTypes().collect(Collectors.toList()); + assertThat(abstractSuperTypes).hasSize(2); + HelperReferenceWrapper objectType = abstractSuperTypes.get(0); + assertThat(objectType.hasSuperTypes()).isFalse(); + HelperReferenceWrapper interface1 = abstractSuperTypes.get(1); + assertThat(interface1.isAbstract()).isTrue(); + List interface1Methods = + interface1.getMethods().collect(Collectors.toList()); + assertThat(interface1Methods).hasSize(1); + HelperReferenceWrapper.Method interface1Method = interface1Methods.get(0); + assertThat(interface1Method.isAbstract()).isTrue(); + assertThat(interface1Method.getName()).isEqualTo("foo"); + assertThat(interface1Method.getDescriptor()).isEqualTo("()V"); + assertThat(interface1.hasSuperTypes()).isFalse(); + assertThat(interface1.getSuperTypes().collect(Collectors.toList())).isEmpty(); + + // interface2 assertions + HelperReferenceWrapper interface2 = superTypes.get(1); + assertThat(interface2.isAbstract()).isTrue(); + List interface2Methods = + interface2.getMethods().collect(Collectors.toList()); + assertThat(interface2Methods).hasSize(1); + HelperReferenceWrapper.Method interface2Method = interface2Methods.get(0); + assertThat(interface2Method.isAbstract()).isTrue(); + assertThat(interface2Method.getName()).isEqualTo("bar"); + assertThat(interface2Method.getDescriptor()).isEqualTo("()V"); + assertThat(interface2.hasSuperTypes()).isFalse(); + assertThat(interface2.getSuperTypes().collect(Collectors.toList())).isEmpty(); + } +} diff --git a/muzzle/src/test/java/muzzle/HelperReferenceWrapperTestClasses.java b/muzzle/src/test/java/muzzle/HelperReferenceWrapperTestClasses.java index 33aa01c97d48..62c4369e7804 100644 --- a/muzzle/src/test/java/muzzle/HelperReferenceWrapperTestClasses.java +++ b/muzzle/src/test/java/muzzle/HelperReferenceWrapperTestClasses.java @@ -12,11 +12,11 @@ interface Interface1 { void foo(); } - interface Interface2 { + public interface Interface2 { void bar(); } - abstract static class AbstractClasspathType implements Interface1 { + public abstract static class AbstractClasspathType implements Interface1 { private Object privateFieldsAreIgnored; protected Object field; From 834c051fc7c0fbea3de1a4d20051346e014729f4 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 7 Oct 2025 12:19:27 +0200 Subject: [PATCH 2/7] improve --- .../muzzle/HelperReferenceWrapperTest.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java index 7423e32d2f86..07018dc9e52c 100644 --- a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java +++ b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java @@ -5,11 +5,12 @@ package io.opentelemetry.javaagent.tooling.muzzle; -import io.opentelemetry.javaagent.tooling.muzzle.references.Flag.ManifestationFlag; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.atIndex; import io.opentelemetry.javaagent.tooling.muzzle.references.ClassRef; import io.opentelemetry.javaagent.tooling.muzzle.references.Flag; +import io.opentelemetry.javaagent.tooling.muzzle.references.Flag.ManifestationFlag; import io.opentelemetry.javaagent.tooling.muzzle.references.Source; import java.util.HashMap; import java.util.List; @@ -75,13 +76,13 @@ void shouldWrapHelperTypes() { // helperWrapper assertions assertThat(helperWrapper.isAbstract()).isFalse(); - List helperMethods = - helperWrapper.getMethods().collect(Collectors.toList()); - assertThat(helperMethods).hasSize(1); - HelperReferenceWrapper.Method barMethod = helperMethods.get(0); - assertThat(barMethod.isAbstract()).isFalse(); - assertThat(barMethod.getName()).isEqualTo("bar"); - assertThat(barMethod.getDescriptor()).isEqualTo("()V"); + assertThat(helperWrapper.getMethods()) + .hasSize(1) + .satisfies(method -> { + assertThat(method.isAbstract()).isFalse(); + assertThat(method.getName()).isEqualTo("bar"); + assertThat(method.getDescriptor()).isEqualTo("()V"); + }, atIndex(0)); List helperFields = helperWrapper.getFields().collect(Collectors.toList()); From 3c532baa765a8d31b7af3c7d12e5426b8e58a8b3 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 7 Oct 2025 12:22:01 +0200 Subject: [PATCH 3/7] improve --- .../muzzle/HelperReferenceWrapperTest.java | 65 +++++++++++-------- 1 file changed, 38 insertions(+), 27 deletions(-) diff --git a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java index 07018dc9e52c..9ca87bda0e10 100644 --- a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java +++ b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java @@ -86,10 +86,12 @@ void shouldWrapHelperTypes() { List helperFields = helperWrapper.getFields().collect(Collectors.toList()); - assertThat(helperFields).hasSize(1); - HelperReferenceWrapper.Field declaredField = helperFields.get(0); - assertThat(declaredField.getName()).isEqualTo("declaredField"); - assertThat(declaredField.getDescriptor()).isEqualTo("Ljava/lang/Object;"); + assertThat(helperFields) + .hasSize(1) + .satisfies(field -> { + assertThat(field.getName()).isEqualTo("declaredField"); + assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;"); + }, atIndex(0)); assertThat(helperWrapper.hasSuperTypes()).isTrue(); List superTypes = @@ -101,15 +103,18 @@ void shouldWrapHelperTypes() { assertThat(baseHelper.isAbstract()).isTrue(); List baseHelperMethods = baseHelper.getMethods().collect(Collectors.toList()); - assertThat(baseHelperMethods).hasSize(2); - HelperReferenceWrapper.Method fooMethod = baseHelperMethods.get(0); - assertThat(fooMethod.isAbstract()).isFalse(); - assertThat(fooMethod.getName()).isEqualTo("foo"); - assertThat(fooMethod.getDescriptor()).isEqualTo("()V"); - HelperReferenceWrapper.Method abstractMethod = baseHelperMethods.get(1); - assertThat(abstractMethod.isAbstract()).isTrue(); - assertThat(abstractMethod.getName()).isEqualTo("abstract"); - assertThat(abstractMethod.getDescriptor()).isEqualTo("()I"); + assertThat(baseHelperMethods) + .hasSize(2) + .satisfies(method -> { + assertThat(method.isAbstract()).isFalse(); + assertThat(method.getName()).isEqualTo("foo"); + assertThat(method.getDescriptor()).isEqualTo("()V"); + }, atIndex(0)) + .satisfies(method -> { + assertThat(method.isAbstract()).isTrue(); + assertThat(method.getName()).isEqualTo("abstract"); + assertThat(method.getDescriptor()).isEqualTo("()I"); + }, atIndex(1)); assertThat(baseHelper.hasSuperTypes()).isTrue(); List baseSuperTypes = @@ -120,10 +125,12 @@ void shouldWrapHelperTypes() { assertThat(abstractClasspathType.getMethods().collect(Collectors.toList())).isEmpty(); List abstractFields = abstractClasspathType.getFields().collect(Collectors.toList()); - assertThat(abstractFields).hasSize(1); - HelperReferenceWrapper.Field field = abstractFields.get(0); - assertThat(field.getName()).isEqualTo("field"); - assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;"); + assertThat(abstractFields) + .hasSize(1) + .satisfies(field -> { + assertThat(field.getName()).isEqualTo("field"); + assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;"); + }, atIndex(0)); assertThat(abstractClasspathType.hasSuperTypes()).isTrue(); List abstractSuperTypes = @@ -135,11 +142,13 @@ void shouldWrapHelperTypes() { assertThat(interface1.isAbstract()).isTrue(); List interface1Methods = interface1.getMethods().collect(Collectors.toList()); - assertThat(interface1Methods).hasSize(1); - HelperReferenceWrapper.Method interface1Method = interface1Methods.get(0); - assertThat(interface1Method.isAbstract()).isTrue(); - assertThat(interface1Method.getName()).isEqualTo("foo"); - assertThat(interface1Method.getDescriptor()).isEqualTo("()V"); + assertThat(interface1Methods) + .hasSize(1) + .satisfies(method -> { + assertThat(method.isAbstract()).isTrue(); + assertThat(method.getName()).isEqualTo("foo"); + assertThat(method.getDescriptor()).isEqualTo("()V"); + }, atIndex(0)); assertThat(interface1.hasSuperTypes()).isFalse(); assertThat(interface1.getSuperTypes().collect(Collectors.toList())).isEmpty(); @@ -148,11 +157,13 @@ void shouldWrapHelperTypes() { assertThat(interface2.isAbstract()).isTrue(); List interface2Methods = interface2.getMethods().collect(Collectors.toList()); - assertThat(interface2Methods).hasSize(1); - HelperReferenceWrapper.Method interface2Method = interface2Methods.get(0); - assertThat(interface2Method.isAbstract()).isTrue(); - assertThat(interface2Method.getName()).isEqualTo("bar"); - assertThat(interface2Method.getDescriptor()).isEqualTo("()V"); + assertThat(interface2Methods) + .hasSize(1) + .satisfies(method -> { + assertThat(method.isAbstract()).isTrue(); + assertThat(method.getName()).isEqualTo("bar"); + assertThat(method.getDescriptor()).isEqualTo("()V"); + }, atIndex(0)); assertThat(interface2.hasSuperTypes()).isFalse(); assertThat(interface2.getSuperTypes().collect(Collectors.toList())).isEmpty(); } From a65fdbf80fb79153a2ba8f563c2902be91bbeee7 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 7 Oct 2025 12:23:21 +0200 Subject: [PATCH 4/7] improve --- .../tooling/muzzle/HelperReferenceWrapperTest.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java index 9ca87bda0e10..430af3adaf92 100644 --- a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java +++ b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java @@ -84,9 +84,7 @@ void shouldWrapHelperTypes() { assertThat(method.getDescriptor()).isEqualTo("()V"); }, atIndex(0)); - List helperFields = - helperWrapper.getFields().collect(Collectors.toList()); - assertThat(helperFields) + assertThat(helperWrapper.getFields()) .hasSize(1) .satisfies(field -> { assertThat(field.getName()).isEqualTo("declaredField"); @@ -101,9 +99,7 @@ void shouldWrapHelperTypes() { // baseHelper assertions HelperReferenceWrapper baseHelper = superTypes.get(0); assertThat(baseHelper.isAbstract()).isTrue(); - List baseHelperMethods = - baseHelper.getMethods().collect(Collectors.toList()); - assertThat(baseHelperMethods) + assertThat(baseHelper.getMethods().collect(Collectors.toList())) .hasSize(2) .satisfies(method -> { assertThat(method.isAbstract()).isFalse(); From 8b38ddab0c47adb37ba1b8a932fa3142a2b6cfa4 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 7 Oct 2025 12:43:46 +0200 Subject: [PATCH 5/7] improve --- .../muzzle/HelperReferenceWrapperTest.java | 177 ++++++++++-------- 1 file changed, 99 insertions(+), 78 deletions(-) diff --git a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java index 430af3adaf92..5c89c52107cd 100644 --- a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java +++ b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java @@ -78,89 +78,110 @@ void shouldWrapHelperTypes() { assertThat(helperWrapper.getMethods()) .hasSize(1) - .satisfies(method -> { - assertThat(method.isAbstract()).isFalse(); - assertThat(method.getName()).isEqualTo("bar"); - assertThat(method.getDescriptor()).isEqualTo("()V"); - }, atIndex(0)); + .satisfies( + method -> { + assertThat(method.isAbstract()).isFalse(); + assertThat(method.getName()).isEqualTo("bar"); + assertThat(method.getDescriptor()).isEqualTo("()V"); + }, + atIndex(0)); assertThat(helperWrapper.getFields()) .hasSize(1) - .satisfies(field -> { - assertThat(field.getName()).isEqualTo("declaredField"); - assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;"); - }, atIndex(0)); + .satisfies( + field -> { + assertThat(field.getName()).isEqualTo("declaredField"); + assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;"); + }, + atIndex(0)); assertThat(helperWrapper.hasSuperTypes()).isTrue(); - List superTypes = - helperWrapper.getSuperTypes().collect(Collectors.toList()); - assertThat(superTypes).hasSize(2); - - // baseHelper assertions - HelperReferenceWrapper baseHelper = superTypes.get(0); - assertThat(baseHelper.isAbstract()).isTrue(); - assertThat(baseHelper.getMethods().collect(Collectors.toList())) + assertThat(helperWrapper.getSuperTypes()) .hasSize(2) - .satisfies(method -> { - assertThat(method.isAbstract()).isFalse(); - assertThat(method.getName()).isEqualTo("foo"); - assertThat(method.getDescriptor()).isEqualTo("()V"); - }, atIndex(0)) - .satisfies(method -> { - assertThat(method.isAbstract()).isTrue(); - assertThat(method.getName()).isEqualTo("abstract"); - assertThat(method.getDescriptor()).isEqualTo("()I"); - }, atIndex(1)); - - assertThat(baseHelper.hasSuperTypes()).isTrue(); - List baseSuperTypes = - baseHelper.getSuperTypes().collect(Collectors.toList()); - assertThat(baseSuperTypes).hasSize(1); - HelperReferenceWrapper abstractClasspathType = baseSuperTypes.get(0); - assertThat(abstractClasspathType.isAbstract()).isTrue(); - assertThat(abstractClasspathType.getMethods().collect(Collectors.toList())).isEmpty(); - List abstractFields = - abstractClasspathType.getFields().collect(Collectors.toList()); - assertThat(abstractFields) - .hasSize(1) - .satisfies(field -> { - assertThat(field.getName()).isEqualTo("field"); - assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;"); - }, atIndex(0)); - - assertThat(abstractClasspathType.hasSuperTypes()).isTrue(); - List abstractSuperTypes = - abstractClasspathType.getSuperTypes().collect(Collectors.toList()); - assertThat(abstractSuperTypes).hasSize(2); - HelperReferenceWrapper objectType = abstractSuperTypes.get(0); - assertThat(objectType.hasSuperTypes()).isFalse(); - HelperReferenceWrapper interface1 = abstractSuperTypes.get(1); - assertThat(interface1.isAbstract()).isTrue(); - List interface1Methods = - interface1.getMethods().collect(Collectors.toList()); - assertThat(interface1Methods) - .hasSize(1) - .satisfies(method -> { - assertThat(method.isAbstract()).isTrue(); - assertThat(method.getName()).isEqualTo("foo"); - assertThat(method.getDescriptor()).isEqualTo("()V"); - }, atIndex(0)); - assertThat(interface1.hasSuperTypes()).isFalse(); - assertThat(interface1.getSuperTypes().collect(Collectors.toList())).isEmpty(); - - // interface2 assertions - HelperReferenceWrapper interface2 = superTypes.get(1); - assertThat(interface2.isAbstract()).isTrue(); - List interface2Methods = - interface2.getMethods().collect(Collectors.toList()); - assertThat(interface2Methods) - .hasSize(1) - .satisfies(method -> { - assertThat(method.isAbstract()).isTrue(); - assertThat(method.getName()).isEqualTo("bar"); - assertThat(method.getDescriptor()).isEqualTo("()V"); - }, atIndex(0)); - assertThat(interface2.hasSuperTypes()).isFalse(); - assertThat(interface2.getSuperTypes().collect(Collectors.toList())).isEmpty(); + .satisfies( + baseHelper -> { + assertThat(baseHelper.isAbstract()).isTrue(); + assertThat(baseHelper.getMethods().collect(Collectors.toList())) + .hasSize(2) + .satisfies( + method -> { + assertThat(method.isAbstract()).isFalse(); + assertThat(method.getName()).isEqualTo("foo"); + assertThat(method.getDescriptor()).isEqualTo("()V"); + }, + atIndex(0)) + .satisfies( + method -> { + assertThat(method.isAbstract()).isTrue(); + assertThat(method.getName()).isEqualTo("abstract"); + assertThat(method.getDescriptor()).isEqualTo("()I"); + }, + atIndex(1)); + + assertThat(baseHelper.hasSuperTypes()).isTrue(); + assertThat(baseHelper.getSuperTypes()) + .hasSize(1) + .satisfies( + abstractClasspathType -> { + assertThat(abstractClasspathType.isAbstract()).isTrue(); + assertThat(abstractClasspathType.getMethods()).isEmpty(); + + assertThat(abstractClasspathType.getFields()) + .hasSize(1) + .satisfies( + field -> { + assertThat(field.getName()).isEqualTo("field"); + assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;"); + }, + atIndex(0)); + + assertThat(abstractClasspathType.hasSuperTypes()).isTrue(); + assertThat(abstractClasspathType.getSuperTypes()) + .hasSize(2) + .satisfies( + wrapper -> assertThat(wrapper.hasSuperTypes()).isFalse(), + atIndex(0)) + .satisfies( + wrapper -> { + assertThat(wrapper.isAbstract()).isTrue(); + List interface1Methods = + wrapper.getMethods().collect(Collectors.toList()); + assertThat(interface1Methods) + .hasSize(1) + .satisfies( + method -> { + assertThat(method.isAbstract()).isTrue(); + assertThat(method.getName()).isEqualTo("foo"); + assertThat(method.getDescriptor()).isEqualTo("()V"); + }, + atIndex(0)); + assertThat(wrapper.hasSuperTypes()).isFalse(); + assertThat(wrapper.getSuperTypes().collect(Collectors.toList())) + .isEmpty(); + }, + atIndex(1)); + }, + atIndex(0)); + }, + atIndex(0)) + .satisfies( + interface2 -> { + // interface2 assertions + assertThat(interface2.isAbstract()).isTrue(); + List interface2Methods = + interface2.getMethods().collect(Collectors.toList()); + assertThat(interface2Methods) + .hasSize(1) + .satisfies( + method -> { + assertThat(method.isAbstract()).isTrue(); + assertThat(method.getName()).isEqualTo("bar"); + assertThat(method.getDescriptor()).isEqualTo("()V"); + }, + atIndex(0)); + assertThat(interface2.hasSuperTypes()).isFalse(); + assertThat(interface2.getSuperTypes().collect(Collectors.toList())).isEmpty(); + }, + atIndex(1)); } } From 8669bcc115f63b738e5bbcbf737bb80253492f79 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 7 Oct 2025 12:45:51 +0200 Subject: [PATCH 6/7] improve --- .../muzzle/HelperReferenceWrapperTest.java | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java index 5c89c52107cd..116e72253697 100644 --- a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java +++ b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java @@ -13,9 +13,7 @@ import io.opentelemetry.javaagent.tooling.muzzle.references.Flag.ManifestationFlag; import io.opentelemetry.javaagent.tooling.muzzle.references.Source; import java.util.HashMap; -import java.util.List; import java.util.Map; -import java.util.stream.Collectors; import muzzle.HelperReferenceWrapperTestClasses; import net.bytebuddy.pool.TypePool; import org.junit.jupiter.api.BeforeAll; @@ -73,7 +71,6 @@ void shouldWrapHelperTypes() { new HelperReferenceWrapper.Factory(typePool, references, helperClassPredicate) .create(helperClass); - // helperWrapper assertions assertThat(helperWrapper.isAbstract()).isFalse(); assertThat(helperWrapper.getMethods()) @@ -101,7 +98,7 @@ void shouldWrapHelperTypes() { .satisfies( baseHelper -> { assertThat(baseHelper.isAbstract()).isTrue(); - assertThat(baseHelper.getMethods().collect(Collectors.toList())) + assertThat(baseHelper.getMethods()) .hasSize(2) .satisfies( method -> { @@ -144,9 +141,7 @@ void shouldWrapHelperTypes() { .satisfies( wrapper -> { assertThat(wrapper.isAbstract()).isTrue(); - List interface1Methods = - wrapper.getMethods().collect(Collectors.toList()); - assertThat(interface1Methods) + assertThat(wrapper.getMethods()) .hasSize(1) .satisfies( method -> { @@ -156,8 +151,7 @@ void shouldWrapHelperTypes() { }, atIndex(0)); assertThat(wrapper.hasSuperTypes()).isFalse(); - assertThat(wrapper.getSuperTypes().collect(Collectors.toList())) - .isEmpty(); + assertThat(wrapper.getSuperTypes()).isEmpty(); }, atIndex(1)); }, @@ -166,11 +160,8 @@ void shouldWrapHelperTypes() { atIndex(0)) .satisfies( interface2 -> { - // interface2 assertions assertThat(interface2.isAbstract()).isTrue(); - List interface2Methods = - interface2.getMethods().collect(Collectors.toList()); - assertThat(interface2Methods) + assertThat(interface2.getMethods()) .hasSize(1) .satisfies( method -> { @@ -180,7 +171,7 @@ void shouldWrapHelperTypes() { }, atIndex(0)); assertThat(interface2.hasSuperTypes()).isFalse(); - assertThat(interface2.getSuperTypes().collect(Collectors.toList())).isEmpty(); + assertThat(interface2.getSuperTypes()).isEmpty(); }, atIndex(1)); } From 640c2f39beadd553529c0ffb7f0caa3502e9f221 Mon Sep 17 00:00:00 2001 From: Gregor Zeitlinger Date: Tue, 7 Oct 2025 12:52:25 +0200 Subject: [PATCH 7/7] improve --- .../muzzle/HelperReferenceWrapperTest.java | 85 +++++++------------ 1 file changed, 30 insertions(+), 55 deletions(-) diff --git a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java index 116e72253697..8518336e9d69 100644 --- a/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java +++ b/muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java @@ -6,7 +6,6 @@ package io.opentelemetry.javaagent.tooling.muzzle; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.atIndex; import io.opentelemetry.javaagent.tooling.muzzle.references.ClassRef; import io.opentelemetry.javaagent.tooling.muzzle.references.Flag; @@ -74,105 +73,81 @@ void shouldWrapHelperTypes() { assertThat(helperWrapper.isAbstract()).isFalse(); assertThat(helperWrapper.getMethods()) - .hasSize(1) - .satisfies( + .satisfiesExactly( method -> { assertThat(method.isAbstract()).isFalse(); assertThat(method.getName()).isEqualTo("bar"); assertThat(method.getDescriptor()).isEqualTo("()V"); - }, - atIndex(0)); + }); assertThat(helperWrapper.getFields()) - .hasSize(1) - .satisfies( + .satisfiesExactly( field -> { assertThat(field.getName()).isEqualTo("declaredField"); assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;"); - }, - atIndex(0)); + }); assertThat(helperWrapper.hasSuperTypes()).isTrue(); assertThat(helperWrapper.getSuperTypes()) - .hasSize(2) - .satisfies( + .satisfiesExactly( baseHelper -> { assertThat(baseHelper.isAbstract()).isTrue(); assertThat(baseHelper.getMethods()) - .hasSize(2) - .satisfies( + .satisfiesExactly( method -> { assertThat(method.isAbstract()).isFalse(); assertThat(method.getName()).isEqualTo("foo"); assertThat(method.getDescriptor()).isEqualTo("()V"); }, - atIndex(0)) - .satisfies( method -> { assertThat(method.isAbstract()).isTrue(); assertThat(method.getName()).isEqualTo("abstract"); assertThat(method.getDescriptor()).isEqualTo("()I"); - }, - atIndex(1)); + }); assertThat(baseHelper.hasSuperTypes()).isTrue(); assertThat(baseHelper.getSuperTypes()) - .hasSize(1) - .satisfies( - abstractClasspathType -> { - assertThat(abstractClasspathType.isAbstract()).isTrue(); - assertThat(abstractClasspathType.getMethods()).isEmpty(); - - assertThat(abstractClasspathType.getFields()) - .hasSize(1) - .satisfies( + .satisfiesExactly( + helperReferenceWrapper -> { + assertThat(helperReferenceWrapper.isAbstract()).isTrue(); + assertThat(helperReferenceWrapper.getMethods()).isEmpty(); + + assertThat(helperReferenceWrapper.getFields()) + .satisfiesExactly( field -> { assertThat(field.getName()).isEqualTo("field"); assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;"); - }, - atIndex(0)); + }); - assertThat(abstractClasspathType.hasSuperTypes()).isTrue(); - assertThat(abstractClasspathType.getSuperTypes()) - .hasSize(2) - .satisfies( + assertThat(helperReferenceWrapper.hasSuperTypes()).isTrue(); + assertThat(helperReferenceWrapper.getSuperTypes()) + .satisfiesExactly( wrapper -> assertThat(wrapper.hasSuperTypes()).isFalse(), - atIndex(0)) - .satisfies( wrapper -> { assertThat(wrapper.isAbstract()).isTrue(); assertThat(wrapper.getMethods()) - .hasSize(1) - .satisfies( + .satisfiesExactly( method -> { assertThat(method.isAbstract()).isTrue(); assertThat(method.getName()).isEqualTo("foo"); assertThat(method.getDescriptor()).isEqualTo("()V"); - }, - atIndex(0)); + }); assertThat(wrapper.hasSuperTypes()).isFalse(); assertThat(wrapper.getSuperTypes()).isEmpty(); - }, - atIndex(1)); - }, - atIndex(0)); + }); + }); }, - atIndex(0)) - .satisfies( - interface2 -> { - assertThat(interface2.isAbstract()).isTrue(); - assertThat(interface2.getMethods()) - .hasSize(1) - .satisfies( + wrapper -> { + assertThat(wrapper.isAbstract()).isTrue(); + assertThat(wrapper.getMethods()) + .satisfiesExactly( method -> { assertThat(method.isAbstract()).isTrue(); assertThat(method.getName()).isEqualTo("bar"); assertThat(method.getDescriptor()).isEqualTo("()V"); - }, - atIndex(0)); - assertThat(interface2.hasSuperTypes()).isFalse(); - assertThat(interface2.getSuperTypes()).isEmpty(); - }, - atIndex(1)); + }); + assertThat(wrapper.hasSuperTypes()).isFalse(); + assertThat(wrapper.getSuperTypes()).isEmpty(); + }); } }