Skip to content

Commit

Permalink
[#54] test: Follow 인스턴스 getter 테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
kwj1270 committed Oct 3, 2021
1 parent 468e815 commit 59d21d0
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 7 deletions.
32 changes: 32 additions & 0 deletions src/main/java/com/study/realworld/domain/follow/domain/Follow.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,18 +29,36 @@ 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(),
() -> assertThat(follow).isExactlyInstanceOf(Follow.class)
);
}

@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();
}

}

0 comments on commit 59d21d0

Please sign in to comment.