forked from sunday-develop/toby-spring
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UserService.upgrade 메소드는 GOLD인 사용자가 호출한다면 문제가 되고, grade가 늘어난다면 if문이 점점 더 길어지는 문제가 있다. - grade의 순서와 다음 단계의 grade가 무엇인지 결정하는 일은 Grade에게 - 사용자의 정보가 바뀌는 부분은 User에게 (예외 검증도 스스로 할 수 있도록, 다른 어느 곳에서 사용할 수도 있으니까 ~) => 객체 지향 적이 된다! User 클래스의 테스트도 추가하자
- Loading branch information
1 parent
645eba7
commit 10a7f22
Showing
5 changed files
with
61 additions
and
5 deletions.
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
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
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
42 changes: 42 additions & 0 deletions
42
src/test/java/com/toby/tobyspring/user/domain/UserTest.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,42 @@ | ||
package com.toby.tobyspring.user.domain; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
class UserTest { | ||
User user; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
user = new User(); | ||
} | ||
|
||
@Test | ||
@DisplayName("user의 upgrade() 테스트") | ||
public void upgrade() { | ||
Grade[] grades = Grade.values(); | ||
for (Grade grade : grades) { | ||
if (grade.nextGrade() == null) continue; | ||
user.setGrade(grade); | ||
user.upgrade(); | ||
assertEquals(grade.nextGrade(), user.getGrade()); | ||
} | ||
} | ||
|
||
@Test | ||
@DisplayName("user의 upgrade() exception 테스트") | ||
public void cannotUpgrade() { | ||
Grade[] grades = Grade.values(); | ||
for (Grade grade : grades) { | ||
if (grade.nextGrade() != null) continue; | ||
user.setGrade(grade); | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
user.upgrade(); | ||
}); | ||
} | ||
} | ||
} |
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