Java Reference
In-Depth Information
Let's look at the details:
B
The setup() method creates the mock JdoTemplate , the JdoRestaurant-
Repository , and the delivery information that is used for the test.
The testFindAvailableRestaurants() method creates the list of restaurants
that is returned by ExecuteNamedQueryWithMapCallback and that should be
returned by the repository.
This calls makeExpectedCallback() to create the ExecuteNamedQueryWith-
MapCallback that should be passed to the JdoTemplate . The makeExpected-
Callback() method creates an ExecuteNamedQueryWithMapCallback that
specifies the Restaurant class, the Restaurant.findAvailableRestaurants
query, and the query's parameters, which consist of the delivery information's ZIP
code, day of the week, hour, and minute.
The testFindAvailableRestaurants() method configures the mock JdoTem-
plate to expect its execute() method to be called with an ExecuteNamedQuery-
WithMapCallback and to return the list of restaurants.
This calls findAvailableRestaurants() and verifies that it returns the expected
list of restaurants.
C
D
E
F
5.3.2
Implementing JDORestaurantRepositoryImpl
The next step is to write the JDORestaurantRepositoryImpl class and the
findRestaurants() method. This will be easy since we had to decide how it
worked in order to write the test. Listing 5.6 shows the JDORestaurantReposi-
tory class, which uses the JdoTemplate class to execute an instance of the Exe-
cuteNamedQueryWithMapCallback class.
Listing 5.6
The JDORestaurantRepository class
public class JDORestaurantRepositoryImpl extends JdoDaoSupport
implements RestaurantRepository {
public JDORestaurantRepositoryImpl
(JdoTemplate jdoTemplate) {
setJdoTemplate(jdoTemplate);
}
B Creates
JDORestaurantRepositoryImpl
public List findAvailableRestaurants(Address deliveryAddress,
Date deliveryTime) {
Calendar c = Calendar.getInstance();
c.setTime(deliveryTime);
int dayOfWeek =
C Creates
parameters
 
 
Search WWH ::




Custom Search