Java Reference
In-Depth Information
F
The test calls the transaction script.
G
The
testUpdateDeliveryInfo_good()
method verifies that the transaction script
returns an
UpdateDeliveryInfoResult
containing the expected data.
The tests for the other scenarios are similar. They configure mock objects, call
updateDeliveryInfo()
with other combinations of arguments, and assert that the
method returns the expected value. Let's now look at the
updateDeliveryInfo()
method.
9.3.2
Writing the transaction script
Now that we have written a test, the next step is to get it to compile and pass. To
do that we must implement the
updateDeliveryInfo()
transaction script, as well
as the
DTO
s. Let's look at how to do that, beginning with the transaction script.
Writing the updateDeliveryInfo() method
The
updateDeliveryInfo()
method is one of the transaction scripts implemented
by the
PlaceOrderTransactionScriptsImpl
. Listing 9.2 shows
PlaceOrderTransac-
tionScriptsImpl
's constructor and the
updateDeliveryInfo()
transaction script.
The constructor takes a
PendingOrderDAO
and a
RestaurantDAO
as parameters and
stores them in fields for use by the transaction scripts. The
updateDeliveryInfo()
transaction script finds or creates the
PendingOrder
; finds the available restau-
rants; updates the
PendingOrder
if the delivery information is valid; and returns
the
UpdateDeliveryInfoResult
.
Listing 9.2
PlaceOrderTransactionScriptsImpl
public class PlaceOrderTransactionScriptsImpl implements
PlaceOrderTransactionScripts {
private RestaurantDAO restaurantDAO;
private PendingOrderDAO pendingOrderDAO;
public PlaceOrderTransactionScriptsImpl(
PendingOrderDAO pendingOrderDAO,
RestaurantDAO restaurantDAO) {
this.pendingOrderDAO = pendingOrderDAO;
this.restaurantDAO = restaurantDAO;
}
public UpdateDeliveryInfoResult updateDeliveryInfo(
String pendingOrderId,
Address deliveryAddress, Date deliveryTime) {
Search WWH ::
Custom Search