From 8f364b5a0d76345446ba488a3946734e4901d53b Mon Sep 17 00:00:00 2001 From: Charles Wright Date: Wed, 6 Sep 2017 08:08:52 -0400 Subject: [PATCH] Test for default interfaces. --- .../DefaultInterfaceImplTestFixture.java | 31 +++++++++++++++++ .../fixtures/DefaultInterfaceTestFixture.java | 33 +++++++++++++++++++ src/test/python/jpy_overload_test.py | 10 ++++++ 3 files changed, 74 insertions(+) create mode 100644 src/test/java/org/jpy/fixtures/DefaultInterfaceImplTestFixture.java create mode 100644 src/test/java/org/jpy/fixtures/DefaultInterfaceTestFixture.java diff --git a/src/test/java/org/jpy/fixtures/DefaultInterfaceImplTestFixture.java b/src/test/java/org/jpy/fixtures/DefaultInterfaceImplTestFixture.java new file mode 100644 index 0000000000..84ac8001e6 --- /dev/null +++ b/src/test/java/org/jpy/fixtures/DefaultInterfaceImplTestFixture.java @@ -0,0 +1,31 @@ +/* + * Copyright 2015 Brockmann Consult GmbH + * + * Licensed 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.jpy.fixtures; + +import static org.jpy.fixtures.MethodOverloadTestFixture.stringifyArgs; + +/** + * Used as a test class for the test cases in jpy_overload_test.py + * + * @author Charles Wright + */ +@SuppressWarnings("UnusedDeclaration") +public class DefaultInterfaceImplTestFixture implements DefaultInterfaceTestFixture { + public int doIt() { + return 2; + } +} diff --git a/src/test/java/org/jpy/fixtures/DefaultInterfaceTestFixture.java b/src/test/java/org/jpy/fixtures/DefaultInterfaceTestFixture.java new file mode 100644 index 0000000000..9e36c24ee2 --- /dev/null +++ b/src/test/java/org/jpy/fixtures/DefaultInterfaceTestFixture.java @@ -0,0 +1,33 @@ +/* + * Copyright 2015 Brockmann Consult GmbH + * + * Licensed 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.jpy.fixtures; + +import static org.jpy.fixtures.MethodOverloadTestFixture.stringifyArgs; + +/** + * Used as a test class for the test cases in jpy_overload_test.py + * + * @author Charles Wright + */ +@SuppressWarnings("UnusedDeclaration") +public interface DefaultInterfaceTestFixture { + int doIt(); + + default public int doItPlusOne() { + return 1 + doIt(); + } +} diff --git a/src/test/python/jpy_overload_test.py b/src/test/python/jpy_overload_test.py index f865ebd75f..4a7c774418 100644 --- a/src/test/python/jpy_overload_test.py +++ b/src/test/python/jpy_overload_test.py @@ -129,6 +129,16 @@ def test_toReproduceAndFixIssue54(self): # without the fix, we get str(s) = "java.lang.String@xxxxxx" self.assertEqual(str(s), '[A, B, C]') +class TestDefaultMethods(unittest.TestCase): + def setUp(self): + self.Fixture = jpy.get_type('org.jpy.fixtures.DefaultInterfaceImplTestFixture') + self.assertIsNotNone(self.Fixture) + + # see https://github.com/bcdev/jpy/issues/102 + def test_defaultedInterfaces(self): + fixture = self.Fixture() + self.assertEqual(fixture.doItPlusOne(), 3) + if __name__ == '__main__': print('\nRunning ' + __file__)