Skip to content

Commit

Permalink
Merge pull request #1641 from pdbain-ibm/test_common
Browse files Browse the repository at this point in the history
Add tests for findVirtual on interface concrete methods
  • Loading branch information
DanHeidinga authored Apr 13, 2018
2 parents 2b23e03 + a07582e commit 090fe35
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 1 deletion.
36 changes: 35 additions & 1 deletion test/Jsr292/src/com/ibm/j9/jsr292/LookupAPITests_Find.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2001, 2017 IBM Corp. and others
* Copyright (c) 2001, 2018 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
Expand Down Expand Up @@ -2359,6 +2359,40 @@ public void test_FindStatic_InitCheck() throws Throwable {
}
AssertJUnit.assertTrue(NoSuchMethodExceptionThrown);
}

/**
* Test getVirtual on a concrete method inherited from Object returns a valid method handle.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_findVirtual_on_interface_concreteMethods() throws Throwable {
MethodHandle mh = MethodHandles.lookup().findVirtual(TestInterface.class,
"hashCode", MethodType.methodType(int.class));
TestInterface receiver = new TestInterface() {
@Override
public void test() throws Throwable {
// empty
}
};
@SuppressWarnings("unused")
int result = (int)mh.invokeExact(receiver);
}

/**
* Test getVirtual on a default method returns a valid method handle.
* @throws Throwable
*/
@Test(groups = { "level.extended" })
public void test_findVirtual_on_interface_defaultMethods() throws Throwable {
MethodHandle mh =
MethodHandles.lookup().findVirtual(TestInterfaceWithDefaultMethod.class,
"test", MethodType.methodType(Integer.class));
TestInterfaceWithDefaultMethod receiver = new TestInterfaceWithDefaultMethod() {};
Integer result = (Integer) mh.invokeExact(receiver);
AssertJUnit.assertEquals("Wrong result from default method",
TestInterfaceWithDefaultMethod.FORTY_TWO, result);
}

}

class Find_StaticMethodHelper {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*******************************************************************************
* Copyright (c) 2014, 2018 IBM Corp. and others
*
* This program and the accompanying materials are made available under
* the terms of the Eclipse Public License 2.0 which accompanies this
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
* or the Apache License, Version 2.0 which accompanies this distribution and
* is available at https://www.apache.org/licenses/LICENSE-2.0.
*
* This Source Code may also be made available under the following
* Secondary Licenses when the conditions for such availability set
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
* General Public License, version 2 with the GNU Classpath
* Exception [1] and GNU General Public License, version 2 with the
* OpenJDK Assembly Exception [2].
*
* [1] https://www.gnu.org/software/classpath/license.html
* [2] http://openjdk.java.net/legal/assembly-exception.html
*
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
*******************************************************************************/
package com.ibm.j9.jsr292;

/**
* An Interface that is used with InterfaceHandleTest class
*/
public interface TestInterfaceWithDefaultMethod {
public static final Integer FORTY_TWO = 42;

public default Integer test() {
return FORTY_TWO;
}
}

0 comments on commit 090fe35

Please sign in to comment.