\r
import static org.hamcrest.core.Is.is;\r
import static org.junit.Assert.assertThat;\r
+import static org.mockito.BDDMockito.given;\r
\r
import java.util.List;\r
\r
private static final Trip TO_BERLIN = new Trip();\r
\r
@Mock TripDAO tripDAO;\r
- @InjectMocks @Spy private TripService realTripService;\r
- private TripService tripService;\r
+ @InjectMocks @Spy private TripService tripService;\r
\r
@Before\r
public void setUp() {\r
- realTripService = new TripService(tripDAO);\r
- tripService = new TesteableTripService();\r
+ tripService = new TripService(tripDAO);\r
}\r
\r
@Test(expected=UserNotLoggedInException.class) public void\r
throw_an_exception_when_user_is_not_logged_in() { \r
- realTripService.getTripsByUser(UNUSED_USER, GUEST);\r
+ tripService.getTripsByUser(UNUSED_USER, GUEST);\r
}\r
\r
@Test public void\r
.withTrips(TO_BRAZIL)\r
.build();\r
\r
- List<Trip> friendTrips = realTripService.getTripsByUser(friend, REGISTERED_USER); \r
+ List<Trip> friendTrips = tripService.getTripsByUser(friend, REGISTERED_USER); \r
// You must always begin writing the assert.\r
// Remember: the assert must match the unit test method's name!!\r
// In this case, no trips must be returned.\r
.friendsWith(ANOTHER_USER, REGISTERED_USER)\r
.withTrips(TO_BRAZIL, TO_BERLIN)\r
.build();\r
+ given(tripDAO.tripsBy(friend)).willReturn(friend.trips());\r
\r
- List<Trip> friendTrips = realTripService.getTripsByUser(friend, REGISTERED_USER); \r
+ List<Trip> friendTrips = tripService.getTripsByUser(friend, REGISTERED_USER); \r
// You must always begin writing the assert.\r
// Remember: the assert must match the unit test method's name!!\r
// In this case, no trips must be returned.\r
assertThat(friendTrips.size(), is(2));\r
}\r
- \r
- private class TesteableTripService extends TripService {\r
-\r
- public TesteableTripService() {\r
- super(new TripDAO());\r
- }\r
-\r
- @Override\r
- protected List<Trip> tripsBy(User user) {\r
- return user.trips();\r
- }\r
- \r
- }\r
}\r