From 347102b96e59f4e05f2a1cfee9a7ede257931602 Mon Sep 17 00:00:00 2001 From: Gustavo Martin Morcuende Date: Fri, 25 Nov 2016 00:08:26 +0100 Subject: [PATCH] isFriendsWith(user) method added to User --- .../org/craftedsw/tripservicekata/user/User.java | 4 ++++ .../craftedsw/tripservicekata/user/UserShould.java | 28 +++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/TDD/src/main/java/org/craftedsw/tripservicekata/user/User.java b/TDD/src/main/java/org/craftedsw/tripservicekata/user/User.java index c0442ff..d038fe8 100644 --- a/TDD/src/main/java/org/craftedsw/tripservicekata/user/User.java +++ b/TDD/src/main/java/org/craftedsw/tripservicekata/user/User.java @@ -26,4 +26,8 @@ public class User { return trips; } + public boolean isFriendsWith(User anotherUser) { + return friends.contains(anotherUser); + } + } diff --git a/TDD/src/test/java/org/craftedsw/tripservicekata/user/UserShould.java b/TDD/src/test/java/org/craftedsw/tripservicekata/user/UserShould.java index 28b2a37..dfe2aee 100644 --- a/TDD/src/test/java/org/craftedsw/tripservicekata/user/UserShould.java +++ b/TDD/src/test/java/org/craftedsw/tripservicekata/user/UserShould.java @@ -1,5 +1,31 @@ package org.craftedsw.tripservicekata.user; -public class UserTest { +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; +import org.craftedsw.tripservicekata.UserBuilder; +import org.junit.Test; + +public class UserShould { + + private static final User JOHN = new User(); + private static final User PAUL = new User(); + + @Test public void + inform_when_users_are_not_friends() { + User user = UserBuilder.aUser() + .friendsWith(JOHN) + .build(); + + assertThat(user.isFriendsWith(PAUL), is(false)); + } + + @Test public void + inform_when_users_are_friends() { + User user = UserBuilder.aUser() + .friendsWith(JOHN, PAUL) + .build(); + + assertThat(user.isFriendsWith(PAUL), is(true)); + } } -- 2.1.4