-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
79 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
server/src/test/java/server/haengdong/domain/BillActionTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package server.haengdong.domain; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertAll; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class BillActionTest { | ||
|
||
@DisplayName("앞뒤 공백을 제거한 title이 2 ~ 30자가 아니면 지출을 생성할 수 없다.") | ||
@ParameterizedTest | ||
@ValueSource(strings = {" 감 ", "", " ", "감자감자감자감자감자감자백호백호백호백호백호감자감자감자감자감자감자백호백호백호백호백호"}) | ||
void validateTitle(String title) { | ||
Event event = new Event("name", "token"); | ||
Action action = new Action(event, 1L); | ||
Long price = 100L; | ||
|
||
assertThatThrownBy(() -> new BillAction(action, title, price)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("앞뒤 공백을 제거한 지출 내역 제목은 2 ~ 30자여야 합니다."); | ||
} | ||
|
||
@DisplayName("금액이 10,000,000 이하의 자연수가 아니면 지출을 생성할 수 없다.") | ||
@ParameterizedTest | ||
@ValueSource(longs = {0, 10_000_001, 20_000_000}) | ||
void validatePrice(long price) { | ||
Event event = new Event("name", "token"); | ||
Action action = new Action(event, 1L); | ||
String title = "title"; | ||
|
||
assertThatThrownBy(() -> new BillAction(action, title, price)) | ||
.isInstanceOf(IllegalArgumentException.class) | ||
.hasMessage("지출 금액은 10,000,000 이하의 자연수여야 합니다."); | ||
} | ||
|
||
@DisplayName("지출 내역을 올바르게 생성한다.") | ||
@Test | ||
void createBillAction() { | ||
Event event = new Event("name", "token"); | ||
Action action = new Action(event, 1L); | ||
String title = "title"; | ||
Long price = 1_000L; | ||
|
||
BillAction billAction = new BillAction(action, title, price); | ||
|
||
assertAll( | ||
() -> assertThat(billAction.getAction()).isEqualTo(action), | ||
() -> assertThat(billAction.getTitle()).isEqualTo(title), | ||
() -> assertThat(billAction.getPrice()).isEqualTo(price) | ||
); | ||
} | ||
} |