Skip to content

Commit

Permalink
[#54] test: Following 인스턴스 add()에 null 입력시 실패 테스트 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
kwj1270 committed Oct 12, 2021
1 parent 52670a3 commit 729bab6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.study.realworld.domain.follow.domain;

import com.study.realworld.domain.follow.error.exception.FollowNullPointerException;

import javax.persistence.CascadeType;
import javax.persistence.Embeddable;
import javax.persistence.OneToMany;
Expand All @@ -17,13 +19,13 @@ public Followings() {
}

public void addFollowing(final Follow following) {
validateArgumentNull(following);
validateFollowNull(following);
followings.add(following);
}

private void validateArgumentNull(final Follow following) {
private void validateFollowNull(final Follow following) {
if(Objects.isNull(following)) {
throw new IllegalArgumentException();
throw new FollowNullPointerException();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.study.realworld.domain.follow.error.exception;

public class FollowBusinessException extends RuntimeException {

public FollowBusinessException(final String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.study.realworld.domain.follow.error.exception;

public class FollowNullPointerException extends FollowBusinessException {

private static final String MESSAGE = "Follow 가 null 입니다.";

public FollowNullPointerException() {
super(MESSAGE);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.study.realworld.domain.follow.domain;

import com.study.realworld.domain.follow.error.exception.FollowNullPointerException;
import com.study.realworld.domain.user.domain.persist.User;
import com.study.realworld.domain.user.domain.vo.*;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -13,6 +14,7 @@
import static com.study.realworld.domain.user.domain.vo.NameTest.USERNAME;
import static com.study.realworld.domain.user.domain.vo.PasswordTest.PASSWORD;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.*;

class FollowingsTest {
Expand All @@ -30,7 +32,7 @@ void constructor_test() {

@DisplayName("Following 인스턴스 add 테스트")
@Test
void add_fail_test() {
void add_test() {
final Followings followings = new Followings();
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("email1"), new Name("username1"), new Password("password1"), new Bio("bio1"), new Image("image1"));
Expand All @@ -40,4 +42,13 @@ void add_fail_test() {
assertThat(followings.getFollowings().size()).isEqualTo(1);
}

@DisplayName("Following 인스턴스 add()에 null 입력시 실패 테스트")
@Test
void add_fail_test() {
final Followings followings = new Followings();
assertThatThrownBy(() -> followings.addFollowing(null))
.isInstanceOf(FollowNullPointerException.class)
.hasMessage("Follow 가 null 입니다.");
}

}

0 comments on commit 729bab6

Please sign in to comment.