Table of Contents

Mockito

Official site

Mocks

Spies

Argument Matchers

when(flowerService.analyze(anyString())).thenReturn("Flower");

BDDMockito

Links:

BDD-phases:

import static org.mockito.BDDMockito.*;
 
Seller seller = mock(Seller.class);
Shop shop = new Shop(seller);
 
public void shouldBuyBread() throws Exception {
  //given
  given(seller.askForBread()).willReturn(new Bread());
 
  //when
  Goods goods = shop.buyBread();
 
  //then
  assertThat(goods, containBread());
}