Java Reference
In-Depth Information
D
This method invokes PendingOrder .
The updateDeliveryInfo() method creates and returns a PlaceOrderService-
Result that contains the status and the PendingOrder .
PlaceOrderService collaborates with the PendingOrderRepository and Pending-
Order classes. Implementing the PendingOrder and PendingOrderRepository
classes at this stage would be a distraction from implementing PlaceOrderService .
If we implemented the PendingOrder class we would have to dive into the details
of the business logic, and if we implemented PendingOrderRepository we would
have to deal with ORM issues. A better approach for the tests is for the Place-
OrderService to use mock object implementations.
To do this with jMock, however, we do need to at least define the PendingOrder-
Repository interface and write a stub implementation of PendingOrder . The Pend-
ingOrderRepository interface defines the findOrCreatePendingOrder() method:
E
public interface PendingOrderRepository {
PendingOrder findOrCreatePendingOrder(String pendingOrderId);
}
The PendingOrder class defines a stub for the updateDeliveryInfo() method,
which we will fill in later:
public class PendingOrder {
public boolean updateDeliveryInfo(Address deliveryAddress,
Date deliveryTime) {
return false;
}
}
The stub for the updateDeliveryInfo() method returns false .
Finishing the test
We've written the updateDeliveryInfo() method and defined the PendingOrder-
Repository interface and PendingOrder class, but at this point we need to revise the
test we wrote earlier. It no longer compiles because PlaceOrderServiceImpl 's con-
structor now expects to be passed a PendingOrderRepository . In addition, the test
must create and configure mocks for PendingOrder and PendingOrderRepository .
The mock PendingOrderRepository expects to have its findOrCreatePending-
Order() method called and returns a mock PendingOrder . PendingOrder expects to
have its updateDeliveryInfo() method called. Listing 3.4 shows the updated test.
 
 
Search WWH ::




Custom Search