@@ -20,6 +20,8 @@ package org.codehaus.groovy.classgen.asm.sc
2020
2121import groovy.transform.stc.ArraysAndCollectionsSTCTest
2222import org.junit.jupiter.api.Test
23+ import org.junit.jupiter.params.ParameterizedTest
24+ import org.junit.jupiter.params.provider.ValueSource
2325
2426/**
2527 * Unit tests for static compilation : arrays and collections.
@@ -98,8 +100,7 @@ final class ArraysAndCollectionsStaticCompileTest extends ArraysAndCollectionsST
98100 assert astTrees[' Foo' ][1 ]. count(' DefaultGroovyMethods.toList' ) == 1
99101 }
100102
101- @Override
102- @Test
103+ @Override @Test
103104 void testMultiDimensionalArray4 () {
104105 super . testMultiDimensionalArray4()
105106 String script = astTrees. values()[0 ][1 ]
@@ -109,50 +110,48 @@ final class ArraysAndCollectionsStaticCompileTest extends ArraysAndCollectionsST
109110 }
110111
111112 // GROOVY-11309
112- @Test
113- void testListLiteralToSetAssignmentSC () {
114- for (t in [' LinkedHashSet' ,' HashSet' ,' Set' ]) {
115- astTrees. clear()
116- assertScript """
117- $t <String> set = []
118- assert set.isEmpty()
119- assert set.size() == 0
120- assert set instanceof LinkedHashSet
121- """
122- String script = astTrees. values()[0 ][1 ]
123- assert script. contains(' LinkedHashSet.<init> ()V' )
124- assert ! script. contains(' ScriptBytecodeAdapter.createList' )
125- }
113+ @ParameterizedTest
114+ @ValueSource (strings = [' LinkedHashSet' ,' HashSet' ,' Set' ])
115+ void testListLiteralToSetAssignmentSC (String t ) {
116+ assertScript """
117+ $t <String> set = []
118+ assert set.isEmpty()
119+ assert set.size() == 0
120+ assert set instanceof LinkedHashSet
121+ """
122+ String script = astTrees. values()[0 ][1 ]
123+ assert script. contains(' LinkedHashSet.<init> ()V' )
124+ assert ! script. contains(' ScriptBytecodeAdapter.createList' )
126125 }
127126
128127 // GROOVY-11309
129- @Test
130- void testListLiteralToListAssignmentSC () {
131- for (t in [' ArrayList' ,' List' ,' Collection' ,' Iterable' ]) {
132- astTrees. clear()
133- assertScript """
134- $t <String> list = []
135- assert list.isEmpty()
136- assert list.size() == 0
137- assert list instanceof ArrayList
138- """
139- String script = astTrees. values()[0 ][1 ]
140- assert script. contains(' ArrayList.<init> ()V' )
141- assert ! script. contains(' ScriptBytecodeAdapter.createList' )
142- }
128+ @ParameterizedTest
129+ @ValueSource (strings = [' ArrayList' ,' List' ,' Collection' ,' Iterable' ])
130+ void testListLiteralToListAssignmentSC (String t ) {
131+ assertScript """
132+ $t <String> list = []
133+ assert list.isEmpty()
134+ assert list.size() == 0
135+ assert list instanceof ArrayList
136+ """
137+ String script = astTrees. values()[0 ][1 ]
138+ assert script. contains(' ArrayList.<init> ()V' )
139+ assert ! script. contains(' ScriptBytecodeAdapter.createList' )
140+ }
143141
144- for (t in [' Object' ,' Cloneable' ,' Serializable' ,' RandomAccess' ]) {
145- astTrees. clear()
146- assertScript """
147- $t list = []
148- assert list.isEmpty()
149- assert list.size() == 0
150- assert list instanceof ArrayList
151- """
152- String script = astTrees. values()[0 ][1 ]
153- assert script. contains(' ArrayList.<init> ()V' )
154- assert ! script. contains(' ScriptBytecodeAdapter.createList' )
155- }
142+ // GROOVY-11309
143+ @ParameterizedTest
144+ @ValueSource (strings = [' Object' ,' Cloneable' ,' Serializable' ,' RandomAccess' ])
145+ void testListLiteralToOtherAssignmentSC (String t ) {
146+ assertScript """
147+ $t list = []
148+ assert list.isEmpty()
149+ assert list.size() == 0
150+ assert list instanceof ArrayList
151+ """
152+ String script = astTrees. values()[0 ][1 ]
153+ assert script. contains(' ArrayList.<init> ()V' )
154+ assert ! script. contains(' ScriptBytecodeAdapter.createList' )
156155 }
157156
158157 // GROOVY-10029
0 commit comments