This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 40095eca7e minor items
40095eca7e is described below
commit 40095eca7eb399be342339c84eea9abe9d798430
Author: Eric Milles <[email protected]>
AuthorDate: Sun Mar 16 15:58:22 2025 -0500
minor items
---
.../codehaus/groovy/control/ResolveVisitor.java | 22 ++-
.../groovy/transform/traitx/Groovy10218.groovy | 3 +-
.../groovy/transform/traitx/Groovy11508.groovy | 3 +-
.../groovy/transform/traitx/Groovy6697Bug.groovy | 153 -----------------
.../transform/traitx/Groovy7196SupportTrait.groovy | 3 +
.../traitx/Groovy7196SupportTraitImpl.groovy | 22 ---
.../groovy/transform/traitx/Groovy7215Bug.groovy | 47 ------
.../transform/traitx/Groovy7215SupportTrait.groovy | 13 +-
.../groovy/transform/traitx/Groovy7285Bug.groovy | 64 -------
.../groovy/transform/traitx/Groovy7926.groovy | 56 -------
.../groovy/transform/traitx/Groovy_6697.groovy | 183 +++++++++++++++++++++
.../{Groovy6736Bug.groovy => Groovy_6736.groovy} | 25 +--
.../{Groovy6741Bug.groovy => Groovy_6741.groovy} | 10 +-
.../{Groovy7011Bug.groovy => Groovy_7011.groovy} | 13 +-
.../{Groovy7190Bug.groovy => Groovy_7190.groovy} | 12 +-
.../{Groovy7196Bug.groovy => Groovy_7196.groovy} | 15 +-
.../{Groovy7206Bug.groovy => Groovy_7206.groovy} | 38 +++--
.../groovy/transform/traitx/Groovy_7215.groovy | 59 +++++++
.../{Groovy7217Bug.groovy => Groovy_7217.groovy} | 14 +-
.../{Groovy7269Bug.groovy => Groovy_7269.groovy} | 36 ++--
.../{Groovy7275Bug.groovy => Groovy_7275.groovy} | 46 +++---
.../groovy/transform/traitx/Groovy_7285.groovy | 66 ++++++++
.../{Groovy7456Bug.groovy => Groovy_7456.groovy} | 11 +-
.../{Groovy7500.groovy => Groovy_7500.groovy} | 4 +-
.../{Groovy7846Bug.groovy => Groovy_7846.groovy} | 20 +--
.../groovy/transform/traitx/Groovy_7926.groovy | 84 ++++++++++
.../{Groovy8864.groovy => Groovy_8864.groovy} | 7 +-
.../groovy/transform/traitx/TestTrait2.groovy | 10 +-
.../traitx/TraitASTTransformationTest.groovy | 6 +-
.../traitx/TraitWithClosureOrLambda.groovy | 2 +-
.../codehaus/groovy/util/HashCodeHelperTest.groovy | 5 +-
.../codehaus/groovy/util/ListHashMapTest.groovy | 22 ++-
.../util/ManagedConcurrentLinkedQueueTest.groovy | 24 ++-
.../util/ManagedConcurrentValueMapTest.groovy | 7 +-
.../groovy/util/ReferenceManagerTest.groovy | 21 ++-
.../v8/InterfaceStaticMethodCallTest.groovy | 9 +-
.../v8/PluginDefaultGroovyMethodsSCTest.groovy | 26 ---
.../v8/PluginDefaultGroovyMethodsTest.groovy | 54 ++++--
.../groovy/vmplugin/v9/ClassFinderTest.groovy | 72 ++++----
39 files changed, 711 insertions(+), 576 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
index 9921c0b40c..bd621a126a 100644
--- a/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
+++ b/src/main/java/org/codehaus/groovy/control/ResolveVisitor.java
@@ -273,7 +273,8 @@ public class ResolveVisitor extends
ClassCodeExpressionTransformer {
}
if (!fieldTypesChecked.contains(node)) {
- resolveOrFail(node.getType(), node);
+ ClassNode t = node.getOriginType();
+ resolveOrFail(t, t);
}
super.visitField(node);
@@ -287,7 +288,8 @@ public class ResolveVisitor extends
ClassCodeExpressionTransformer {
genericParameterNames = Collections.emptyMap();
}
- resolveOrFail(node.getType(), node);
+ ClassNode t = node.getOriginType();
+ resolveOrFail(t, t);
fieldTypesChecked.add(node.getField());
super.visitProperty(node);
@@ -310,10 +312,13 @@ public class ResolveVisitor extends
ClassCodeExpressionTransformer {
resolveGenericsHeader(node.getGenericsTypes());
- resolveOrFail(node.getReturnType(), node);
+ {
+ ClassNode t = node.getReturnType();
+ resolveOrFail(t, t);
+ }
for (Parameter p : node.getParameters()) {
p.setInitialExpression(transform(p.getInitialExpression()));
- ClassNode t = p.getType();
+ ClassNode t = p.getOriginType();
resolveOrFail(t, t);
visitAnnotations(p);
}
@@ -848,7 +853,7 @@ public class ResolveVisitor extends
ClassCodeExpressionTransformer {
String property = ((PropertyExpression)
expr).getPropertyAsString();
// the class property stops resolving, dynamic property names too
- if (property == null || "class".equals(property)) {
+ if (property == null || property.equals("class")) {
return null;
}
Tuple2<StringBuilder, Boolean> classNameInfo =
makeClassName(doInitialClassTest, name, property);
@@ -898,7 +903,7 @@ public class ResolveVisitor extends
ClassCodeExpressionTransformer {
String propertyName = classProperty.getPropertyAsString();
// if it's "Type.foo.bar" or something else return PropertyExpression
- if (propertyName == null || !"class".equals(propertyName)) return pe;
+ if (propertyName == null || !propertyName.equals("class")) return pe;
// if it's "Type.class" or "pack.Type.class" return ClassExpression
ce.setSourcePosition(classProperty);
if (stack.isEmpty()) return ce;
@@ -972,8 +977,7 @@ public class ResolveVisitor extends
ClassCodeExpressionTransformer {
private void checkThisAndSuperAsPropertyAccess(final PropertyExpression
expression) {
if (expression.isImplicitThis()) return;
String prop = expression.getPropertyAsString();
- if (prop == null) return;
- if (!"this".equals(prop) && !"super".equals(prop)) return;
+ if (prop == null || !(prop.equals("this") || prop.equals("super")))
return;
ClassNode type = expression.getObjectExpression().getType();
if (expression.getObjectExpression() instanceof ClassExpression &&
!isSuperCallToDefaultMethod(expression) &&
!isThisCallToPrivateInterfaceMethod(expression)) {
@@ -1122,7 +1126,7 @@ public class ResolveVisitor extends
ClassCodeExpressionTransformer {
boolean oldInClosure = inClosure;
inClosure = true;
for (Parameter p : getParametersSafe(ce)) {
- ClassNode t = p.getType();
+ ClassNode t = p.getOriginType();
resolveOrFail(t, t);
visitAnnotations(p);
if (p.hasInitialExpression()) {
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy10218.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy10218.groovy
index 3299e515cd..bda2dae527 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy10218.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy10218.groovy
@@ -18,11 +18,12 @@
*/
package org.codehaus.groovy.transform.traitx
-import org.junit.Test
+import org.junit.jupiter.api.Test
import static groovy.test.GroovyAssert.shouldFail
final class Groovy10218 {
+
@Test
void testThatTypeCheckingDoesNotFailWhenCheckingTraitWithInterface() {
def ex = shouldFail '''
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy11508.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy11508.groovy
index ddf72729e5..0a9658712b 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy11508.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy11508.groovy
@@ -18,11 +18,12 @@
*/
package org.codehaus.groovy.transform.traitx
-import org.junit.Test
+import org.junit.jupiter.api.Test
import static groovy.test.GroovyAssert.assertScript
final class Groovy11508 {
+
@Test
void testGenericsAppliedToStaticMethodsForTraits() {
assertScript '''
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy6697Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy6697Bug.groovy
deleted file mode 100644
index 9a25b7121e..0000000000
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy6697Bug.groovy
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.codehaus.groovy.transform.traitx
-
-import groovy.test.GroovyTestCase
-
-class Groovy6697Bug extends GroovyTestCase {
- void testShouldAllowTraitSuperPropertyNotation() {
- assertScript '''
-trait A {
- String foo
-}
-
-class C implements A {
- void setBar(String foo) {
- // This fails with "Caught: groovy.lang.MissingPropertyException: No such
property: super for class: A"
- A.super.foo = foo
-
- // This work
- //A.super.setFoo(foo)
- }
-
- def yell() { foo.toUpperCase() + "!!" }
-}
-def c = new C()
-c.bar = 'bar'
-assert c.yell() == 'BAR!!'
- '''
- }
-
- void testShouldAllowTraitSuperPropertyNotationWithAmbiguousCall() {
- assertScript '''
-trait A {
- String foo
-}
-
-trait B {
- String foo
-}
-
-class C implements A,B {
- void setBar(String foo) {
- A.super.foo = foo+'Bar'
- }
- def yell() { foo.toUpperCase() + "!!" }
-}
-def c = new C()
-c.foo = 'foo'
-c.bar = 'bar'
-assert c.yell() == 'FOO!!'
- '''
-
- assertScript '''
-trait A {
- String foo
-}
-
-trait B {
- String foo
-}
-
-class C implements A,B {
- void setBar(String foo) {
- B.super.foo = foo+'Bar'
- }
- def yell() { foo.toUpperCase() + "!!" }
-}
-def c = new C()
-c.foo = 'foo'
-c.bar = 'bar'
-assert c.yell() == 'BARBAR!!'
- '''
- }
-
- void testShouldAllowTraitSuperSetterNotation() {
- assertScript '''
-trait A {
- String foo
-}
-
-class C implements A {
- void setBar(String foo) {
- A.super.setFoo(foo)
- }
-
- def yell() { foo.toUpperCase() + "!!" }
-}
-def c = new C()
-c.bar = 'bar'
-assert c.yell() == 'BAR!!'
- '''
- }
-
- void testShouldAllowTraitSuperSetterNotationWithAmbiguousCall() {
- assertScript '''
-trait A {
- String foo
-}
-
-trait B {
- String foo
-}
-
-class C implements A,B {
- void setBar(String foo) {
- A.super.setFoo(foo+'Bar')
- }
- def yell() { foo.toUpperCase() + "!!" }
-}
-def c = new C()
-c.foo = 'foo'
-c.bar = 'bar'
-assert c.yell() == 'FOO!!'
- '''
-
- assertScript '''
-trait A {
- String foo
-}
-
-trait B {
- String foo
-}
-
-class C implements A,B {
- void setBar(String foo) {
- B.super.setFoo(foo+'Bar')
- }
- def yell() { foo.toUpperCase() + "!!" }
-}
-def c = new C()
-c.foo = 'foo'
-c.bar = 'bar'
-assert c.yell() == 'BARBAR!!'
- '''
- }
-}
diff --git
a/src/test/org/codehaus/groovy/transform/traitx/Groovy7196SupportTrait.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy7196SupportTrait.groovy
index 5ee119c612..f994784aae 100644
---
a/src/test/org/codehaus/groovy/transform/traitx/Groovy7196SupportTrait.groovy
+++
b/src/test/org/codehaus/groovy/transform/traitx/Groovy7196SupportTrait.groovy
@@ -21,3 +21,6 @@ package org.codehaus.groovy.transform.traitx
trait Groovy7196SupportTrait {
public static String someString = 'ok'
}
+
+class Groovy7196SupportTraitImpl implements Groovy7196SupportTrait {
+}
diff --git
a/src/test/org/codehaus/groovy/transform/traitx/Groovy7196SupportTraitImpl.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy7196SupportTraitImpl.groovy
deleted file mode 100644
index 8101462660..0000000000
---
a/src/test/org/codehaus/groovy/transform/traitx/Groovy7196SupportTraitImpl.groovy
+++ /dev/null
@@ -1,22 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.codehaus.groovy.transform.traitx
-
-class Groovy7196SupportTraitImpl implements Groovy7196SupportTrait {
-}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7215Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy7215Bug.groovy
deleted file mode 100644
index 84e1bd20a8..0000000000
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7215Bug.groovy
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.codehaus.groovy.transform.traitx
-
-import org.codehaus.groovy.tools.stubgenerator.StringSourcesStubTestCase
-
-class Groovy7215Bug extends StringSourcesStubTestCase {
- @Override
- Map<String, String> provideSources() {
- [
- 'FooJ.java': '''
-
- public class FooJ {
- public static String TEXT = "FooJ";
- }
- ''',
- 'FilterConfig.groovy':'''
-
- @groovy.transform.CompileStatic
- class FilterConfig implements
org.codehaus.groovy.transform.traitx.Groovy7215SupportTrait {
- String text
- }
- '''
- ]
- }
-
- @Override
- void verifyStubs() {
-
- }
-}
diff --git
a/src/test/org/codehaus/groovy/transform/traitx/Groovy7215SupportTrait.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy7215SupportTrait.groovy
index 6a205ddd7d..17b967fcdb 100644
---
a/src/test/org/codehaus/groovy/transform/traitx/Groovy7215SupportTrait.groovy
+++
b/src/test/org/codehaus/groovy/transform/traitx/Groovy7215SupportTrait.groovy
@@ -18,8 +18,13 @@
*/
package org.codehaus.groovy.transform.traitx
[email protected]
+import groovy.transform.CompileStatic
+
+@CompileStatic
trait Groovy7215SupportTrait {
- void setText(String text) {}
- String getText() { 'ok' }
-}
\ No newline at end of file
+ void setText(String s) {
+ }
+ String getText() {
+ 'ok'
+ }
+}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7285Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy7285Bug.groovy
deleted file mode 100644
index ca9f66f1ee..0000000000
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7285Bug.groovy
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-
-
-
-package org.codehaus.groovy.transform.traitx
-
-import groovy.test.GroovyTestCase
-
-class Groovy7285Bug extends GroovyTestCase {
- void testRuntimeStackableTraits() {
- assertScript '''trait D {
- void methodA() { ref << "D"; super.methodA() }
-}
-trait C {
- void methodA() { ref << "C"; super.methodA() }
-}
-trait B {
- void methodA() { ref << "B"; super.methodA() }
-}
-trait A {
- void methodA() { ref << "A" }
-}
-
-class M implements A, D, C, B { List ref = [] }
-class Q { List ref = [] }
-
-def direct = new M()
-
-println "Static: ${direct.methodA();direct.ref}"
-
-def runtime = new Q().withTraits(A,D,C,B)
-
-// we need another test to make sure that 2 proxies with the same set of
traits are different
-// because the traits ordering is different
-def runtime2 = new Q().withTraits(A,D,C,B)
-
-println "Dynamic: ${runtime.methodA();runtime.ref}"
-println "Dynamic 2: ${runtime2.methodA();runtime2.ref}"
-
-assert direct.ref == ['B','C','D','A']
-assert direct.ref == runtime.ref
-assert runtime2.ref == ['B','C','D','A']
-
-'''
- }
-}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7926.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy7926.groovy
deleted file mode 100644
index cb4f7bf3f9..0000000000
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7926.groovy
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.codehaus.groovy.transform.traitx
-
-import org.codehaus.groovy.classgen.asm.AbstractBytecodeTestCase
-
-final class Groovy7926 extends AbstractBytecodeTestCase {
-
- void testThatVoidTypesFromTraitsWithGenericsWork() {
- assertScript '''
- trait MyTrait<D> {
- void delete() {
- println 'works'
- }
- }
- class MyImpl implements MyTrait<MyImpl> {
- }
- new MyImpl().delete()
- true
- '''
- }
-
- void testThatVoidTypesAreNotUsedForVariableNamesInByteCode() {
- def result = compile method:'delete', classNamePattern:'MyImpl', '''
- trait MyTrait<D> {
- void delete() {
- println 'works'
- }
- }
- class MyImpl implements MyTrait<MyImpl> {
- }
- '''
-
- int start = result.indexOf('--BEGIN--')
- int until = result.indexOf('--END--')
- assert start > 0 && until > start
-
- assert result.indexOf('CHECKCAST void', start) !in start..until
- }
-}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy_6697.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_6697.groovy
new file mode 100644
index 0000000000..2f7c799d5c
--- /dev/null
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_6697.groovy
@@ -0,0 +1,183 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.codehaus.groovy.transform.traitx
+
+import org.junit.jupiter.api.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy_6697 {
+
+ @Test
+ void testShouldAllowTraitSuperPropertyNotation() {
+ assertScript '''
+ trait A {
+ String foo
+ }
+
+ class C implements A {
+ void setBar(String foo) {
+ // This fails with "Caught:
groovy.lang.MissingPropertyException: No such property: super for class: A"
+ A.super.foo = foo
+
+ // This work
+ //A.super.setFoo(foo)
+ }
+
+ def yell() {
+ foo.toUpperCase() + "!!"
+ }
+ }
+
+ def c = new C()
+ c.bar = 'bar'
+ assert c.yell() == 'BAR!!'
+ '''
+ }
+
+ @Test
+ void testShouldAllowTraitSuperPropertyNotationWithAmbiguousCall() {
+ assertScript '''
+ trait A {
+ String foo
+ }
+
+ trait B {
+ String foo
+ }
+
+ class C implements A,B {
+ void setBar(String foo) {
+ A.super.foo = foo+'Bar'
+ }
+ def yell() {
+ foo.toUpperCase() + "!!"
+ }
+ }
+
+ def c = new C()
+ c.foo = 'foo'
+ c.bar = 'bar'
+ assert c.yell() == 'FOO!!'
+ '''
+ }
+
+ @Test
+ void testShouldAllowTraitSuperPropertyNotationWithAmbiguousCall2() {
+ assertScript '''
+ trait A {
+ String foo
+ }
+
+ trait B {
+ String foo
+ }
+
+ class C implements A,B {
+ void setBar(String foo) {
+ B.super.foo = foo+'Bar'
+ }
+ def yell() {
+ foo.toUpperCase() + "!!"
+ }
+ }
+
+ def c = new C()
+ c.foo = 'foo'
+ c.bar = 'bar'
+ assert c.yell() == 'BARBAR!!'
+ '''
+ }
+
+ @Test
+ void testShouldAllowTraitSuperSetterNotation() {
+ assertScript '''
+ trait A {
+ String foo
+ }
+
+ class C implements A {
+ void setBar(String foo) {
+ A.super.setFoo(foo)
+ }
+ def yell() {
+ foo.toUpperCase() + "!!"
+ }
+ }
+
+ def c = new C()
+ c.bar = 'bar'
+ assert c.yell() == 'BAR!!'
+ '''
+ }
+
+ @Test
+ void testShouldAllowTraitSuperSetterNotationWithAmbiguousCall() {
+ assertScript '''
+ trait A {
+ String foo
+ }
+
+ trait B {
+ String foo
+ }
+
+ class C implements A,B {
+ void setBar(String foo) {
+ A.super.setFoo(foo+'Bar')
+ }
+ def yell() {
+ foo.toUpperCase() + "!!"
+ }
+ }
+
+ def c = new C()
+ c.foo = 'foo'
+ c.bar = 'bar'
+ assert c.yell() == 'FOO!!'
+ '''
+ }
+
+ @Test
+ void testShouldAllowTraitSuperSetterNotationWithAmbiguousCall2() {
+ assertScript '''
+ trait A {
+ String foo
+ }
+
+ trait B {
+ String foo
+ }
+
+ class C implements A,B {
+ void setBar(String foo) {
+ B.super.setFoo(foo+'Bar')
+ }
+ def yell() {
+ foo.toUpperCase() + "!!"
+ }
+ }
+
+ def c = new C()
+ c.foo = 'foo'
+ c.bar = 'bar'
+ assert c.yell() == 'BARBAR!!'
+ '''
+ }
+}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy6736Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_6736.groovy
similarity index 68%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy6736Bug.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_6736.groovy
index b5cb5401a5..ad12031c64 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy6736Bug.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_6736.groovy
@@ -18,18 +18,23 @@
*/
package org.codehaus.groovy.transform.traitx
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
-class Groovy6736Bug extends GroovyTestCase {
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy_6736 {
+
+ @Test
void testAddExtraMethodToMapUsingTraitAndAsKeyword() {
assertScript '''
-trait Extra {
- String extra() { "I'm an extra method" }
-}
-def extraList = [] as Extra
-assert extraList.extra() == "I'm an extra method"
-def extraMap = [:] as Extra
-assert extraMap.extra() == "I'm an extra method"
-'''
+ trait Extra {
+ String extra() { "I'm an extra method" }
+ }
+
+ def extraList = [] as Extra
+ assert extraList.extra() == "I'm an extra method"
+ def extraMap = [:] as Extra
+ assert extraMap.extra() == "I'm an extra method"
+ '''
}
}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy6741Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_6741.groovy
similarity index 91%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy6741Bug.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_6741.groovy
index f1bd5395d2..2425d3da66 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy6741Bug.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_6741.groovy
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.codehaus.groovy.transform.traitx
+import org.junit.jupiter.api.Test
+import static groovy.test.GroovyAssert.assertScript
+final class Groovy_6741 {
-package org.codehaus.groovy.transform.traitx
-
-import groovy.test.GroovyTestCase
-
-class Groovy6741Bug extends GroovyTestCase {
+ @Test
void testRunTimeCoercionOfTraitUsingGenerics() {
assertScript '''
trait GPredicate<T> {
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7011Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7011.groovy
similarity index 94%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy7011Bug.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_7011.groovy
index ae6a9a5283..efa2380f47 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7011Bug.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7011.groovy
@@ -16,15 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.codehaus.groovy.transform.traitx
+import org.junit.jupiter.api.Test
+import static groovy.test.GroovyAssert.assertScript
+final class Groovy_7011 {
-package org.codehaus.groovy.transform.traitx
-
-import groovy.test.GroovyTestCase
-
-class Groovy7011Bug extends GroovyTestCase {
+ @Test
void testTraitWithDefaultArgumentMethod() {
assertScript '''
trait HiSupport {
@@ -40,6 +40,7 @@ class Groovy7011Bug extends GroovyTestCase {
'''
}
+ @Test
void testTraitWithDefaultArgumentMethod2() {
assertScript '''
trait HiSupport {
@@ -55,6 +56,7 @@ class Groovy7011Bug extends GroovyTestCase {
'''
}
+ @Test
void testTraitWithDefaultArgumentMethodCompileStatic() {
assertScript '''import groovy.transform.CompileStatic
@@ -77,6 +79,7 @@ class Groovy7011Bug extends GroovyTestCase {
'''
}
+ @Test
void testTraitWithDefaultArgumentMethod2CompileStatic() {
assertScript '''import groovy.transform.CompileStatic
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7190Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7190.groovy
similarity index 89%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy7190Bug.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_7190.groovy
index 69a26e952d..8f8d717bd4 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7190Bug.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7190.groovy
@@ -18,9 +18,13 @@
*/
package org.codehaus.groovy.transform.traitx
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
-class Groovy7190Bug extends GroovyTestCase {
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy_7190 {
+
+ @Test
void testStaticPropertyBug() {
assertScript '''
trait SomeTrait {
@@ -40,7 +44,9 @@ class Groovy7190Bug extends GroovyTestCase {
this.someString
}
}
- class SomeClass implements SomeTrait {}
+
+ class SomeClass implements SomeTrait {
+ }
assert 'Default Value' == SomeClass.stringValue
assert 'Default Value' == SomeClass.stringValueUsingThis
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7196Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7196.groovy
similarity index 81%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy7196Bug.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_7196.groovy
index 04ecb981f9..cd2e292c6c 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7196Bug.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7196.groovy
@@ -18,15 +18,22 @@
*/
package org.codehaus.groovy.transform.traitx
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
-class Groovy7196Bug extends GroovyTestCase {
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy_7196 {
+
+ @Test
void testShouldNotThrowDuplicateMethodWithPrecompiledTrait() {
- assertScript '''import
org.codehaus.groovy.transform.traitx.Groovy7196SupportTrait
- class SomeTestClass implements Groovy7196SupportTrait {}
+ assertScript '''
+ class SomeTestClass implements
org.codehaus.groovy.transform.traitx.Groovy7196SupportTrait {
+ }
assert
SomeTestClass.org_codehaus_groovy_transform_traitx_Groovy7196SupportTrait__someString
== 'ok'
'''
}
+
+ @Test
void testStaticFieldShouldBeInitialized() {
assert
Groovy7196SupportTraitImpl.org_codehaus_groovy_transform_traitx_Groovy7196SupportTrait__someString
== 'ok'
}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7206Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7206.groovy
similarity index 79%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy7206Bug.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_7206.groovy
index e6ba152f2d..edadacb1d0 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7206Bug.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7206.groovy
@@ -16,13 +16,15 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.codehaus.groovy.transform.traitx
+import org.junit.jupiter.api.Test
-package org.codehaus.groovy.transform.traitx
+import static groovy.test.GroovyAssert.assertScript
-import groovy.test.GroovyTestCase
+final class Groovy_7206 {
-class Groovy7206Bug extends GroovyTestCase {
+ @Test
void testShouldNotThrowNPEDuringCompilation() {
assertScript '''
trait SetUnknown {
@@ -33,12 +35,14 @@ class Groovy7206Bug extends GroovyTestCase {
class A implements SetUnknown {
def unknownProperty
}
+
def a = new A()
a.setup()
assert a.unknownProperty == 1
'''
}
+ @Test
void testShouldNotThrowNPEDuringCompilation2() {
assertScript '''
trait SetUnknown {
@@ -50,6 +54,7 @@ class Groovy7206Bug extends GroovyTestCase {
class A implements SetUnknown {
def unknownProperty
}
+
def a = new A()
a.setup()
assert a.unknownProperty == 1
@@ -57,6 +62,7 @@ class Groovy7206Bug extends GroovyTestCase {
'''
}
+ @Test
void testShouldNotThrowNPEDuringCompilation3() {
assertScript '''
trait SetUnknown {
@@ -68,6 +74,7 @@ class Groovy7206Bug extends GroovyTestCase {
class A implements SetUnknown {
def unknownProperty = 1
}
+
def a = new A()
a.setup()
assert a.unknownProperty == 3
@@ -75,19 +82,22 @@ class Groovy7206Bug extends GroovyTestCase {
'''
}
+ @Test
void testShouldRecognizeStaticProperty() {
assertScript '''
-trait Validateable {
- private static Map constraintsMapInternal
- static Map getConstraintsMap() {
- if(this.constraintsMapInternal == null) {
- this.constraintsMapInternal = [:]
- }
- }
-}
-class ValidateTest implements Validateable {}
-def v = new ValidateTest()
-assert v.constraintsMap == [:]
+ trait Validateable {
+ private static Map constraintsMapInternal
+ static Map getConstraintsMap() {
+ if(this.constraintsMapInternal == null) {
+ this.constraintsMapInternal = [:]
+ }
+ }
+ }
+ class ValidateTest implements Validateable {
+ }
+
+ def v = new ValidateTest()
+ assert v.constraintsMap == [:]
'''
}
}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy_7215.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7215.groovy
new file mode 100644
index 0000000000..e29e2840dd
--- /dev/null
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7215.groovy
@@ -0,0 +1,59 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.codehaus.groovy.transform.traitx
+
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.tools.javac.JavaAwareCompilationUnit
+import org.junit.jupiter.api.Test
+
+final class Groovy_7215 {
+
+ @Test
+ void testTraitAndClassUnderJointCompilation() {
+ def config = new CompilerConfiguration().tap {
+ jointCompilationOptions = [flags: new String[]{'release=11'},
memStub: true]
+ targetDirectory = File.createTempDir()
+ targetBytecode = '11'
+ }
+ File parentDir = File.createTempDir()
+ try {
+ def a = new File(parentDir, 'A.java')
+ a.write '''
+ public class A {
+ public static final String TEXT = "";
+ }
+ '''
+ def b = new File(parentDir, 'B.groovy')
+ b.write '''
+ @groovy.transform.CompileStatic
+ class B implements
org.codehaus.groovy.transform.traitx.Groovy7215SupportTrait {
+ String text // same name as trait property
+ }
+ '''
+
+ def loader = new GroovyClassLoader(this.class.classLoader)
+ def unit = new JavaAwareCompilationUnit(config, loader)
+ unit.addSources(a, b)
+ unit.compile()
+ } finally {
+ parentDir.deleteDir()
+ config.targetDirectory.deleteDir()
+ }
+ }
+}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7217Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7217.groovy
similarity index 88%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy7217Bug.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_7217.groovy
index 9efce8b606..7543ef24fc 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7217Bug.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7217.groovy
@@ -16,25 +16,28 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.codehaus.groovy.transform.traitx
+import org.junit.jupiter.api.Test
-package org.codehaus.groovy.transform.traitx
+import static groovy.test.GroovyAssert.assertScript
-import groovy.test.GroovyTestCase
+final class Groovy_7217 {
-class Groovy7217Bug extends GroovyTestCase {
+ @Test
void testNumberInitializationInTrait() {
assertScript '''
trait Version {
Long version = 1
}
-
- class HasVersion implements Version {}
+ class HasVersion implements Version {
+ }
def v = new HasVersion()
assert v.version == 1'''
}
+ @Test
void testAnyInitializerInTrait() {
assertScript '''
class SomeA {}
@@ -46,6 +49,7 @@ class Groovy7217Bug extends GroovyTestCase {
new SomeA()
}
}
+
def d = new Dummy()
assert d.a instanceof SomeA
'''
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7269Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7269.groovy
similarity index 74%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy7269Bug.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_7269.groovy
index c72572e5af..c537c9e436 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7269Bug.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7269.groovy
@@ -16,24 +16,27 @@
* specific language governing permissions and limitations
* under the License.
*/
+package org.codehaus.groovy.transform.traitx
+import org.junit.jupiter.api.Test
-package org.codehaus.groovy.transform.traitx
+import static groovy.test.GroovyAssert.assertScript
-import groovy.test.GroovyTestCase
+final class Groovy_7269 {
-class Groovy7269Bug extends GroovyTestCase {
+ @Test
void testTraitWithMetaClassMod() {
assertScript '''
trait SomeTrait {
String title
}
-
- class Widget implements SomeTrait {}
+ class Widget implements SomeTrait {
+ }
Widget.metaClass.getTitle = {
'Some Default Title'
}
+
def w = new Widget()
w.title = 'Some New Title'
assert w.title == 'Some Default Title'
@@ -41,22 +44,19 @@ class Groovy7269Bug extends GroovyTestCase {
}
// GROOVY-7308
+ @Test
void testMixOfStaticAndNotStaticPropertiesOfSameName() {
- assertScript '''class Widget {
-
- static Integer someNumber = 42
-}
-
-Widget.metaClass.getSomeNumber = {
- 2112
-}
-
-def widget = new Widget()
-
-assert widget.someNumber == 2112
+ assertScript '''
+ class Widget {
+ static Integer someNumber = 42
+ }
+ Widget.metaClass.getSomeNumber = {
+ 2112
+ }
+ def widget = new Widget()
+ assert widget.someNumber == 2112
'''
}
}
-
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7275Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7275.groovy
similarity index 60%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy7275Bug.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_7275.groovy
index 8c352d2e0e..0da82d8047 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7275Bug.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7275.groovy
@@ -18,30 +18,32 @@
*/
package org.codehaus.groovy.transform.traitx
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
-class Groovy7275Bug extends GroovyTestCase {
- void testShouldNotThrowCompileBug() {
- assertScript '''
-
-import groovy.transform.SelfType
-import groovy.transform.CompileStatic
+import static groovy.test.GroovyAssert.assertScript
-class BitcoinClient {
- Map<String,Object> getTransaction(String txid) {}
-}
-
-@SelfType(BitcoinClient)
-@CompileStatic
-trait BitcoinCLIAPI {
+final class Groovy_7275 {
- Map<String, Object> gettransaction(String txid) {
- return getTransaction(txid)
- }
-}
-
-BitcoinCLIAPI
-
-'''
+ @Test
+ void testShouldNotThrowCompileBug() {
+ assertScript '''
+ import groovy.transform.SelfType
+ import groovy.transform.CompileStatic
+
+ class BitcoinClient {
+ Map<String,Object> getTransaction(String txid) {
+ }
+ }
+
+ @CompileStatic
+ @SelfType(BitcoinClient)
+ trait BitcoinCLIAPI {
+ Map<String, Object> gettransaction(String txid) {
+ return getTransaction(txid)
+ }
+ }
+
+ BitcoinCLIAPI
+ '''
}
}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy_7285.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7285.groovy
new file mode 100644
index 0000000000..74b2e7d474
--- /dev/null
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7285.groovy
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.codehaus.groovy.transform.traitx
+
+import org.junit.jupiter.api.Test
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy_7285 {
+
+ @Test
+ void testRuntimeStackableTraits() {
+ assertScript '''
+ trait A {
+ void methodA() { ref << "A" }
+ }
+ trait B {
+ void methodA() { ref << "B"; super.methodA() }
+ }
+ trait C {
+ void methodA() { ref << "C"; super.methodA() }
+ }
+ trait D {
+ void methodA() { ref << "D"; super.methodA() }
+ }
+
+ class M implements A, D, C, B {
+ List ref = []
+ }
+ class Q {
+ List ref = []
+ }
+
+ def direct = new M()
+ println "Static: ${direct.methodA();direct.ref}"
+ def runtime = new Q().withTraits(A,D,C,B)
+
+ // we need another test to make sure that 2 proxies with the same
set of traits are different
+ // because the traits ordering is different
+ def runtime2 = new Q().withTraits(A,D,C,B)
+
+ println "Dynamic: ${runtime.methodA();runtime.ref}"
+ println "Dynamic 2: ${runtime2.methodA();runtime2.ref}"
+
+ assert direct.ref == ['B','C','D','A']
+ assert direct.ref == runtime.ref
+ assert runtime2.ref == ['B','C','D','A']
+ '''
+ }
+}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7456Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7456.groovy
similarity index 89%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy7456Bug.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_7456.groovy
index 6fdf6224aa..63b1b4d07d 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7456Bug.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7456.groovy
@@ -18,12 +18,15 @@
*/
package org.codehaus.groovy.transform.traitx
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
-class Groovy7456Bug extends GroovyTestCase {
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy_7456 {
+
+ @Test
void testShouldAllowBuilderInTrait() {
- assertScript '''
- import groovy.xml.*
+ assertScript '''import groovy.xml.*
trait MyBuilder {
def build2() {
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7500.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7500.groovy
similarity index 95%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy7500.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_7500.groovy
index 923b6d3cf0..5d1357f3c3 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7500.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7500.groovy
@@ -18,11 +18,11 @@
*/
package org.codehaus.groovy.transform.traitx
-import org.junit.Test
+import org.junit.jupiter.api.Test
import static groovy.test.GroovyAssert.shouldFail
-final class Groovy7500 {
+final class Groovy_7500 {
@Test
void testMetaClassOverride() {
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy7846Bug.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7846.groovy
similarity index 84%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy7846Bug.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_7846.groovy
index 6aaee4714d..af50a13777 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy7846Bug.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7846.groovy
@@ -18,14 +18,15 @@
*/
package org.codehaus.groovy.transform.traitx
-import groovy.test.GroovyTestCase
import org.codehaus.groovy.ast.ClassNode
+import org.junit.jupiter.api.Test
-class Groovy7846Bug extends GroovyTestCase {
+final class Groovy_7846 {
+ @Test
void testTraitsShouldAllowGenerifiedReturnTypesInStaticMethods() {
- def cl = new GroovyClassLoader()
- cl.parseClass('''
+ def gcl = new GroovyClassLoader()
+ gcl.parseClass '''
class Foo {
static <T> T withClient(@DelegatesTo(Foo) Closure<T> callable
) {
callable.call()
@@ -36,18 +37,17 @@ class Groovy7846Bug extends GroovyTestCase {
Collection<D> asCollection(D type) {
return [type]
}
-
static <T> T withClient(@DelegatesTo(Foo) Closure<T> callable
) {
callable.call()
}
}
- ''')
- Class cls = cl.parseClass('''
- class Bar implements TraitWithStaticMethod<Bar> {}
- ''')
+ '''
+ Class cls = gcl.parseClass '''
+ class Bar implements TraitWithStaticMethod<Bar> {
+ }
+ '''
assert new ClassNode(cls).methods
assert cls.withClient { true }
}
}
-
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy_7926.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7926.groovy
new file mode 100644
index 0000000000..0e3c4eaa09
--- /dev/null
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_7926.groovy
@@ -0,0 +1,84 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.codehaus.groovy.transform.traitx
+
+import org.codehaus.groovy.control.CompilationUnit
+import org.codehaus.groovy.control.CompilerConfiguration
+import org.codehaus.groovy.control.Phases
+import org.junit.jupiter.api.Test
+import org.objectweb.asm.ClassReader
+import org.objectweb.asm.util.CheckClassAdapter
+
+import static groovy.test.GroovyAssert.assertScript
+
+final class Groovy_7926 {
+
+ @Test
+ void testThatVoidTypesFromTraitsWithGenericsWork() {
+ assertScript '''
+ trait T<X> {
+ void proc() {
+ println 'works'
+ }
+ }
+ class C implements T<C> {
+ }
+
+ new C().proc()
+ '''
+ }
+
+ @Test
+ void testThatVoidTypesAreNotUsedForVariableNamesInByteCode() {
+ def config = new CompilerConfiguration().tap {
+ targetDirectory = File.createTempDir()
+ }
+ File parentDir = File.createTempDir()
+ try {
+ def loader = new GroovyClassLoader(this.class.classLoader)
+ def unit = new CompilationUnit(config, null, loader)
+ unit.addSources(new File(parentDir, 'T.groovy').leftShift(
+ '''
+ trait T<X> {
+ void proc() {
+ println 'works'
+ }
+ }
+ class C implements T<C> {
+ }
+ '''
+ ))
+ unit.compile(Phases.CLASS_GENERATION)
+
+ def writer = new StringWriter()
+ def reader = new ClassReader(unit.classes.find{ it.name == 'C'
}.bytes)
+ CheckClassAdapter.verify(reader, loader, true, new
PrintWriter(writer))
+
+ def string = writer.toString().with {
+ int start = indexOf('proc()V')
+ int until = indexOf('RETURN', start) + 7
+ substring(start, until) // proc bytecode
+ }
+ assert !string.contains('CHECKCAST void') //
+ } finally {
+ parentDir.deleteDir()
+ config.targetDirectory.deleteDir()
+ }
+ }
+}
diff --git a/src/test/org/codehaus/groovy/transform/traitx/Groovy8864.groovy
b/src/test/org/codehaus/groovy/transform/traitx/Groovy_8864.groovy
similarity index 91%
rename from src/test/org/codehaus/groovy/transform/traitx/Groovy8864.groovy
rename to src/test/org/codehaus/groovy/transform/traitx/Groovy_8864.groovy
index de702ef144..266b6205c2 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/Groovy8864.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/Groovy_8864.groovy
@@ -18,11 +18,12 @@
*/
package org.codehaus.groovy.transform.traitx
-import org.junit.Test
+import org.junit.jupiter.api.Test
import static groovy.test.GroovyAssert.assertScript
-final class Groovy8864 {
+final class Groovy_8864 {
+
@Test
void testGenericsAppliedToStaticMethodsForTraits() {
assertScript '''
@@ -34,7 +35,7 @@ final class Groovy8864 {
class Bar implements Foo<Bar> {
}
- assert Bar.getMethod("get", [Bar] as Class[]).returnType == Bar
+ assert Bar.getMethod("get", new Class[]{Bar}).returnType == Bar
assert Bar.getDeclaredField("Foo__INSTANCE").type == Bar
assert Bar.getMethod("setINSTANCE", new Class[]{Bar})
assert Bar.getMethod("getINSTANCE").returnType == Bar
diff --git a/src/test/org/codehaus/groovy/transform/traitx/TestTrait2.groovy
b/src/test/org/codehaus/groovy/transform/traitx/TestTrait2.groovy
index 9f74b37c39..4b5edd5d5f 100644
--- a/src/test/org/codehaus/groovy/transform/traitx/TestTrait2.groovy
+++ b/src/test/org/codehaus/groovy/transform/traitx/TestTrait2.groovy
@@ -20,9 +20,13 @@ package org.codehaus.groovy.transform.traitx
trait TestTrait2 {
private String message = 'Hello'
- String getMessage() { this.message }
- String blah() { message }
+ String getMessage() {
+ this.message
+ }
+ String blah() {
+ message
+ }
def meow() {
"Meow! I'm a ${cat()}"
}
-}
\ No newline at end of file
+}
diff --git
a/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
b/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
index 3c8c2445ab..86514f6623 100644
---
a/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
+++
b/src/test/org/codehaus/groovy/transform/traitx/TraitASTTransformationTest.groovy
@@ -22,8 +22,8 @@ import groovy.transform.SelfType
import org.codehaus.groovy.ast.ClassHelper
import org.codehaus.groovy.ast.expr.ClassExpression
import org.codehaus.groovy.ast.expr.ListExpression
-import org.junit.Ignore
-import org.junit.Test
+import org.junit.jupiter.api.Disabled
+import org.junit.jupiter.api.Test
import static groovy.test.GroovyAssert.assertScript
import static groovy.test.GroovyAssert.shouldFail
@@ -3828,7 +3828,7 @@ final class TraitASTTransformationTest {
}
// GROOVY-10598
- @Ignore @Test
+ @Disabled @Test
void testAssignOperators() {
assertScript shell, '''
trait T {
diff --git
a/src/test/org/codehaus/groovy/transform/traitx/TraitWithClosureOrLambda.groovy
b/src/test/org/codehaus/groovy/transform/traitx/TraitWithClosureOrLambda.groovy
index 1a7f844b5a..5305c82969 100644
---
a/src/test/org/codehaus/groovy/transform/traitx/TraitWithClosureOrLambda.groovy
+++
b/src/test/org/codehaus/groovy/transform/traitx/TraitWithClosureOrLambda.groovy
@@ -18,7 +18,7 @@
*/
package org.codehaus.groovy.transform.traitx
-import org.junit.Test
+import org.junit.jupiter.api.Test
import static groovy.test.GroovyAssert.assertScript
import static groovy.test.GroovyAssert.shouldFail
diff --git a/src/test/org/codehaus/groovy/util/HashCodeHelperTest.groovy
b/src/test/org/codehaus/groovy/util/HashCodeHelperTest.groovy
index 2298dd1926..a1d492688b 100644
--- a/src/test/org/codehaus/groovy/util/HashCodeHelperTest.groovy
+++ b/src/test/org/codehaus/groovy/util/HashCodeHelperTest.groovy
@@ -19,10 +19,11 @@
package org.codehaus.groovy.util
import groovy.transform.CompileStatic
-import org.junit.Test
+import org.junit.jupiter.api.Test
@CompileStatic
-class HashCodeHelperTest {
+final class HashCodeHelperTest {
+
@Test
void testUpdateHash() {
assert 158 == HashCodeHelper.updateHash(1, new Character('c' as char))
diff --git a/src/test/org/codehaus/groovy/util/ListHashMapTest.groovy
b/src/test/org/codehaus/groovy/util/ListHashMapTest.groovy
index 3e28bfc75d..a0188601cd 100644
--- a/src/test/org/codehaus/groovy/util/ListHashMapTest.groovy
+++ b/src/test/org/codehaus/groovy/util/ListHashMapTest.groovy
@@ -18,7 +18,9 @@
*/
package org.codehaus.groovy.util
-import org.junit.Test
+import org.junit.jupiter.api.Test
+
+import static org.junit.jupiter.api.Assertions.assertThrows
final class ListHashMapTest {
@@ -188,21 +190,27 @@ final class ListHashMapTest {
assert !lhm.containsValue('3')
}
- @Test(expected = UnsupportedOperationException)
+ @Test
void testCannotModifyInnerMapViaKeySet() {
testSwitchToInnerMap()
- lhm.keySet().clear()
+ assertThrows(UnsupportedOperationException) {
+ lhm.keySet().clear()
+ }
}
- @Test(expected = UnsupportedOperationException)
+ @Test
void testCannotModifyInnerMapViaEntrySet() {
testSwitchToInnerMap()
- lhm.entrySet().clear()
+ assertThrows(UnsupportedOperationException) {
+ lhm.entrySet().clear()
+ }
}
- @Test(expected = UnsupportedOperationException)
+ @Test
void testCannotModifyInnerMapViaValueCol() {
testSwitchToInnerMap()
- lhm.values().clear()
+ assertThrows(UnsupportedOperationException) {
+ lhm.values().clear()
+ }
}
}
diff --git
a/src/test/org/codehaus/groovy/util/ManagedConcurrentLinkedQueueTest.groovy
b/src/test/org/codehaus/groovy/util/ManagedConcurrentLinkedQueueTest.groovy
index f587f788d9..e5829e5e61 100644
--- a/src/test/org/codehaus/groovy/util/ManagedConcurrentLinkedQueueTest.groovy
+++ b/src/test/org/codehaus/groovy/util/ManagedConcurrentLinkedQueueTest.groovy
@@ -18,18 +18,22 @@
*/
package org.codehaus.groovy.util
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
-class ManagedConcurrentLinkedQueueTest extends GroovyTestCase {
+import static org.junit.jupiter.api.Assertions.assertThrows
- def queue
+final class ManagedConcurrentLinkedQueueTest {
+ private ManagedConcurrentLinkedQueue queue
+
+ @BeforeEach
void setUp() {
- def manager = ReferenceManager.createIdlingManager(null)
- def bundle = new ReferenceBundle(manager, ReferenceType.HARD)
+ def bundle = new
ReferenceBundle(ReferenceManager.createIdlingManager(null), ReferenceType.HARD)
queue = new ManagedConcurrentLinkedQueue(bundle)
}
+ @Test
void testElementAdd() {
queue.add(1)
def i = 0
@@ -40,10 +44,12 @@ class ManagedConcurrentLinkedQueueTest extends
GroovyTestCase {
assert i ==1
}
+ @Test
void testEmptylist() {
assert queue.isEmpty()
}
+ @Test
void testRemoveinTheMiddle() {
queue.add(1)
queue.add(2)
@@ -58,6 +64,7 @@ class ManagedConcurrentLinkedQueueTest extends GroovyTestCase
{
assert val == 12
}
+ @Test
void testAddRemove() {
10.times {
queue.add(it)
@@ -69,8 +76,9 @@ class ManagedConcurrentLinkedQueueTest extends GroovyTestCase
{
assert queue.isEmpty()
}
+ @Test
void testIteratorThrowsNoSuchElementException() {
- shouldFail(NoSuchElementException) {
+ assertThrows(NoSuchElementException) {
queue.add(1)
def iter = queue.iterator()
assert iter.next() == 1
@@ -78,13 +86,13 @@ class ManagedConcurrentLinkedQueueTest extends
GroovyTestCase {
}
}
+ @Test
void testIteratorThrowsOnRemoveIfNextNotCalled() {
- shouldFail(IllegalStateException) {
+ assertThrows(IllegalStateException) {
queue.add(1)
def iter = queue.iterator()
assert iter.hasNext()
iter.remove()
}
}
-
}
diff --git
a/src/test/org/codehaus/groovy/util/ManagedConcurrentValueMapTest.groovy
b/src/test/org/codehaus/groovy/util/ManagedConcurrentValueMapTest.groovy
index c5e405d835..05c0d5df5b 100644
--- a/src/test/org/codehaus/groovy/util/ManagedConcurrentValueMapTest.groovy
+++ b/src/test/org/codehaus/groovy/util/ManagedConcurrentValueMapTest.groovy
@@ -18,13 +18,14 @@
*/
package org.codehaus.groovy.util
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
-class ManagedConcurrentValueMapTest extends GroovyTestCase {
+final class ManagedConcurrentValueMapTest {
- ManagedConcurrentValueMap<String, Object> map =
+ private ManagedConcurrentValueMap<String, Object> map =
new ManagedConcurrentValueMap<String,
Object>(ReferenceBundle.getHardBundle())
+ @Test
void testEntriesRemoveSelfFromMapWhenFinalized() {
for (int i = 0; i < 5; i++) {
map.put("Key${i}", new Object())
diff --git a/src/test/org/codehaus/groovy/util/ReferenceManagerTest.groovy
b/src/test/org/codehaus/groovy/util/ReferenceManagerTest.groovy
index 117d023bcf..0e518890f0 100644
--- a/src/test/org/codehaus/groovy/util/ReferenceManagerTest.groovy
+++ b/src/test/org/codehaus/groovy/util/ReferenceManagerTest.groovy
@@ -18,17 +18,19 @@
*/
package org.codehaus.groovy.util
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.BeforeEach
+import org.junit.jupiter.api.Test
import java.lang.ref.ReferenceQueue
-class ReferenceManagerTest extends GroovyTestCase {
+final class ReferenceManagerTest {
- int finalizeCounter
- TestReference<Object> testReference
- TestQueue<Object> queue
- ReferenceManager callback
+ private int finalizeCounter
+ private TestReference<Object> testReference
+ private TestQueue<Object> queue
+ private ReferenceManager callback
+ @BeforeEach
void setUp() {
finalizeCounter = 0
testReference = new TestReference<Object>(new Object())
@@ -36,6 +38,7 @@ class ReferenceManagerTest extends GroovyTestCase {
callback = ReferenceManager.createCallBackedManager(queue)
}
+ @Test
void testCallbackManagerRemovesFromQueueAfterCreation() {
3.times {
queue.add(testReference)
@@ -45,6 +48,7 @@ class ReferenceManagerTest extends GroovyTestCase {
assert finalizeCounter == 3
}
+ @Test
void testCallbackManagerRemovesStalledEntriesFromQueue() {
5.times {
queue.add(testReference)
@@ -54,6 +58,7 @@ class ReferenceManagerTest extends GroovyTestCase {
assert finalizeCounter == 5
}
+ @Test
void
testThresholdManagerRemovesFromQueueAfterCreationWhenThresholdIsReached() {
ReferenceManager manager =
ReferenceManager.createThresholdedIdlingManager(queue, callback, 2)
2.times {
@@ -72,6 +77,7 @@ class ReferenceManagerTest extends GroovyTestCase {
assert finalizeCounter == 3
}
+ @Test
void
testThresholdManagerRemovesStalledEntriesFromQueueWhenThresholdIsReached() {
ReferenceManager manager =
ReferenceManager.createThresholdedIdlingManager(queue, callback, 2)
2.times {
@@ -99,6 +105,7 @@ class ReferenceManagerTest extends GroovyTestCase {
assert finalizeCounter == 4
}
+ @Test
void testCallbackManagerGuardsAgainstRecursiveQueueProcessing() {
// Populate queue with enough references that call back into
removeStallEntries
// so that would normally generate a StackOverflowError
@@ -116,6 +123,8 @@ class ReferenceManagerTest extends GroovyTestCase {
assert queue.size() == 0
}
+
//--------------------------------------------------------------------------
+
private static class TestQueue<T> extends ReferenceQueue<T> {
final List<T> entries = []
diff --git
a/src/test/org/codehaus/groovy/vmplugin/v8/InterfaceStaticMethodCallTest.groovy
b/src/test/org/codehaus/groovy/vmplugin/v8/InterfaceStaticMethodCallTest.groovy
index 1de0d2f222..371460b3a0 100644
---
a/src/test/org/codehaus/groovy/vmplugin/v8/InterfaceStaticMethodCallTest.groovy
+++
b/src/test/org/codehaus/groovy/vmplugin/v8/InterfaceStaticMethodCallTest.groovy
@@ -18,14 +18,17 @@
*/
package org.codehaus.groovy.vmplugin.v8
-import groovy.test.GroovyTestCase
+import org.junit.jupiter.api.Test
-class InterfaceStaticMethodCallTest extends GroovyTestCase {
+import static groovy.test.GroovyAssert.assertScript
+
+final class InterfaceStaticMethodCallTest {
+
+ @Test
void testStreamOf() {
// "of" is a static method declared on the interface, we only want to
be sure we can call the method
assertScript '''
import java.util.stream.Stream
-
assert Stream.of("1") instanceof Stream
'''
}
diff --git
a/src/test/org/codehaus/groovy/vmplugin/v8/PluginDefaultGroovyMethodsSCTest.groovy
b/src/test/org/codehaus/groovy/vmplugin/v8/PluginDefaultGroovyMethodsSCTest.groovy
deleted file mode 100644
index 3c22368cd3..0000000000
---
a/src/test/org/codehaus/groovy/vmplugin/v8/PluginDefaultGroovyMethodsSCTest.groovy
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.codehaus.groovy.vmplugin.v8
-
-import org.codehaus.groovy.classgen.asm.sc.StaticCompilationTestSupport
-
-class PluginDefaultGroovyMethodsSCTest
- extends PluginDefaultGroovyMethodsTest
- implements StaticCompilationTestSupport {
-}
diff --git
a/src/test/org/codehaus/groovy/vmplugin/v8/PluginDefaultGroovyMethodsTest.groovy
b/src/test/org/codehaus/groovy/vmplugin/v8/PluginDefaultGroovyMethodsTest.groovy
index 75e907bc5f..b0493a671b 100644
---
a/src/test/org/codehaus/groovy/vmplugin/v8/PluginDefaultGroovyMethodsTest.groovy
+++
b/src/test/org/codehaus/groovy/vmplugin/v8/PluginDefaultGroovyMethodsTest.groovy
@@ -18,13 +18,20 @@
*/
package org.codehaus.groovy.vmplugin.v8
-import groovy.transform.stc.StaticTypeCheckingTestCase
+import org.junit.jupiter.api.Test
-class PluginDefaultGroovyMethodsTest extends StaticTypeCheckingTestCase {
+import static groovy.test.GroovyAssert.assertScript
+
+final class PluginDefaultGroovyMethodsTest {
+
+ private final GroovyShell shell = GroovyShell.withConfig {
+ ast(groovy.transform.CompileStatic)
+ }
// GROOVY-7611
+ @Test
void testOptionalAsBoolean() {
- assertScript '''
+ assertScript shell, '''
boolean m() {
assert Optional.of('foo')
assert !Optional.empty()
@@ -42,97 +49,110 @@ class PluginDefaultGroovyMethodsTest extends
StaticTypeCheckingTestCase {
'''
}
+ @Test
void testStreamToList() {
- assertScript '''
+ assertScript shell, '''
def list = [1, 2, 3]
assert list == list.stream().toList()
'''
}
+ @Test
void testStreamToSet() {
- assertScript '''
+ assertScript shell, '''
def set = [1, 2, 3] as Set
assert set.sort() == set.stream().toSet().sort()
'''
}
+ @Test
void testBaseStreamToList() {
- assertScript '''
+ assertScript shell, '''
def list = [1, 2, 3]
assert list == Arrays.stream(list as int[]).toList()
'''
}
+ @Test
void testBaseStreamToSet() {
- assertScript '''
+ assertScript shell, '''
def set = [1, 2, 3] as Set
assert set.sort() == Arrays.stream(set as int[]).toSet().sort()
'''
}
+ @Test
void testObjectArrayToStream() {
- assertScript '''
+ assertScript shell, '''
def array = ["Hello", "World"] as Object[]
assert array == array.stream().toArray()
'''
- assertScript '''
+ assertScript shell, '''
def array = ["Hello", "World"] as String[]
assert array == array.stream().toArray()
'''
}
+ @Test
void testIntArrayToStream() {
- assertScript '''
+ assertScript shell, '''
def array = [1, 2] as int[]
assert array == array.stream().toArray()
'''
}
+ @Test
void testLongArrayToStream() {
- assertScript '''
+ assertScript shell, '''
def array = [1, 2] as long[]
assert array == array.stream().toArray()
'''
}
+ @Test
void testDoubleArrayToStream() {
- assertScript '''
+ assertScript shell, '''
def array = [1, 2] as double[]
assert array == array.stream().toArray()
'''
}
+ @Test
void testCharArrayToStream() {
- assertScript '''
+ assertScript shell, '''
def array = [65, 66] as char[]
assert array == array.stream().toArray()
'''
}
+ @Test
void testByteArrayToStream() {
- assertScript '''
+ assertScript shell, '''
def array = [65, 66] as byte[]
assert array == array.stream().toArray()
'''
}
+ @Test
void testShortArrayToStream() {
- assertScript '''
+ assertScript shell, '''
def array = [65, 66] as short[]
assert array == array.stream().toArray()
'''
}
+ @Test
void testBooleanArrayToStream() {
- assertScript '''
+ assertScript shell, '''
def array = [true, false] as boolean[]
assert array == array.stream().toArray()
'''
}
+ @Test
void testFloatArrayToStream() {
- assertScript '''
+ assertScript shell, '''
def array = [65, 66] as float[]
assert array == array.stream().toArray()
'''
diff --git a/src/test/org/codehaus/groovy/vmplugin/v9/ClassFinderTest.groovy
b/src/test/org/codehaus/groovy/vmplugin/v9/ClassFinderTest.groovy
index 6ce0d51494..6eb59b406f 100644
--- a/src/test/org/codehaus/groovy/vmplugin/v9/ClassFinderTest.groovy
+++ b/src/test/org/codehaus/groovy/vmplugin/v9/ClassFinderTest.groovy
@@ -20,95 +20,97 @@ package org.codehaus.groovy.vmplugin.v9
import org.codehaus.groovy.control.ResolveVisitor
import org.codehaus.groovy.vmplugin.VMPluginFactory
-import org.junit.Test
+import org.junit.jupiter.api.Test
import java.util.stream.Collectors
-class ClassFinderTest {
+import static org.junit.jupiter.api.Assertions.assertThrows
+
+final class ClassFinderTest {
+
@Test
void findGroovyClass() {
- Map<String, Set<String>> result =
ClassFinder.find(GroovySystem.location.toURI(), "groovy/lang")
- assert ["groovy/lang"] == result.get("GString")?.toList()
- assert null == result.get("GroovydocHolder")
+ Map<String, Set<String>> result =
ClassFinder.find(GroovySystem.location.toURI(), 'groovy/lang')
+ assert ['groovy/lang'] == result.get('GString')?.toList()
+ assert null == result.get('GroovydocHolder')
}
@Test
void findGroovyClass2() {
- Map<String, Set<String>> result =
ClassFinder.find(GroovySystem.location.toURI(), "groovy/util")
- assert ["groovy/util"] == result.get("NodeBuilder")?.toList()
+ Map<String, Set<String>> result =
ClassFinder.find(GroovySystem.location.toURI(), 'groovy/util')
+ assert ['groovy/util'] == result.get('NodeBuilder')?.toList()
}
@Test
void findGroovyClass3() {
- Map<String, Set<String>> result =
ClassFinder.find(org.codehaus.groovy.control.ResolveVisitor.location.toURI(),
"org/codehaus/groovy/control")
- assert ["org/codehaus/groovy/control"] ==
result.get("ResolveVisitor")?.toList()
+ Map<String, Set<String>> result =
ClassFinder.find(org.codehaus.groovy.control.ResolveVisitor.location.toURI(),
'org/codehaus/groovy/control')
+ assert ['org/codehaus/groovy/control'] ==
result.get('ResolveVisitor')?.toList()
}
@Test
void findGroovyClassRecursive() {
- Map<String, Set<String>> result =
ClassFinder.find(GroovySystem.location.toURI(), "groovy/lang", true)
- assert ["groovy/lang"] == result.get("GString")?.toList()
- assert ["groovy/lang/groovydoc"] ==
result.get("GroovydocHolder")?.toList()
+ Map<String, Set<String>> result =
ClassFinder.find(GroovySystem.location.toURI(), 'groovy/lang', true)
+ assert ['groovy/lang'] == result.get('GString')?.toList()
+ assert ['groovy/lang/groovydoc'] ==
result.get('GroovydocHolder')?.toList()
}
@Test
void findJavaClass() {
- Map<String, Set<String>> result =
ClassFinder.find(URI.create("jrt:/modules/java.base/"), "java/lang")
- assert ["java/lang"] == result.get("String")?.toList()
- assert null == result.get("MethodHandle")
+ Map<String, Set<String>> result =
ClassFinder.find(URI.create('jrt:/modules/java.base/'), 'java/lang')
+ assert ['java/lang'] == result.get('String')?.toList()
+ assert null == result.get('MethodHandle')
}
@Test
void findJavaClass2() {
- Map<String, Set<String>> result =
ClassFinder.find(URI.create("jrt:/modules/java.base/"), "java/util")
- assert ["java/util"] == result.get("Map")?.toList()
+ Map<String, Set<String>> result =
ClassFinder.find(URI.create('jrt:/modules/java.base/'), 'java/util')
+ assert ['java/util'] == result.get('Map')?.toList()
}
@Test
void findJavaClass3() {
- Map<String, Set<String>> result =
ClassFinder.find(URI.create("jrt:/modules/java.base/"), "java/io")
- assert ["java/io"] == result.get("InputStream")?.toList()
+ Map<String, Set<String>> result =
ClassFinder.find(URI.create('jrt:/modules/java.base/'), 'java/io')
+ assert ['java/io'] == result.get('InputStream')?.toList()
}
@Test
void findJavaClass4() {
- Map<String, Set<String>> result =
ClassFinder.find(URI.create("jrt:/modules/java.base/"), "java/net")
- assert ["java/net"] == result.get("Inet4Address")?.toList()
+ Map<String, Set<String>> result =
ClassFinder.find(URI.create('jrt:/modules/java.base/'), 'java/net')
+ assert ['java/net'] == result.get('Inet4Address')?.toList()
}
@Test
void findJavaClassRecursive() {
- Map<String, Set<String>> result =
ClassFinder.find(URI.create("jrt:/modules/java.base/"), "java/lang", true)
- assert ["java/lang/invoke"] == result.get("MethodHandle")?.toList()
+ Map<String, Set<String>> result =
ClassFinder.find(URI.create('jrt:/modules/java.base/'), 'java/lang', true)
+ assert ['java/lang/invoke'] == result.get('MethodHandle')?.toList()
}
@Test
void findJarClass() {
- Map<String, Set<String>> result =
ClassFinder.find(org.antlr.v4.runtime.tree.ParseTree.location.toURI(),
"org/antlr/v4/runtime/tree")
- assert ["org/antlr/v4/runtime/tree"] ==
result.get("ParseTree")?.toList()
- assert null == result.get("ParseTreePattern")
+ Map<String, Set<String>> result =
ClassFinder.find(org.antlr.v4.runtime.tree.ParseTree.location.toURI(),
'org/antlr/v4/runtime/tree')
+ assert ['org/antlr/v4/runtime/tree'] ==
result.get('ParseTree')?.toList()
+ assert null == result.get('ParseTreePattern')
}
@Test
void findJarClassRecursive() {
- Map<String, Set<String>> result =
ClassFinder.find(org.antlr.v4.runtime.tree.ParseTree.location.toURI(),
"org/antlr/v4/runtime/tree", true)
- assert ["org/antlr/v4/runtime/tree"] ==
result.get("ParseTree")?.toList()
- assert ["org/antlr/v4/runtime/tree/pattern"] ==
result.get("ParseTreePattern")?.toList()
+ Map<String, Set<String>> result =
ClassFinder.find(org.antlr.v4.runtime.tree.ParseTree.location.toURI(),
'org/antlr/v4/runtime/tree', true)
+ assert ['org/antlr/v4/runtime/tree'] ==
result.get('ParseTree')?.toList()
+ assert ['org/antlr/v4/runtime/tree/pattern'] ==
result.get('ParseTreePattern')?.toList()
}
@Test
void defaultImportClasses() {
Map<String, Set<String>> r1 =
VMPluginFactory.getPlugin().getDefaultImportClasses(ResolveVisitor.DEFAULT_IMPORTS)
as TreeMap<String, Set<String>>
-
assert (ResolveVisitor.DEFAULT_IMPORTS as List).sort() ==
r1.values().stream().flatMap(e -> e.stream()).collect(Collectors.toSet()).sort()
}
+ // GROOVY-9480
@Test
- void testGroovy9480() {
- try {
- ClassFinder.find(URI.create("file:/"), "NOT_EXISTS", "org/",
false, true)
- } catch (ClassFindFailedException e) {
- assert e.message.contains('Failed to find classes')
+ void noNoSuchFieldException() {
+ def e = assertThrows(ClassFindFailedException) {
+ ClassFinder.find(URI.create('file:/'), 'NOT_EXISTS', 'org/',
false, true)
}
+ assert e.message.contains('Failed to find classes')
}
}