| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import jpype |
| 19 |
import common |
| 20 |
|
| 21 |
|
| 22 |
def callFunctional(cls, i): |
| 23 |
fun = cls @(lambda x: x) |
| 24 |
return fun.call(i) |
| 25 |
|
| 26 |
|
| 27 |
class FunctionalTestCase(common.JPypeTestCase): |
| 28 |
|
| 29 |
def _checkValidFunctional(self, name, value): |
| 30 |
cls = jpype.JClass("jpype.functional." + name) |
| 31 |
self.assertEqual(callFunctional(cls, value), value) |
| 32 |
|
| 33 |
def testAnnotated(self): |
| 34 |
self._checkValidFunctional("Annotated", 0) |
| 35 |
|
| 36 |
def testNonAnnotated(self): |
| 37 |
self._checkValidFunctional("NonAnnotated", 1) |
| 38 |
|
| 39 |
def testExtendsFunctional(self): |
| 40 |
self._checkValidFunctional("ExtendsFunctional", 2) |
| 41 |
|
| 42 |
def testExtendsNonFunctional(self): |
| 43 |
with self.assertRaises(TypeError): |
| 44 |
self._checkValidFunctional("ExtendsNonFunctional", 3) |
| 45 |
|
| 46 |
def testAnnotatedWithObjectMethods(self): |
| 47 |
self._checkValidFunctional("AnnotatedWithObjectMethods", 4) |
| 48 |
|
| 49 |
def testNonAnnotatedWithObjectMethods(self): |
| 50 |
self._checkValidFunctional("NonAnnotatedWithObjectMethods", 5) |
| 51 |
|
| 52 |
def testRedeclaresAnnotated(self): |
| 53 |
self._checkValidFunctional("RedeclaresAnnotated", 6) |
| 54 |
|
| 55 |
def testRedeclaresNonAnnotated(self): |
| 56 |
self._checkValidFunctional("RedeclaresNonAnnotated", 7) |
| 57 |
|
| 58 |
def testStaticDefaultMethods(self): |
| 59 |
|
| 60 |
Predicate = jpype.JClass("java.util.function.Predicate") |
| 61 |
fun = Predicate @ (lambda x: True) |
| 62 |
self.assertTrue(fun.test(fun)) |