From 7a692c53946efdd32d792be3c34132ae3130f1f7 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Sun, 20 Nov 2016 23:44:01 +0100 Subject: [PATCH] We test the next branch. Remember: the assert must match the unit test method's name!! In this case, no trips must be returned. --- .../tripservicekata/trip/TripServiceShould.java | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java b/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java index 58ee787..136c953 100644 --- a/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java +++ b/TDD/src/test/java/org/craftedsw/tripservicekata/trip/TripServiceShould.java @@ -1,5 +1,10 @@ package org.craftedsw.tripservicekata.trip; +import static org.junit.Assert.assertThat; +import static org.hamcrest.core.Is.is; + +import java.util.List; + import org.craftedsw.tripservicekata.exception.UserNotLoggedInException; import org.craftedsw.tripservicekata.user.User; import org.junit.Test; @@ -8,6 +13,9 @@ public class TripServiceShould { private static final User GUEST = null; private static final User UNUSED_USER = null; + private static final User REGISTERED_USER = new User(); + private static final User ANOTHER_USER = new User(); + private static final Trip TO_BRAZIL = new Trip(); private User loggedInUser; @Test(expected=UserNotLoggedInException.class) public void @@ -19,6 +27,23 @@ public class TripServiceShould { tripService.getTripsByUser(UNUSED_USER); } + @Test public void + not_return_any_trips_when_users_are_not_friends() { + TesteableTripService tripService = new TesteableTripService(); + + loggedInUser = REGISTERED_USER; + + User friend = new User(); + friend.addFriend(ANOTHER_USER); + friend.addTrip(TO_BRAZIL); + + List friendTrips = tripService.getTripsByUser(friend); + // You must always begin writing the assert. + // Remember: the assert must match the unit test method's name!! + // In this case, no trips must be returned. + assertThat(friendTrips.size(), is(0)); + } + private class TesteableTripService extends TripService { @Override -- 2.1.4