From: Gustavo Martin Morcuende Date: Thu, 24 Nov 2016 23:08:26 +0000 (+0100) Subject: isFriendsWith(user) method added to User X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=347102b96e59f4e05f2a1cfee9a7ede257931602;p=JavaForFun isFriendsWith(user) method added to User --- 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)); + } }