Java Reference
In-Depth Information
.with(eq(PlaceOrderStatusCodes.OK),
eq(pendingOrder))
.will(returnValue(
bbbbbbbbbbb
b
➥
resultFactoryResult));
E
Defines expectations
for mocks
PlaceOrderFacadeResult result =
placeOrderFacade
.updateRestaurant(pendingOrderId,
restaurantId);
F
Calls
façade
G
Verifies
result
assertSame(resultFactoryResult, result);
}
…
Let's look at the details:
B
The
setUp()
method creates the mock implementations of the
RestaurantRepos-
itory
,
PlaceOrderService
, and
PlaceOrderFacadeResultFactory
classes.
The
setUp()
method creates the
PlaceOrderFacade
, passing the mock
PlaceOrder-
Service
and
PlaceOrderFacadeResultFactory
to its constructor.
The
testUpdateRestaurant()
method configures the expectations of each mock
object and the return value of each method. For example, it specifies that the
PlaceOrderService
is called once with the same parameters that were passed to
the
PlaceOrderFacade
and that it should return an
UpdateDeliveryResult
indicat-
ing a successful outcome.
The test then calls the
PlaceOrderFacade
.
The test verifies that it returns the result of the
PlaceOrderFacadeResultFactory
.
The
MockObjectTestCase
automatically verifies that the
mockPlaceOrderService
and
mockPlaceOrderFacadeResultFactory
are called as expected.
The next step is to write the method.
C
D
E
F
G
7.4.2
Implementing updateRestaurant()
In order for this test to compile and run successfully, we have to define the
Place-
OrderFacadeImpl
class and implement its constructor and the
updateRestaurant()
method. The constructor stores its parameters in fields, and the
updateRestau-
rant()
method calls
PlaceOrderService
and the
PlaceOrderFacadeResultFactory
.
Here is an excerpt of the source code for
PlaceOrderFacadeImpl
:
public class PlaceOrderFacadeImpl implements PlaceOrderFacade {
private PlaceOrderFacadeResultFactory resultFactory;
Search WWH ::
Custom Search