package testcode; import static org.junit.Assert.assertEquals; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import org.junit.Test; class TestClass { public int f(int x) { return x + 1; } } /** * Test for mockito translator. This program is going to be translated and run * in python. */ public class MockitoBasicTest { /** * NOTE NO CONSTRUCTOR. This is needed to check that the proper constructor, * matching in this case the implicit superclass TestCase from Python, is * created. This is a special case, in normal cases java already enforces * all required code including the call to super(). */ @Test public void testStub1() { TestClass test = mock(TestClass.class); when(test.f(3)).thenReturn(1); // the mock did not do any when.thenReturn and should fail assertEquals(1, test.f(3)); } }