Java Reference
In-Depth Information
This method returns true if there is at least one restaurant that serves the speci-
fied delivery information. We also have to change PlaceOrderService to take Res-
taurantRespository as a constructor parameter and pass it to PendingOrder and
change its tests to use a mock RestaurantRepository .
Revising the test
After writing PendingOrder 's method, we only have one thing left to do. We must go
back to its test and change it to create and configure the required mock objects.
This test, which is shown in listing 3.7, creates and configures a mock Restaurant-
Repository and passes it as an argument to the call to updateDeliveryInfo() .
Listing 3.7
Tests for the updateDeliveryInfo() method
public class PendingOrderTests extends MockObjectTestCase {
private Date goodDeliveryTime;
private Address goodDeliveryAddress;
private RestaurantRepository restaurantRepository;
private Mock mockRestaurantRepository;
private PendingOrder pendingOrder;
protected void setUp() throws Exception {
super.setUp();
pendingOrder = new PendingOrder();
Creates
PendingOrder
and test data
goodDeliveryAddress = RestaurantTestData.ADDRESS1;
goodDeliveryTime =
RestaurantTestData.
bbbbbb makeGoodDeliveryTime();
Creates mock
Restaurant
mockRestaurantRepository =
new Mock(RestaurantRepository.class);
restaurantRepository =
(RestaurantRepository) mockRestaurantRepository.proxy();
}
public void testUpdateDeliveryInfo_good() throws Exception {
mockRestaurantRepository
.expects(once())
.method("isRestaurantAvailable")
.with(eq(goodDeliveryAddress),
eq(goodDeliveryTime))
.will(returnValue(true));
Configures
expectations
boolean result =
pendingOrder.updateDeliveryInfo(
restaurantRepository,
Calls
updateDeliveryInfo()
 
 
Search WWH ::




Custom Search