Ejemplo n.º 1
0
  @Test
  public <T extends BaseAction> void test4_mockUpConcreteSubclassesUsingAnonymousMockUp() {
    actionB = new ConcreteAction1();

    new MockUp<T>() {
      @Mock
      int perform(int i) {
        return i + 1;
      }

      @Mock
      int toBeMockedAsWell() {
        return 123;
      }
    };

    assertEquals(2, actionB.perform(1));
    assertEquals(123, actionB.toBeMockedAsWell());
    assertEquals(1, actionB.notToBeMocked());

    ConcreteAction2 action2 = new ConcreteAction2();
    assertEquals(3, action2.perform(2));
    assertEquals(123, action2.toBeMockedAsWell());
    assertEquals(2, action2.notToBeMocked());

    ConcreteAction3 action3 = new ConcreteAction3();
    assertEquals(4, action3.perform(3));
    assertEquals(123, action3.toBeMockedAsWell());
    assertEquals(3, action3.notToBeMocked());
  }
Ejemplo n.º 2
0
  @Test
  public void test6_mockUpConcreteSubclassesUsingNamedMockUp() {
    new BaseClassMockUp();

    actionB = new ConcreteAction1();
    assertEquals(4, actionB.perform(1));
    assertEquals(5, new ConcreteAction2().perform(2));
    assertEquals(6, new ConcreteAction3().perform(3));
  }
Ejemplo n.º 3
0
  @After
  public void checkImplementationClassesAreNoLongerMocked() {
    if (actionI != null) {
      assertEquals(-1, actionI.perform(0));
    }

    assertEquals(-2, new ActionImpl2().perform(0));

    if (actionB != null) {
      assertEquals(-1, actionB.perform(0));
    }

    assertEquals(-2, new ConcreteAction2().perform(0));
    assertEquals(-3, new ConcreteAction3().perform(0));
  }