====== Mockito ====== [[https://site.mockito.org/|Official site]] ===== Mocks ===== ===== Spies ===== ===== Argument Matchers ===== * we can configure our mocked methods with argument matchers when(flowerService.analyze(anyString())).thenReturn("Flower"); * **We can't use argument matchers as a return value**, an exact value is required when stubbing calls * we can't use argument matchers outside of verification or stubbing ===== BDDMockito ===== Links: * [[https://static.javadoc.io/org.mockito/mockito-core/3.0.0/org/mockito/BDDMockito.html|BDDMockito]] - JavaDoc * https://riptutorial.com/mockito/topic/2055/getting-started-with-mockito BDD-phases: * given * when * then 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()); }