Skip to content

Instantly share code, notes, and snippets.

@anpieber
Created December 30, 2010 15:54
Show Gist options
  • Save anpieber/759918 to your computer and use it in GitHub Desktop.
Save anpieber/759918 to your computer and use it in GitHub Desktop.
specification for proxyhelper
@Test
public void testMethodCallPointingToToStringMethod_ShouldReturnOriginalValue() throws Exception {
Object originalObject = new Object();
Object[] args = null;
Method methodMock = mock(Method.class);
when(methodMock.getName()).thenReturn("toString");
when(methodMock.invoke(originalObject, args)).thenReturn("TestValue");
ProxyObjectMethodMirror proxyObjectMethodMirror = new ProxyObjectMethodMirror(objectMock, methodMock, args);
assertTrue(proxyObjectMethodMirror.isMethodObjectMethod());
assertEquals("TestValue",proxyObjectMethodMirror.executeMethod());
}
@Test
public void testMethodCallPointingToWaitMethod_ShouldCallOriginalWaitMethod() throws Exception {
Object originalObject = new Object();
Object[] args = new Object[]{ 12 };
Method methodMock = mock(Method.class);
when(methodMock.getName()).thenReturn("toString");
ProxyObjectMethodMirror proxyObjectMethodMirror = new ProxyObjectMethodMirror(objectMock, methodMock, args);
assertTrue(proxyObjectMethodMirror.isMethodObjectMethod());
proxyObjectMethodMirror.executeMethod(args);
verify(methodMock).invoke(originalObject, args);
}
@Test
public void testMethodCallPointingToNonObjectMethod_shouldReturnFalseOnIsMethodObjectMethod() throws Exception {
Object originalObject = new Object();
Object[] args = null;
Method methodMock = mock(Method.class);
when(methodMock.getName()).thenReturn("anythingElse");
ProxyObjectMethodMirror proxyObjectMethodMirror = new ProxyObjectMethodMirror(objectMock, methodMock, args);
assertFalse(proxyObjectMethodMirror.isMethodObjectMethod());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment