LoginSignup
0
0

Java memo

Posted at
public class MainServiceTest {
    private SubService subService;
    private MainService mainService;

    @BeforeEach
    public void setUp() {
        subService = Mockito.mock(SubService.class);
        mainService = new MainService(subService);
    }

    @Test
    public void testExecuteCallsPerformActionTwiceWithDifferentReturnValues() {
        // 1回目の呼び出しは0を返し、2回目の呼び出しは1を返すように設定
        when(subService.performAction()).thenReturn(0).thenReturn(1);

        int[] results = mainService.execute();

        assertEquals(0, results[0]);
        assertEquals(1, results[1]);

        verify(subService, times(2)).performAction();
    }
}
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0