Guest User

Untitled

a guest
Jul 18th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. @Test
  2. public void testMethodCallPointingToToStringMethod_ShouldReturnOriginalValue() throws Exception {
  3. Object originalObject = new Object();
  4. Object[] args = null;
  5. Method methodMock = mock(Method.class);
  6. when(methodMock.getName()).thenReturn("toString");
  7. when(methodMock.invoke(originalObject, args)).thenReturn("TestValue");
  8. ProxyObjectMethodMirror proxyObjectMethodMirror = new ProxyObjectMethodMirror(objectMock, methodMock, args);
  9. assertTrue(proxyObjectMethodMirror.isMethodObjectMethod());
  10. assertEquals("TestValue",proxyObjectMethodMirror.executeMethod());
  11. }
  12.  
  13. @Test
  14. public void testMethodCallPointingToWaitMethod_ShouldCallOriginalWaitMethod() throws Exception {
  15. Object originalObject = new Object();
  16. Object[] args = new Object[]{ 12 };
  17. Method methodMock = mock(Method.class);
  18. when(methodMock.getName()).thenReturn("toString");
  19. ProxyObjectMethodMirror proxyObjectMethodMirror = new ProxyObjectMethodMirror(objectMock, methodMock, args);
  20. assertTrue(proxyObjectMethodMirror.isMethodObjectMethod());
  21. proxyObjectMethodMirror.executeMethod(args);
  22. verify(methodMock).invoke(originalObject, args);
  23. }
  24.  
  25. @Test
  26. public void testMethodCallPointingToNonObjectMethod_shouldReturnFalseOnIsMethodObjectMethod() throws Exception {
  27. Object originalObject = new Object();
  28. Object[] args = null;
  29. Method methodMock = mock(Method.class);
  30. when(methodMock.getName()).thenReturn("anythingElse");
  31. ProxyObjectMethodMirror proxyObjectMethodMirror = new ProxyObjectMethodMirror(objectMock, methodMock, args);
  32. assertFalse(proxyObjectMethodMirror.isMethodObjectMethod());
  33. }
Add Comment
Please, Sign In to add comment