Skip to content

Commit 3d28286

Browse files
committed
Merge branch 'test-code-can-use-java-11-features' into 'master'
Use Java 11 features when it makes the code better See merge request asm/asm!385
2 parents 4d58008 + 90e3ded commit 3d28286

File tree

20 files changed

+127
-147
lines changed

20 files changed

+127
-147
lines changed

asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/AnalyzerWithBasicInterpreterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,13 +102,13 @@ protected Frame<BasicValue> newFrame(final Frame<? extends BasicValue> src) {
102102
}
103103
};
104104

105-
ArrayList<Frame<? extends BasicValue>[]> methodFrames = new ArrayList<>();
105+
ArrayList<Frame<BasicValue>[]> methodFrames = new ArrayList<>();
106106
for (MethodNode methodNode : classNode.methods) {
107107
methodFrames.add(analyzer.analyze(classNode.name, methodNode));
108108
}
109109

110-
for (Frame<? extends BasicValue>[] frames : methodFrames) {
111-
for (Frame<? extends BasicValue> frame : frames) {
110+
for (Frame<BasicValue>[] frames : methodFrames) {
111+
for (Frame<BasicValue> frame : frames) {
112112
assertTrue(frame == null || frame instanceof CustomFrame);
113113
}
114114
}

asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SimpleVerifierTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
import static org.junit.jupiter.api.Assertions.assertThrows;
3434
import static org.junit.jupiter.api.Assertions.assertTrue;
3535

36-
import java.util.Arrays;
36+
import java.util.List;
3737
import org.junit.jupiter.api.Test;
3838
import org.junit.jupiter.params.ParameterizedTest;
3939
import org.junit.jupiter.params.provider.CsvSource;
@@ -85,7 +85,7 @@ void testIsAssignableFrom_subclassWithInterfaces() {
8585
/* latest */ Opcodes.ASM10_EXPERIMENTAL,
8686
baseType,
8787
superType,
88-
Arrays.asList(interfaceType),
88+
List.of(interfaceType),
8989
false) {
9090

9191
@Override

asm-analysis/src/test/java/org/objectweb/asm/tree/analysis/SmallSetTest.java

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
import static org.junit.jupiter.api.Assertions.assertThrows;
3333
import static org.junit.jupiter.api.Assertions.assertTrue;
3434

35-
import java.util.Arrays;
36-
import java.util.HashSet;
3735
import java.util.Iterator;
3836
import java.util.NoSuchElementException;
3937
import java.util.Set;
@@ -73,7 +71,7 @@ void testUnion_oneElement_oneElement() {
7371
Set<Object> union2 = set2.union(set1);
7472

7573
assertEquals(union1, union2);
76-
assertEquals(union1, new HashSet<Object>(Arrays.asList(ELEMENT1)));
74+
assertEquals(union1, Set.of(ELEMENT1));
7775
}
7876

7977
@Test
@@ -85,7 +83,7 @@ void testUnion_oneElement_twoElements_superSet() {
8583
Set<Object> union2 = set2.union(set1);
8684

8785
assertEquals(union1, union2);
88-
assertEquals(union1, new HashSet<Object>(Arrays.asList(ELEMENT1, ELEMENT2)));
86+
assertEquals(union1, Set.of(ELEMENT1, ELEMENT2));
8987
}
9088

9189
@Test
@@ -97,7 +95,7 @@ void testUnion_twoElements_twoElements_equalSets() {
9795
Set<Object> union2 = set2.union(set1);
9896

9997
assertEquals(union1, union2);
100-
assertEquals(union1, new HashSet<Object>(Arrays.asList(ELEMENT1, ELEMENT2)));
98+
assertEquals(union1, Set.of(ELEMENT1, ELEMENT2));
10199
}
102100

103101
@Test
@@ -109,7 +107,7 @@ void testUnion_twoElements_oneElement_distinctSets() {
109107
Set<Object> union2 = set2.union(set1);
110108

111109
assertEquals(union1, union2);
112-
assertEquals(union1, new HashSet<Object>(Arrays.asList(ELEMENT1, ELEMENT2, ELEMENT3)));
110+
assertEquals(union1, Set.of(ELEMENT1, ELEMENT2, ELEMENT3));
113111
}
114112

115113
@Test
@@ -121,8 +119,7 @@ void testUnion_twoElements_twoElements_distincSets() {
121119
Set<Object> union2 = set2.union(set1);
122120

123121
assertEquals(union1, union2);
124-
assertEquals(
125-
union1, new HashSet<Object>(Arrays.asList(ELEMENT1, ELEMENT2, ELEMENT3, ELEMENT4)));
122+
assertEquals(union1, Set.of(ELEMENT1, ELEMENT2, ELEMENT3, ELEMENT4));
126123
}
127124

128125
@Test
@@ -166,6 +163,6 @@ void testIterator_remove() {
166163
}
167164

168165
private static SmallSet<Object> newSmallSet(final Object element1, final Object element2) {
169-
return (SmallSet<Object>) new SmallSet<Object>(element1).union(new SmallSet<Object>(element2));
166+
return (SmallSet<Object>) new SmallSet<>(element1).union(new SmallSet<>(element2));
170167
}
171168
}

asm-commons/src/test/java/org/objectweb/asm/commons/ClassRemapperTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,7 @@ public String mapModuleName(final String name) {
189189
});
190190
classRemapper.visit(Opcodes.V1_5, Opcodes.ACC_PUBLIC, "C", null, "java/lang/Object", null);
191191

192+
// The ClassRemapper change the modules and the hashes so the lists have to be mutable.
192193
classRemapper.visitAttribute(
193194
new ModuleHashesAttribute("algorithm", Arrays.asList("pkg.C"), Arrays.asList(new byte[0])));
194195

asm-commons/src/test/java/org/objectweb/asm/commons/GeneratorAdapterTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
import static org.objectweb.asm.commons.GeneratorAdapter.LT;
3838
import static org.objectweb.asm.commons.GeneratorAdapter.NE;
3939

40-
import java.util.Arrays;
40+
import java.util.List;
4141
import java.util.stream.Collectors;
4242
import org.junit.jupiter.api.Test;
4343
import org.junit.jupiter.api.function.Executable;
@@ -109,7 +109,7 @@ void testConstructor_withClassVisitorAndExceptions() {
109109
assertEquals(Opcodes.ACC_PUBLIC, methodNode.access);
110110
assertEquals("name", methodNode.name);
111111
assertEquals("()V", methodNode.desc);
112-
assertEquals(Arrays.asList("java/lang/Exception"), methodNode.exceptions);
112+
assertEquals(List.of("java/lang/Exception"), methodNode.exceptions);
113113
}
114114

115115
@Test
@@ -127,7 +127,7 @@ void testConstructor_withClassVisitorAndNoExceptions() {
127127
assertEquals(Opcodes.ACC_PUBLIC, methodNode.access);
128128
assertEquals("name", methodNode.name);
129129
assertEquals("()V", methodNode.desc);
130-
assertEquals(Arrays.asList(), methodNode.exceptions);
130+
assertEquals(List.of(), methodNode.exceptions);
131131
}
132132

133133
@Test

asm-commons/src/test/java/org/objectweb/asm/commons/ModuleHashesAttributeTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
3131
import static org.junit.jupiter.api.Assertions.assertEquals;
3232

33-
import java.util.Arrays;
33+
import java.util.List;
3434
import org.junit.jupiter.api.Test;
3535
import org.objectweb.asm.Attribute;
3636
import org.objectweb.asm.ClassReader;
@@ -53,9 +53,7 @@ void testWriteAndRead() {
5353
ClassWriter classWriter = new ClassWriter(0);
5454
classWriter.visitAttribute(
5555
new ModuleHashesAttribute(
56-
"algorithm",
57-
Arrays.asList(new String[] {"module1", "module2"}),
58-
Arrays.asList(new byte[][] {HASH1, HASH2})));
56+
"algorithm", List.of("module1", "module2"), List.of(HASH1, HASH2)));
5957

