public void testDefaultResultsCanBeExplicitlyOverriddenByType() throws Throwable { int newDefaultIntResult = 20; String newDefaultStringResult = "hello"; stub.addResult(String.class, newDefaultStringResult); stub.addResult(int.class, new Integer(newDefaultIntResult)); assertEquals( "expected registered value for string result type", newDefaultStringResult, stub.invoke(invocationReturning(String.class))); assertEquals( "expected registered value for int result type", new Integer(newDefaultIntResult), stub.invoke(invocationReturning(int.class))); }
public void testAnExplicitlyRegisteredResultOverridesThePreviousResultForTheSameType() throws Throwable { stub.addResult(String.class, "result1"); stub.addResult(String.class, "result2"); assertEquals( "expected second result", "result2", stub.invoke(invocationReturning(String.class))); }
// Inspired by http://www.c2.com/cgi/wiki?JavaNullProxy public void testReturnsProxyOfNewMockObjectWithSameDefaultResultStubForInterfaceTypes() throws Throwable { int intResult = -1; stub.addResult(int.class, new Integer(intResult)); InterfaceType result = (InterfaceType) stub.invoke(invocationReturning(InterfaceType.class)); assertEquals("int result from 'null' interface implementation", intResult, result.returnInt()); }