You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2021/12/04 21:15:37 UTC
[groovy] branch master updated: GROOVY-10391: add test case
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 de0718d GROOVY-10391: add test case
de0718d is described below
commit de0718d4b122bc80d914f50fecc7f093801ccf0f
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sat Dec 4 15:15:30 2021 -0600
GROOVY-10391: add test case
---
.../groovy/runtime/InterfaceConversionTest.groovy | 74 +++++++++++++---------
1 file changed, 45 insertions(+), 29 deletions(-)
diff --git a/src/test/org/codehaus/groovy/runtime/InterfaceConversionTest.groovy b/src/test/org/codehaus/groovy/runtime/InterfaceConversionTest.groovy
index ffa9a0b..249c146 100644
--- a/src/test/org/codehaus/groovy/runtime/InterfaceConversionTest.groovy
+++ b/src/test/org/codehaus/groovy/runtime/InterfaceConversionTest.groovy
@@ -18,44 +18,60 @@
*/
package org.codehaus.groovy.runtime
-import groovy.test.GroovyTestCase
+import org.junit.Test
-import static groovy.test.GroovyAssert.isAtLeastJdk
+import static groovy.test.GroovyAssert.assertScript
-class InterfaceConversionTest extends GroovyTestCase {
+final class InterfaceConversionTest {
+ @Test
void testClosureConversion() {
- def c1 = { Object[] args -> args?.length }
- def c2 = c1 as InterfaceConversionTestFoo
- assert !(c1 instanceof InterfaceConversionTestFoo)
- assert c2 instanceof InterfaceConversionTestFoo
- assert c2.a() == 0
- assert c2.b(null) == null
+ assertScript '''
+ interface I {
+ def a()
+ def b(Integer i)
+ }
+ def c = { Object[] args -> args?.length }
+ def i = c as I
+ assert c !instanceof I
+ assert i instanceof I
+ assert i.a() == 0
+ assert i.b(null) == null
+ '''
}
+ @Test
void testMapConversion() {
- def m1 = [a: { 1 }, b: { 2 }]
- def m2 = m1 as InterfaceConversionTestFoo
-
- assert !(m1 instanceof InterfaceConversionTestFoo)
- assert m2 instanceof InterfaceConversionTestFoo
- assert m2.a() == 1
- assert m2.b(null) == 2
+ assertScript '''
+ interface I {
+ def a()
+ def b(Integer i)
+ }
+ def m = [a: { 1 }, b: { 2 }]
+ def i = m as I
+ assert m !instanceof I
+ assert i instanceof I
+ assert i.a() == 1
+ assert i.b(null) == 2
+ '''
}
- //GROOVY-7104
+ @Test // GROOVY-7104
void testDefaultInterfaceMethodCallOnProxy() {
- // reversed is a default method within the Comparator interface for 1.8+
- if (!isAtLeastJdk("1.8")) return
- Comparator c1 = { a, b -> a <=> b }
- assert c1.compare("a", "b") == -1
- def c2 = c1.reversed()
- assert c2.compare("a", "b") == 1
+ assertScript '''
+ Comparator<?> c = { a,b -> a <=> b }
+ assert c.compare("x","y") < 0
+ c = c.reversed() // default method
+ assert c.compare("x","y") > 0
+ '''
}
-}
-
-interface InterfaceConversionTestFoo {
- def a()
- def b(Integer i)
-}
\ No newline at end of file
+ @Test // GROOVY-10391
+ void testDefaultInterfaceMethodCallOnProxy2() {
+ assertScript '''
+ java.util.function.Predicate<?> p = { q -> false }
+ def not = p.negate() // default method
+ assert not.test("x")
+ '''
+ }
+}