RFR: nestmates and methodhandles
Stas Smirnov
stanislav.smirnov at oracle.com
Thu Feb 25 17:24:59 UTC 2016
Bria, Maurizio,
thanks for you feedback.
Brian, good catch, let me take a closer look on TestNG, originally for
me TestNG was good in terms of generating presets of data, but probably
it is applicable here as well to unities the test cases.
Maurizio, thanks for you suggestion, but since the target method throws
an exception, invocation of
inner.getSuperMethodMH(METHOD_NAME_PROTECTED) must be surrounded with
try-catch block, no? and in this case it does not make much sense
On 25/02/16 18:39, Maurizio Cimadamore wrote:
> 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
>>>
>>
>
--
Best regards,
Stanislav
More information about the valhalla-dev
mailing list