RFR: nestmates and methodhandles
Maurizio Cimadamore
maurizio.cimadamore at oracle.com
Thu Feb 25 15:39:47 UTC 2016
Or, at least, code duplication can be reduced by using a lambda-friendly
method could be used for testing:
void check(Runnable r, Class<? extends Exception> exClass) {
try {
r.run();
} catch (Exception ex) {
Asserts.assertEquals(exClass, ex);
}
}
which you can run as follows:
check(() -> inner.getSuperMethodMH(METHOD_NAME_PROTECTED),
NoSuchMethodException.class);
Maurizio
On 25/02/16 14:39, Brian Goetz wrote:
> Can I suggest doing this in TestNG? You'll be far more productive --
> and failures are easier to debug. You can use sophisticated asserts
> rather than just comparing to a golden file. jtreg already supports
> TestNG tests.
>
> For example, each of the negative tests (try-catch-assert expected)
> can be its own test method, and TestNG has a way to mark a test method
> as expected to throw an exception. So these could be written:
>
> @Test(expectedExceptions = ClassNotFoundException.class)
> public void testProtectedMethodNeg() {
> inner.getSuperMethodMH(METHOD_NAME_PROTECTED);
> }
>
> It's far more clear what's going on, and each one is its own test
> case, meaning that you can pinpoint a failure more easily.
>
> Happy to help you get up to speed on TestNG if that helps.
>
> On 2/25/2016 8:12 AM, Stas Smirnov wrote:
>> Hello,
>>
>> please review this set of tests to verify "parent-child" access using
>> MethodHandle in terms of nestmates vm exploration.
>> 1. MethodHandleSubTop class contains methods to verify
>> private/protected methods/fields of the "super" class using
>> MethodHandle from a single one and double level of nesting using
>> access static bridges and direct access in negative and positive test
>> cases
>> 2. MethodHandleInheritTest executes a number of positive and negative
>> test cases using MethodHandleSubTop methods
>> it will allow us to verify current implementation and future, when
>> access bridges will be removed and MethodHandle access checks will be
>> modified.
>>
>> webrev: http://cr.openjdk.java.net/~stsmirno/nestmates/webrev.01
>> Testing: RBT
>>
>
More information about the valhalla-dev
mailing list