Skip to content

Commit

Permalink
[#52] feat: follow 확인 기능 구현 및 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
jinyoungchoi95 committed Sep 20, 2021
1 parent 8b1b6e3 commit ad0f5b4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/main/java/com/study/realworld/user/domain/User.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public void login(Password rawPassword, PasswordEncoder passwordEncoder) {
this.password.matchPassword(rawPassword, passwordEncoder);
}

public boolean isFollow(User user) {
return followingUsers.contains(user);
}

public void followingUser(User user) {
checkFollowingUser(user);
followingUsers.add(user);
Expand Down
25 changes: 25 additions & 0 deletions src/test/java/com/study/realworld/user/domain/UserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

import com.study.realworld.global.exception.BusinessException;
Expand Down Expand Up @@ -195,6 +196,30 @@ void unfollowingNotExceptionTest() {
.withMessageMatching("not follow user exception");
}

@Test
@DisplayName("follow 여부를 확인할 수 있다.")
void isFollowTest() {

// given
User user = User.Builder()
.profile(Username.of("username"), null, null)
.password(Password.of("password"))
.email(Email.of("[email protected]"))
.build();
User followingUser = User.Builder()
.profile(Username.of("followingUser"), null, null)
.password(Password.of("password"))
.email(Email.of("[email protected]"))
.build();
user.followingUser(followingUser);

// when
boolean result = user.isFollow(followingUser);

// then
assertTrue(result);
}

@Test
@DisplayName("equals hashCode 테스트")
void userEqualsHashCodeTest() {
Expand Down

0 comments on commit ad0f5b4

Please sign in to comment.