달력

4

« 2024/4 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
2009. 9. 9. 15:48

Mockito Tips TDD2009. 9. 9. 15:48

Stubbing consecutive calls
동일 메소드가 여러번 호출되고, 호출될 때 마다 다른 값을 반환하도록 설정하는 방법

    @Before
    public void before() {
        ...        
        when(articleRepository.findDeletedByOwnerHistoriesFor(targetDate))
            .thenReturn(deletedByOwnerHistoryList)
            .thenReturn(new ArrayList<DeletedByOwnerHistory>());
    }

위의 코드 예에서 articleRepository#findDeletedByOwnerHistoriesFor(targetDate)가 첫번째 호출될 때는 deletedByOwnerHistoryList를 반환하고, 그 이후로 호출될 때는 new ArrayList<DeletedByOwnerHistory>()를 반환한다.
:
Posted by codetemplate