Skip to content

Commit 8b38dda

Browse files
committed
improve
1 parent a65fdbf commit 8b38dda

File tree

1 file changed

+99
-78
lines changed

1 file changed

+99
-78
lines changed

muzzle/src/test/java/io/opentelemetry/javaagent/tooling/muzzle/HelperReferenceWrapperTest.java

Lines changed: 99 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -78,89 +78,110 @@ void shouldWrapHelperTypes() {
7878

7979
assertThat(helperWrapper.getMethods())
8080
.hasSize(1)
81-
.satisfies(method -> {
82-
assertThat(method.isAbstract()).isFalse();
83-
assertThat(method.getName()).isEqualTo("bar");
84-
assertThat(method.getDescriptor()).isEqualTo("()V");
85-
}, atIndex(0));
81+
.satisfies(
82+
method -> {
83+
assertThat(method.isAbstract()).isFalse();
84+
assertThat(method.getName()).isEqualTo("bar");
85+
assertThat(method.getDescriptor()).isEqualTo("()V");
86+
},
87+
atIndex(0));
8688

8789
assertThat(helperWrapper.getFields())
8890
.hasSize(1)
89-
.satisfies(field -> {
90-
assertThat(field.getName()).isEqualTo("declaredField");
91-
assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;");
92-
}, atIndex(0));
91+
.satisfies(
92+
field -> {
93+
assertThat(field.getName()).isEqualTo("declaredField");
94+
assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;");
95+
},
96+
atIndex(0));
9397

9498
assertThat(helperWrapper.hasSuperTypes()).isTrue();
95-
List<HelperReferenceWrapper> superTypes =
96-
helperWrapper.getSuperTypes().collect(Collectors.toList());
97-
assertThat(superTypes).hasSize(2);
98-
99-
// baseHelper assertions
100-
HelperReferenceWrapper baseHelper = superTypes.get(0);
101-
assertThat(baseHelper.isAbstract()).isTrue();
102-
assertThat(baseHelper.getMethods().collect(Collectors.toList()))
99+
assertThat(helperWrapper.getSuperTypes())
103100
.hasSize(2)
104-
.satisfies(method -> {
105-
assertThat(method.isAbstract()).isFalse();
106-
assertThat(method.getName()).isEqualTo("foo");
107-
assertThat(method.getDescriptor()).isEqualTo("()V");
108-
}, atIndex(0))
109-
.satisfies(method -> {
110-
assertThat(method.isAbstract()).isTrue();
111-
assertThat(method.getName()).isEqualTo("abstract");
112-
assertThat(method.getDescriptor()).isEqualTo("()I");
113-
}, atIndex(1));
114-
115-
assertThat(baseHelper.hasSuperTypes()).isTrue();
116-
List<HelperReferenceWrapper> baseSuperTypes =
117-
baseHelper.getSuperTypes().collect(Collectors.toList());
118-
assertThat(baseSuperTypes).hasSize(1);
119-
HelperReferenceWrapper abstractClasspathType = baseSuperTypes.get(0);
120-
assertThat(abstractClasspathType.isAbstract()).isTrue();
121-
assertThat(abstractClasspathType.getMethods().collect(Collectors.toList())).isEmpty();
122-
List<HelperReferenceWrapper.Field> abstractFields =
123-
abstractClasspathType.getFields().collect(Collectors.toList());
124-
assertThat(abstractFields)
125-
.hasSize(1)
126-
.satisfies(field -> {
127-
assertThat(field.getName()).isEqualTo("field");
128-
assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;");
129-
}, atIndex(0));
130-
131-
assertThat(abstractClasspathType.hasSuperTypes()).isTrue();
132-
List<HelperReferenceWrapper> abstractSuperTypes =
133-
abstractClasspathType.getSuperTypes().collect(Collectors.toList());
134-
assertThat(abstractSuperTypes).hasSize(2);
135-
HelperReferenceWrapper objectType = abstractSuperTypes.get(0);
136-
assertThat(objectType.hasSuperTypes()).isFalse();
137-
HelperReferenceWrapper interface1 = abstractSuperTypes.get(1);
138-
assertThat(interface1.isAbstract()).isTrue();
139-
List<HelperReferenceWrapper.Method> interface1Methods =
140-
interface1.getMethods().collect(Collectors.toList());
141-
assertThat(interface1Methods)
142-
.hasSize(1)
143-
.satisfies(method -> {
144-
assertThat(method.isAbstract()).isTrue();
145-
assertThat(method.getName()).isEqualTo("foo");
146-
assertThat(method.getDescriptor()).isEqualTo("()V");
147-
}, atIndex(0));
148-
assertThat(interface1.hasSuperTypes()).isFalse();
149-
assertThat(interface1.getSuperTypes().collect(Collectors.toList())).isEmpty();
150-
151-
// interface2 assertions
152-
HelperReferenceWrapper interface2 = superTypes.get(1);
153-
assertThat(interface2.isAbstract()).isTrue();
154-
List<HelperReferenceWrapper.Method> interface2Methods =
155-
interface2.getMethods().collect(Collectors.toList());
156-
assertThat(interface2Methods)
157-
.hasSize(1)
158-
.satisfies(method -> {
159-
assertThat(method.isAbstract()).isTrue();
160-
assertThat(method.getName()).isEqualTo("bar");
161-
assertThat(method.getDescriptor()).isEqualTo("()V");
162-
}, atIndex(0));
163-
assertThat(interface2.hasSuperTypes()).isFalse();
164-
assertThat(interface2.getSuperTypes().collect(Collectors.toList())).isEmpty();
101+
.satisfies(
102+
baseHelper -> {
103+
assertThat(baseHelper.isAbstract()).isTrue();
104+
assertThat(baseHelper.getMethods().collect(Collectors.toList()))
105+
.hasSize(2)
106+
.satisfies(
107+
method -> {
108+
assertThat(method.isAbstract()).isFalse();
109+
assertThat(method.getName()).isEqualTo("foo");
110+
assertThat(method.getDescriptor()).isEqualTo("()V");
111+
},
112+
atIndex(0))
113+
.satisfies(
114+
method -> {
115+
assertThat(method.isAbstract()).isTrue();
116+
assertThat(method.getName()).isEqualTo("abstract");
117+
assertThat(method.getDescriptor()).isEqualTo("()I");
118+
},
119+
atIndex(1));
120+
121+
assertThat(baseHelper.hasSuperTypes()).isTrue();
122+
assertThat(baseHelper.getSuperTypes())
123+
.hasSize(1)
124+
.satisfies(
125+
abstractClasspathType -> {
126+
assertThat(abstractClasspathType.isAbstract()).isTrue();
127+
assertThat(abstractClasspathType.getMethods()).isEmpty();
128+
129+
assertThat(abstractClasspathType.getFields())
130+
.hasSize(1)
131+
.satisfies(
132+
field -> {
133+
assertThat(field.getName()).isEqualTo("field");
134+
assertThat(field.getDescriptor()).isEqualTo("Ljava/lang/Object;");
135+
},
136+
atIndex(0));
137+
138+
assertThat(abstractClasspathType.hasSuperTypes()).isTrue();
139+
assertThat(abstractClasspathType.getSuperTypes())
140+
.hasSize(2)
141+
.satisfies(
142+
wrapper -> assertThat(wrapper.hasSuperTypes()).isFalse(),
143+
atIndex(0))
144+
.satisfies(
145+
wrapper -> {
146+
assertThat(wrapper.isAbstract()).isTrue();
147+
List<HelperReferenceWrapper.Method> interface1Methods =
148+
wrapper.getMethods().collect(Collectors.toList());
149+
assertThat(interface1Methods)
150+
.hasSize(1)
151+
.satisfies(
152+
method -> {
153+
assertThat(method.isAbstract()).isTrue();
154+
assertThat(method.getName()).isEqualTo("foo");
155+
assertThat(method.getDescriptor()).isEqualTo("()V");
156+
},
157+
atIndex(0));
158+
assertThat(wrapper.hasSuperTypes()).isFalse();
159+
assertThat(wrapper.getSuperTypes().collect(Collectors.toList()))
160+
.isEmpty();
161+
},
162+
atIndex(1));
163+
},
164+
atIndex(0));
165+
},
166+
atIndex(0))
167+
.satisfies(
168+
interface2 -> {
169+
// interface2 assertions
170+
assertThat(interface2.isAbstract()).isTrue();
171+
List<HelperReferenceWrapper.Method> interface2Methods =
172+
interface2.getMethods().collect(Collectors.toList());
173+
assertThat(interface2Methods)
174+
.hasSize(1)
175+
.satisfies(
176+
method -> {
177+
assertThat(method.isAbstract()).isTrue();
178+
assertThat(method.getName()).isEqualTo("bar");
179+
assertThat(method.getDescriptor()).isEqualTo("()V");
180+
},
181+
atIndex(0));
182+
assertThat(interface2.hasSuperTypes()).isFalse();
183+
assertThat(interface2.getSuperTypes().collect(Collectors.toList())).isEmpty();
184+
},
185+
atIndex(1));
165186
}
166187
}

0 commit comments

Comments
 (0)