Last active
February 10, 2020 05:33
-
-
Save justisr/1a8b5faf318f6da5b14a7356da49444e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
final class AccessorTest { | |
@Test // SUCCESS | |
@DisplayName("Verify MethodHandles.Lookup constructor") | |
void lookupConstructorAvailabilityTest() { | |
Assertions.assertDoesNotThrow(() -> Accessor.newLookupConstructor()); | |
} | |
@Test // SUCCESS | |
@DisplayName("Verify available matching instance method is called") | |
void findMatchingMethodAndCallTest() { | |
ObjectAccessor accessor = Accessor.to(ObjectAccessor.class, TestObject.class, "instanceMethod"); | |
Assertions.assertNotNull(accessor); | |
Assertions.assertTrue(accessor.instanceMethod(new TestObject())); | |
} | |
@Test // SUCCESS | |
@DisplayName("Verify available matching static method is called") | |
void findMatchingStaticMethodAndCallTest() { | |
ObjectAccessor accessor = Accessor.to(ObjectAccessor.class, TestObject.class, "staticMethod"); | |
Assertions.assertNotNull(accessor); | |
Assertions.assertTrue(accessor.staticMethod()); | |
} | |
@Test // FAILURE | |
@DisplayName("Verify java.lang.Object#toString works") | |
void testDynamicToStringInvokation() { | |
ToString accessor = Accessor.to(ToString.class, Object.class, "toString"); | |
// ^ java.lang.NoClassDefFoundError: com/gmail/justisroot/autoecon/data/AccessorTest$ToString | |
Assertions.assertNotNull(accessor); | |
Assertions.assertEquals(accessor.toString(Integer.valueOf(42)), Integer.valueOf(42)); | |
} | |
public interface ObjectAccessor { | |
public boolean instanceMethod(TestObject o); | |
public boolean staticMethod(); | |
} | |
public interface ToString { | |
public String toString(Object o); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment