Skip to content

Commit

Permalink
test: 테스트 코드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
seokjin8678 committed Oct 7, 2023
1 parent 9872f96 commit 8f54279
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class AdminTest {
}

@Test
void password가_20글자_초과하면_예외() {
void password가_255글자_초과하면_예외() {
// given
String password = "1".repeat(256);

Expand Down
54 changes: 54 additions & 0 deletions backend/src/test/java/com/festago/fcm/domain/MemberFCMTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package com.festago.fcm.domain;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.festago.common.exception.ValidException;
import org.junit.jupiter.api.DisplayNameGeneration;
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;

@DisplayNameGeneration(ReplaceUnderscores.class)
@SuppressWarnings("NonAsciiCharacters")
class MemberFCMTest {

@Test
void MemberFCM_생성_성공() {
// given
MemberFCM memberFCM = new MemberFCM(1L, "token");

// when & then
assertThat(memberFCM.getMemberId()).isEqualTo(1L);
assertThat(memberFCM.getFcmToken()).isEqualTo("token");
}

@ParameterizedTest
@NullSource
void memberId가_null이면_예외(Long memberId) {
// when & then
assertThatThrownBy(() -> new MemberFCM(memberId, "token"))
.isInstanceOf(ValidException.class);
}

@ParameterizedTest
@NullSource
@ValueSource(strings = {"", " ", "\t", "\n"})
void token이_null_또는_공백이면_예외(String token) {
// when & then
assertThatThrownBy(() -> new MemberFCM(1L, token))
.isInstanceOf(ValidException.class);
}

@Test
void token의_길이가_255자를_초과하면_예외() {
// given
String token = "1".repeat(256);

// when & then
assertThatThrownBy(() -> new MemberFCM(1L, token))
.isInstanceOf(ValidException.class);
}
}
73 changes: 63 additions & 10 deletions backend/src/test/java/com/festago/school/domain/SchoolTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.NullSource;
import org.junit.jupiter.params.provider.ValueSource;

@DisplayNameGeneration(ReplaceUnderscores.class)
Expand All @@ -17,53 +18,105 @@ class SchoolTest {
@Test
void 학교의_도메인_길이가_50자를_넘으면_예외() {
// given
String domain = "1234567890".repeat(5) + "1";
String domain = "1".repeat(51);

// when & then
assertThatThrownBy(() -> new School(domain, "name"))
assertThatThrownBy(() -> new School(domain, "테코대학교"))
.isInstanceOf(ValidException.class);
}

@ParameterizedTest
@NullSource
@ValueSource(strings = {"", " ", "\t", "\n"})
void 학교의_도메인이_null_또는_공백이면_예외(String domain) {
// when & then
assertThatThrownBy(() -> new School(domain, "테코대학교"))
.isInstanceOf(ValidException.class);
}

@Test
void 학교의_이름이_255자를_넘으면_예외() {
// given
String name = "1234567890".repeat(25) + "123456";
String name = "1".repeat(256);

// when & then
assertThatThrownBy(() -> new School("teco.ac.kr", name))
.isInstanceOf(ValidException.class);
}

@ParameterizedTest
@NullSource
@ValueSource(strings = {"", " ", "\t", "\n"})
void 학교의_이름이_null_또는_공백이면_예외(String name) {
// when & then
assertThatThrownBy(() -> new School("domain", name))
assertThatThrownBy(() -> new School("teco.ac.kr", name))
.isInstanceOf(ValidException.class);
}

@Test
void 학교의_도메인을_수정할때_255자를_넘으면_예외() {
// given
School school = new School("domain", "name");
School school = new School("teco.ac.kr", "테코대학교");

// when & then
String domain = "1".repeat(256);
assertThatThrownBy(() -> school.changeDomain(domain))
.isInstanceOf(ValidException.class);
}

@ParameterizedTest
@NullSource
@ValueSource(strings = {"", " ", "\t", "\n"})
void 학교의_도메인을_수정할때_null_또는_공백이면_예외(String domain) {
// given
School school = new School("teco.ac.kr", "테코대학교");

// when & then
String domain = "1234567890".repeat(5) + "1";
assertThatThrownBy(() -> school.changeDomain(domain))
.isInstanceOf(ValidException.class);
}

@Test
void 학교의_이름을_수정할때_255자를_넘으면_예외() {
// given
School school = new School("domain", "name");
School school = new School("teco.ac.kr", "테코대학교");

// when & then
String name = "1".repeat(256);
assertThatThrownBy(() -> school.changeName(name))
.isInstanceOf(ValidException.class);
}

@ParameterizedTest
@NullSource
@ValueSource(strings = {"", " ", "\t", "\n"})
void 학교의_이름을_수정할때_null_또는_공백이면_예외(String name) {
// given
School school = new School("teco.ac.kr", "테코대학교");

// when & then
String name = "1234567890".repeat(25) + "123456";
assertThatThrownBy(() -> school.changeName(name))
.isInstanceOf(ValidException.class);
}

@Test
void 학교_생성_성공() {
// given
School school = new School("teco.ac.kr", "테코대학교");

// when & then
assertThat(school.getName()).isEqualTo("테코대학교");
assertThat(school.getDomain()).isEqualTo("teco.ac.kr");
}

@ParameterizedTest
@ValueSource(ints = {1, 50})
void 학교를_생성할때_도메인이_50글자_이내_성공(int length) {
// given
String domain = "1".repeat(length);

// when
School school = new School(domain, "name");
School school = new School(domain, "테코대학교");

// then
assertThat(school.getDomain()).isEqualTo(domain);
Expand All @@ -76,7 +129,7 @@ class SchoolTest {
String name = "1".repeat(length);

// when
School school = new School("domain", name);
School school = new School("teco.ac.kr", name);

// then
assertThat(school.getName()).isEqualTo(name);
Expand Down

0 comments on commit 8f54279

Please sign in to comment.