1919package groovy.util
2020
2121import org.codehaus.groovy.runtime.ProxyGeneratorAdapter
22+ import org.junit.jupiter.api.Test
2223
2324import static groovy.test.GroovyAssert.assertScript
2425
2526class ProxyGeneratorAdapterTest {
27+ @Test
2628 void testShouldCreateProxy () {
2729 def map = [' toString' : { ' HELLO' }]
2830 ProxyGeneratorAdapter adapter = new ProxyGeneratorAdapter (map, Object , null , this . class. classLoader, false , null )
@@ -31,11 +33,13 @@ class ProxyGeneratorAdapterTest {
3133 assert obj. toString() == ' HELLO'
3234 }
3335
36+ @Test
3437 void testShouldCreateProxyWithArrayDelegate () {
3538 def adapter = new ProxyGeneratorAdapter ([:], Map $Entry , [Map $Entry ] as Class [], null , false , String [])
3639 assert adapter. proxyName() =~ / String_array\d +_groovyProxy/
3740 }
3841
42+ @Test
3943 void testImplementSingleAbstractMethod () {
4044 def map = [' m' : { ' HELLO' }]
4145 ProxyGeneratorAdapter adapter = new ProxyGeneratorAdapter (map, Foo , null , this . class. classLoader, false , null )
@@ -45,6 +49,7 @@ class ProxyGeneratorAdapterTest {
4549 assert obj. m() == ' HELLO'
4650 }
4751
52+ @Test
4853 void testImplementSingleAbstractMethodReturningVoid () {
4954 def map = [' bar' : { println ' HELLO' }]
5055 ProxyGeneratorAdapter adapter = new ProxyGeneratorAdapter (map, Bar , null , this . class. classLoader, false , null )
@@ -54,6 +59,7 @@ class ProxyGeneratorAdapterTest {
5459 obj. bar()
5560 }
5661
62+ @Test
5763 void testImplementSingleAbstractMethodReturningVoidAndSharedVariable () {
5864 def x = null
5965 def map = [' bar' : { x = ' HELLO' }]
@@ -66,6 +72,7 @@ class ProxyGeneratorAdapterTest {
6672 assert x == ' HELLO'
6773 }
6874
75+ @Test
6976 void testImplementMethodFromInterface () {
7077 def map = [' foo' : { ' HELLO' }]
7178 ProxyGeneratorAdapter adapter = new ProxyGeneratorAdapter (map, Object , [FooInterface ] as Class [], this . class. classLoader, false , null )
@@ -75,6 +82,7 @@ class ProxyGeneratorAdapterTest {
7582 assert obj. foo() == ' HELLO'
7683 }
7784
85+ @Test
7886 void testImplementMethodFromInterfaceUsingInterfaceAsSuperClass () {
7987 def map = [' foo' : { ' HELLO' }]
8088 ProxyGeneratorAdapter adapter = new ProxyGeneratorAdapter (map, FooInterface , null , this . class. classLoader, false , null )
@@ -84,6 +92,7 @@ class ProxyGeneratorAdapterTest {
8492 assert obj. foo() == ' HELLO'
8593 }
8694
95+ @Test
8796 void testImplementMethodFromInterfaceAndSuperClass () {
8897 def x = null
8998 def map = [' foo' : { ' HELLO' }, ' bar' : { x= ' WORLD' } ]
@@ -98,6 +107,7 @@ class ProxyGeneratorAdapterTest {
98107 assert x == ' WORLD'
99108 }
100109
110+ @Test
101111 void testImplementMethodFromInterfaceWithPrimitiveTypes () {
102112 def map = [' calc' : { x -> x* 2 } ]
103113 ProxyGeneratorAdapter adapter = new ProxyGeneratorAdapter (map, Bar , [OtherInterface ] as Class [], this . class. classLoader, false , null )
@@ -107,6 +117,7 @@ class ProxyGeneratorAdapterTest {
107117 assert obj. calc(3 ) == 6
108118 }
109119
120+ @Test
110121 void testWildcardProxy () {
111122 def map = [' *' : { ' 1' } ]
112123 ProxyGeneratorAdapter adapter = new ProxyGeneratorAdapter (map, Foo , null , this . class. classLoader, false , null )
@@ -116,6 +127,7 @@ class ProxyGeneratorAdapterTest {
116127 assert obj. m() == ' 1'
117128 }
118129
130+ @Test
119131 void testDelegatingProxy () {
120132 assertScript '''
121133 public abstract class A { abstract protected String doIt() }
@@ -131,6 +143,7 @@ class ProxyGeneratorAdapterTest {
131143 }
132144
133145 // GROOVY-5925
146+ @Test
134147 void testProxyForLongConstructor () {
135148
136149 def map = [nextInt : { x -> return 0 }]
@@ -142,6 +155,7 @@ class ProxyGeneratorAdapterTest {
142155 assert proxy. nextInt() == 0
143156 }
144157
158+ @Test
145159 void testProxyForDoubleConstructor () {
146160 assertScript '''
147161 public class A {
@@ -162,6 +176,7 @@ class ProxyGeneratorAdapterTest {
162176 }
163177
164178 // GROOVY-7146
179+ @Test
165180 void testShouldNotThrowVerifyErrorBecauseOfStackSize () {
166181 assertScript '''
167182 interface DoStuff {
@@ -178,6 +193,7 @@ class ProxyGeneratorAdapterTest {
178193 static trait Trait1 { def method1 () { ' Trait1 method' } }
179194
180195 // GROOVY-7443
196+ @Test
181197 void testTraitFromDifferentClassloader () {
182198 def aWith1 = new ClassA (). withTraits(Trait1 )
183199 assert aWith1. method1() == ' Trait1 method'
@@ -192,6 +208,7 @@ class ProxyGeneratorAdapterTest {
192208 assert aWith2. method2() == ' Trait2 method'
193209 }
194210
211+ @Test
195212 void testGetTypeArgsRegisterLength () {
196213 def types = { list -> list as org.objectweb.asm.Type [] }
197214 def proxyGeneratorAdapter = new ProxyGeneratorAdapter ([:], Object , [] as Class [], null , false , Object )
0 commit comments