@Test public void exerciseTestedObjectAgain(@Injectable("Another test") String text) { assertThatGeneratedSubclassIsAlwaysTheSame(); assertEquals(123, tested.getValue()); assertEquals("Another test", tested.name); assertFalse(tested.doSomeOperation()); new FullVerificationsInOrder() { { tested.run(); tested.doSomething(); } }; }
void assertThatGeneratedSubclassIsAlwaysTheSame() { Class<?> testedClass = tested.getClass(); if (generatedSubclass == null) { generatedSubclass = testedClass; } else { assertSame(generatedSubclass, testedClass); } }
@Test public void exerciseTestedObject(@Injectable("Test") String name) { assertThatGeneratedSubclassIsAlwaysTheSame(); assertEquals(123, tested.getValue()); assertEquals("Test", tested.name); new Expectations() { { tested.doSomething(); result = 23; times = 1; } }; assertTrue(tested.doSomeOperation()); new Verifications() { { tested.run(); } }; }
@Test public void exerciseDynamicallyMockedTestedObject() { assertThatGeneratedSubclassIsAlwaysTheSame(); assertEquals(123, tested.getValue()); new Expectations(tested) { { tested.getValue(); result = 45; tested.doSomething(); result = 7; } }; assertEquals(45, tested.getValue()); assertTrue(tested.doSomeOperation()); new Verifications() { { tested.run(); times = 1; } }; }