Пример #1
0
  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)));
  }
Пример #2
0
  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)));
  }
Пример #3
0
  // 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());
  }