diff --git a/src/main/java/com/study/realworld/domain/follow/domain/Follow.java b/src/main/java/com/study/realworld/domain/follow/domain/Follow.java index a30d68c7..be3b0081 100644 --- a/src/main/java/com/study/realworld/domain/follow/domain/Follow.java +++ b/src/main/java/com/study/realworld/domain/follow/domain/Follow.java @@ -2,14 +2,46 @@ import com.study.realworld.domain.user.domain.User; +import javax.persistence.*; + +@Entity public class Follow { + @Id @GeneratedValue(strategy = GenerationType.IDENTITY) + @Column(name = "follow_id", updatable = false) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "following_id") + @Column(name = "follow_following", nullable = false, updatable = false) private User following; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "follower_id") + @Column(name = "follow_follower", nullable = false, updatable = false) private User follower; protected Follow() { } + public Follow changeFollowing(final User following) { + this.following = following; + return this; + } + + public Follow changeFollower(final User follower) { + this.follower = follower; + return this; + } + + public User following() { + return following; + } + + public User follower() { + return follower; + } + private Follow(final FollowBuilder followBuilder) { following = followBuilder.following; follower = followBuilder.follower; diff --git a/src/test/java/com/study/realworld/domain/follow/domain/FollowTest.java b/src/test/java/com/study/realworld/domain/follow/domain/FollowTest.java index 8da8f938..01ea75f4 100644 --- a/src/test/java/com/study/realworld/domain/follow/domain/FollowTest.java +++ b/src/test/java/com/study/realworld/domain/follow/domain/FollowTest.java @@ -13,7 +13,7 @@ import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.*; -class FollowTest { +public class FollowTest { @DisplayName("Follow 인스턴스 기본 생성자 테스트") @Test @@ -29,13 +29,10 @@ void constructor_test() { @DisplayName("Follow 인스턴스 빌더 테스트") @Test void builder_test() { - final User user1 = userBuilder(new Email(EMAIL), new Name(USERNAME), new Password(PASSWORD), new Bio(BIO), new Image(IMAGE)); - final User user2 = userBuilder(new Email("Email2@email.com"), new Name("differentUserName"), new Password("Password2"), new Bio("Bio2"), new Image("Image2")); + final User following = userBuilder(new Email(EMAIL), new Name(USERNAME), new Password(PASSWORD), new Bio(BIO), new Image(IMAGE)); + final User follower = userBuilder(new Email("Email2@email.com"), new Name("differentUserName"), new Password("Password2"), new Bio("Bio2"), new Image("Image2")); - final Follow follow = Follow.Builder() - .following(user1) - .follower(user2) - .build(); + final Follow follow = followBuilder(following, follower); assertAll( () -> assertThat(follow).isNotNull(), @@ -43,4 +40,25 @@ void builder_test() { ); } + @DisplayName("Follow 인스턴스 getter 테스트") + @Test + void getter_test() { + final User following = userBuilder(new Email(EMAIL), new Name(USERNAME), new Password(PASSWORD), new Bio(BIO), new Image(IMAGE)); + final User follower = userBuilder(new Email("Email2@email.com"), new Name("differentUserName"), new Password("Password2"), new Bio("Bio2"), new Image("Image2")); + + final Follow follow = followBuilder(following, follower); + + assertAll( + () -> assertThat(follow.following()).isEqualTo(following), + () -> assertThat(follow.follower()).isEqualTo(follower) + ); + } + + public static final Follow followBuilder(final User following, final User follower) { + return Follow.Builder() + .following(following) + .follower(follower) + .build(); + } + } \ No newline at end of file