Exemplo n.º 1
0
  @Test
  public void return_friend_trips_when_users_are_friends() {
    User friend =
        UserBuilder.aUser()
            .friendsWith(ANOTHER_USER, REGISTERED_USER)
            .withTrips(TO_BRAZIL, TO_BERLIN)
            .build();
    given(tripDAO.tripsBy(friend)).willReturn(friend.trips());

    List<Trip> friendTrips = tripService.getTripsByUser(friend, REGISTERED_USER);
    // 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(2));
  }
Exemplo n.º 2
0
  public List<Trip> getTripsByUser(User user, User loggedInUser) throws UserNotLoggedInException {

    if (loggedInUser == null) {
      throw new UserNotLoggedInException();
    }

    return user.isFriendWith(loggedInUser) ? tripsBy(user) : noTrips();
  }