6058
ModuleHashesAttribute moduleHashesAttribute = new ModuleHashesAttribute();
6159
new ClassReader(classWriter.toByteArray())

asm-commons/src/test/java/org/objectweb/asm/commons/SimpleRemapperTest.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929

3030
import static org.junit.jupiter.api.Assertions.assertEquals;
3131

32-
import java.util.Collections;
33-
import java.util.HashMap;
3432
import java.util.Map;
3533
import org.junit.jupiter.api.Test;
3634

@@ -44,7 +42,7 @@ class SimpleRemapperTest {
4442
@Test
4543
void testMapSignature_remapParentOnly_nestedClassExtends() {
4644
String inputSignature = "LOuter<Ljava/lang/Object;>.Inner;";
47-
Remapper remapper = new SimpleRemapper(Collections.singletonMap("Outer", "RenamedOuter"));
45+
Remapper remapper = new SimpleRemapper(Map.of("Outer", "RenamedOuter"));
4846

4947
String remappedSignature = remapper.mapSignature(inputSignature, false);
5048

@@ -54,8 +52,7 @@ void testMapSignature_remapParentOnly_nestedClassExtends() {
5452
@Test
5553
void testMapSignature_remapChildOnly_nestedClassExtends() {
5654
String inputSignature = "LOuter<Ljava/lang/Object;>.Inner;";
57-
Remapper remapper =
58-
new SimpleRemapper(Collections.singletonMap("Outer$Inner", "Outer$RenamedInner"));
55+
Remapper remapper = new SimpleRemapper(Map.of("Outer$Inner", "Outer$RenamedInner"));
5956

6057
String remappedSignature = remapper.mapSignature(inputSignature, false);
6158

@@ -65,8 +62,7 @@ void testMapSignature_remapChildOnly_nestedClassExtends() {
6562
@Test
6663
void testMapSignature_remapChildOnly_nestedClassExtends_identifiersWithDollarSign() {
6764
String inputSignature = "LOuter<Ljava/lang/Object;>.Inner$1;";
68-
Remapper remapper =
69-
new SimpleRemapper(Collections.singletonMap("Outer$Inner$1", "Outer$RenamedInner$1"));
65+
Remapper remapper = new SimpleRemapper(Map.of("Outer$Inner$1", "Outer$RenamedInner$1"));
7066

7167
String remappedSignature = remapper.mapSignature(inputSignature, false);
7268

@@ -76,9 +72,8 @@ void testMapSignature_remapChildOnly_nestedClassExtends_identifiersWithDollarSig
7672
@Test
7773
void testMapSignature_remapBothParentAndChild_nestedClassExtends() {
7874
String inputSignature = "LOuter<Ljava/lang/Object;>.Inner;";
79-
Map<String, String> mapping = new HashMap<>();
80-
mapping.put("Outer", "RenamedOuter");
81-
mapping.put("Outer$Inner", "RenamedOuter$RenamedInner");
75+
Map<String, String> mapping =
76+
Map.of("Outer", "RenamedOuter", "Outer$Inner", "RenamedOuter$RenamedInner");
8277
Remapper remapper = new SimpleRemapper(mapping);
8378

8479
String remappedSignature = remapper.mapSignature(inputSignature, false);

asm-test/src/test/java/org/objectweb/asm/test/AsmTestTest.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@
3232
import static org.junit.jupiter.api.Assertions.assertNotNull;
3333
import static org.junit.jupiter.api.Assertions.assertTrue;
3434

35-
import java.util.Arrays;
36-
import java.util.HashSet;
3735
import java.util.List;
36+
import java.util.Set;
3837
import java.util.stream.Collectors;
3938
import org.junit.jupiter.api.Test;
4039
import org.junit.jupiter.params.provider.Arguments;
@@ -89,10 +88,10 @@ void testGetAllClassesAndAllApis() {
8988
List<Arguments> allArguments = allClassesAndAllApis().collect(Collectors.toList());
9089

9190
assertEquals(
92-
new HashSet<Object>(Arrays.asList(PrecompiledClass.values())),
91+
Set.of(PrecompiledClass.values()),
9392
allArguments.stream().map(arg -> arg.get()[0]).collect(Collectors.toSet()));
9493
assertEquals(
95-
new HashSet<Object>(Arrays.asList(Api.values())),
94+
Set.of(Api.values()),
9695
allArguments.stream().map(arg -> arg.get()[1]).collect(Collectors.toSet()));
9796
}
9897

@@ -101,10 +100,10 @@ void testGetAllClassesAndLatestApi() {
101100
List<Arguments> allArguments = allClassesAndLatestApi().collect(Collectors.toList());
102101

103102
assertEquals(
104-
new HashSet<Object>(Arrays.asList(PrecompiledClass.values())),
103+
Set.of(PrecompiledClass.values()),
105104
allArguments.stream().map(arg -> arg.get()[0]).collect(Collectors.toSet()));
106105
assertEquals(
107-
new HashSet<Object>(Arrays.asList(Api.ASM9)),
106+
Set.of(Api.ASM9),
108107
allArguments.stream().map(arg -> arg.get()[1]).collect(Collectors.toSet()));
109108
}
110109
}

asm-tree/src/test/java/org/objectweb/asm/tree/AnnotationNodeTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import static org.junit.jupiter.api.Assertions.assertNull;
3232
import static org.junit.jupiter.api.Assertions.assertThrows;
3333

34-
import java.util.Arrays;
34+
import java.util.List;
3535
import org.junit.jupiter.api.Test;
3636
import org.junit.jupiter.api.function.Executable;
3737
import org.objectweb.asm.AnnotationVisitor;
@@ -75,21 +75,21 @@ void testVisit() {
7575
annotationNode.visitAnnotation("annotation", "Lpkg/Annotation;");
7676

7777
assertEquals("bytes", annotationNode.values.get(0));
78-
assertEquals(Arrays.asList(new Byte[] {0, 1}), annotationNode.values.get(1));
78+
assertEquals(List.of((byte) 0, (byte) 1), annotationNode.values.get(1));
7979
assertEquals("booleans", annotationNode.values.get(2));
80-
assertEquals(Arrays.asList(new Boolean[] {false, true}), annotationNode.values.get(3));
80+
assertEquals(List.of(false, true), annotationNode.values.get(3));
8181
assertEquals("shorts", annotationNode.values.get(4));
82-
assertEquals(Arrays.asList(new Short[] {0, 1}), annotationNode.values.get(5));
82+
assertEquals(List.of((short) 0, (short) 1), annotationNode.values.get(5));
8383
assertEquals("chars", annotationNode.values.get(6));
84-
assertEquals(Arrays.asList(new Character[] {'0', '1'}), annotationNode.values.get(7));
84+
assertEquals(List.of('0', '1'), annotationNode.values.get(7));
8585
assertEquals("ints", annotationNode.values.get(8));
86-
assertEquals(Arrays.asList(new Integer[] {0, 1}), annotationNode.values.get(9));
86+
assertEquals(List.of(0, 1), annotationNode.values.get(9));
8787
assertEquals("longs", annotationNode.values.get(10));
88-
assertEquals(Arrays.asList(new Long[] {0L, 1L}), annotationNode.values.get(11));
88+
assertEquals(List.of(0L, 1L), annotationNode.values.get(11));
8989
assertEquals("floats", annotationNode.values.get(12));
90-
assertEquals(Arrays.asList(new Float[] {0.0f, 1.0f}), annotationNode.values.get(13));
90+
assertEquals(List.of(0.0f, 1.0f), annotationNode.values.get(13));
9191
assertEquals("doubles", annotationNode.values.get(14));
92-
assertEquals(Arrays.asList(new Double[] {0.0, 1.0}), annotationNode.values.get(15));
92+
assertEquals(List.of(0.0, 1.0), annotationNode.values.get(15));
9393
assertEquals("string", annotationNode.values.get(16));
9494
assertEquals("value", annotationNode.values.get(17));
9595
assertEquals("annotation", annotationNode.values.get(18));

asm-tree/src/test/java/org/objectweb/asm/tree/FrameNodeTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import static org.junit.jupiter.api.Assertions.assertEquals;
3131
import static org.junit.jupiter.api.Assertions.assertThrows;
3232

33-
import java.util.Arrays;
33+
import java.util.List;
3434
import org.junit.jupiter.api.Test;
3535
import org.junit.jupiter.api.function.Executable;
3636
import org.objectweb.asm.Opcodes;
@@ -52,8 +52,8 @@ void testConstructor() {
5252

5353
assertEquals(AbstractInsnNode.FRAME, frameNode.getType());
5454
assertEquals(Opcodes.F_FULL, frameNode.type);
55-
assertEquals(Arrays.asList(locals), frameNode.local);
56-
assertEquals(Arrays.asList(stack), frameNode.stack);
55+
assertEquals(List.of(locals), frameNode.local);
56+
assertEquals(List.of(stack), frameNode.stack);
5757
}
5858

5959
@Test

0 commit comments

Comments
 (0)