Created
February 27, 2012 18:46
-
-
Save oleg/1926142 to your computer and use it in GitHub Desktop.
Mockito BDD style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package logic; | |
import org.junit.Assert; | |
import org.junit.Before; | |
import org.junit.Test; | |
import java.util.List; | |
import static org.hamcrest.CoreMatchers.is; | |
import static org.junit.matchers.JUnitMatchers.hasItem; | |
import static org.mockito.BDDMockito.given; | |
import static org.mockito.BDDMockito.mock; | |
public class BddTest extends Assert { | |
Seller seller; | |
Shop shop; | |
@Before | |
public void setUp() throws Exception { | |
seller = mock(Seller.class); | |
shop = new Shop(seller); | |
} | |
@Test | |
public void shouldBuyBread() throws Exception { | |
//given | |
given(seller.askForBread()).willReturn(new Bread()); | |
//when | |
List<Object> goods = shop.buyBread(); | |
//then | |
assertThat(goods, hasItem(is(Bread.class))); | |
} | |
private static class Seller { | |
public Bread askForBread() { | |
return null; | |
} | |
} | |
private static class Shop { | |
public Shop(Seller seller) { | |
} | |
public List<Object> buyBread() { | |
return null; | |
} | |
} | |
private static class Bread { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment