-
Notifications
You must be signed in to change notification settings - Fork 0
feature/#110 testfixtures 기반 professor testcode 구현 #116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
minjo-on
merged 8 commits into
develop
from
feature/#110-testfixtures-based-professor-testcode
Nov 28, 2024
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
7c296bc
refactor: 허용 가능한 이메일 추가
minjo-on 0afd227
feat: professor domain test 구현
minjo-on d66c62c
feat: FakeProfessorRepository 구현
minjo-on 857089b
feat: Professor test 초기 설정 구현
minjo-on 67f5726
refactor: 교수 삭제시 객체가 아닌 id로 삭제
minjo-on b407f07
feat: professor service test 구현
minjo-on 4bec0f6
refactor: id 증가 AtomicLong 타입으로 수정
minjo-on 03342c5
refactor: 모든 필드 검증
minjo-on File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
139 changes: 139 additions & 0 deletions
139
aics-api/src/testFixtures/java/professor/application/ProfessorServiceTest.java
This file contains hidden or 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,139 @@ | ||
package professor.application; | ||
|
||
import static kgu.developers.domain.professor.domain.Role.ASSISTANT; | ||
import static kgu.developers.domain.professor.domain.Role.PROFESSOR; | ||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import kgu.developers.api.professor.application.ProfessorService; | ||
import kgu.developers.api.professor.presentation.exception.ProfessorNotFoundException; | ||
import kgu.developers.api.professor.presentation.request.ProfessorRequest; | ||
import kgu.developers.api.professor.presentation.response.ProfessorPersistResponse; | ||
import kgu.developers.domain.professor.domain.Professor; | ||
import mock.FakeProfessorRepository; | ||
|
||
public class ProfessorServiceTest { | ||
private ProfessorService professorService; | ||
|
||
@BeforeEach | ||
public void init() { | ||
FakeProfessorRepository fakeProfessorRepository = new FakeProfessorRepository(); | ||
|
||
this.professorService = ProfessorService.builder() | ||
.professorRepository(fakeProfessorRepository) | ||
.build(); | ||
|
||
fakeProfessorRepository.save(Professor.builder() | ||
.email("alswns11346@kyonggi.ac.kr") | ||
.name("박민준") | ||
.role(ASSISTANT) | ||
.contact("010-1234-5678") | ||
.build()); | ||
|
||
fakeProfessorRepository.save(Professor.builder() | ||
.email("alswns11346@kgu.ac.kr") | ||
.name("박민준") | ||
.role(PROFESSOR) | ||
.contact("010-1234-5678") | ||
.build()); | ||
|
||
fakeProfessorRepository.save(Professor.builder() | ||
.email("kkh@kyonggi.ac.kr") | ||
.name("권기현") | ||
.role(PROFESSOR) | ||
.contact("010-1234-5678") | ||
.build()); | ||
} | ||
|
||
@Test | ||
@DisplayName("createProfessor는 교수를 생성할 수 있다") | ||
public void createProfessor_Success() { | ||
// given | ||
ProfessorRequest request = ProfessorRequest.builder() | ||
.name("권기현") | ||
.role(PROFESSOR) | ||
.email("kkh1111@kgu.ac.kr") | ||
.contact("010-1234-5678") | ||
.build(); | ||
|
||
// when | ||
ProfessorPersistResponse response = professorService.createProfessor(request); | ||
Professor result = Professor.create(request.name(), request.role(), request.contact(), request.email()); | ||
|
||
// then | ||
assertEquals(4, response.id()); | ||
minjo-on marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assertEquals("권기현", result.getName()); | ||
assertEquals("kkh1111@kgu.ac.kr", result.getEmail()); | ||
assertEquals("010-1234-5678", result.getContact()); | ||
assertEquals(PROFESSOR, result.getRole()); | ||
} | ||
|
||
@Test | ||
@DisplayName("updateProfessor는 교수 정보를 수정할 수 있다") | ||
public void updateProfessor_Success() { | ||
// given | ||
Long professorId = 2L; | ||
ProfessorRequest request = new ProfessorRequest("박민준", PROFESSOR, "010-9999-8888", | ||
"alswnszzang1@kyonggi.ac.kr"); | ||
|
||
// when | ||
professorService.updateProfessor(professorId, request); | ||
Professor response = professorService.getProfessorById(professorId); | ||
|
||
// then | ||
assertEquals("박민준", response.getName()); | ||
assertEquals(PROFESSOR, response.getRole()); | ||
assertEquals("010-9999-8888", response.getContact()); | ||
assertEquals("alswnszzang1@kyonggi.ac.kr", response.getEmail()); | ||
} | ||
|
||
@Test | ||
@DisplayName("getProfessor는 존재하지 않는 교수를 찾아올 경우 ProfessorNotFoundException을 발생시킨다.") | ||
public void getProfessor_NotFound_ThrowsException() { | ||
// given | ||
Long professorId = 4L; | ||
|
||
// when | ||
// then | ||
assertThatThrownBy(() -> { | ||
professorService.getProfessorById(professorId); | ||
}).isInstanceOf(ProfessorNotFoundException.class); | ||
} | ||
|
||
@Test | ||
@DisplayName("deleteProfessor는 교수를 삭제할 수 있다") | ||
public void deleteProfessor_Success() { | ||
// given | ||
Long professorId = 1L; | ||
|
||
// when | ||
professorService.deleteProfessor(professorId); | ||
|
||
// then | ||
assertThatThrownBy(() -> { | ||
professorService.getProfessorById(professorId); | ||
}).isInstanceOf(ProfessorNotFoundException.class); | ||
} | ||
|
||
@Test | ||
@DisplayName("getSortedProfessorList는 정렬된 교수 리스트를 반환한다") | ||
public void getSortedProfessorList_Success() { | ||
// when | ||
List<Professor> result = professorService.getSortedProfessorList(); | ||
|
||
// then | ||
assertEquals(3, result.size()); | ||
assertEquals("권기현", result.get(0).getName()); | ||
assertEquals(PROFESSOR, result.get(0).getRole()); | ||
assertEquals("박민준", result.get(1).getName()); | ||
assertEquals(PROFESSOR, result.get(1).getRole()); | ||
assertEquals("박민준", result.get(2).getName()); | ||
assertEquals(ASSISTANT, result.get(2).getRole()); | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
aics-api/src/testFixtures/java/professor/presentation/ProfessorControllerTest.java
This file contains hidden or 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,4 @@ | ||
package professor.presentation; | ||
|
||
public class ProfessorControllerTest { | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
50 changes: 50 additions & 0 deletions
50
aics-domain/src/testFixtures/java/mock/FakeProfessorRepository.java
This file contains hidden or 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,50 @@ | ||
package mock; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import kgu.developers.domain.professor.domain.Professor; | ||
import kgu.developers.domain.professor.domain.ProfessorRepository; | ||
|
||
public class FakeProfessorRepository implements ProfessorRepository { | ||
|
||
private final List<Professor> data = Collections.synchronizedList(new ArrayList<>()); | ||
private final AtomicLong sequence = new AtomicLong(1); | ||
|
||
@Override | ||
public Professor save(Professor professor) { | ||
Professor newProfessor = Professor.builder() | ||
.id(sequence.getAndIncrement()) | ||
.name(professor.getName()) | ||
.role(professor.getRole()) | ||
.contact(professor.getContact()) | ||
.email(professor.getEmail()) | ||
.build(); | ||
data.add(newProfessor); | ||
return newProfessor; | ||
} | ||
|
||
@Override | ||
public Optional<Professor> findById(Long id) { | ||
return data.stream() | ||
.filter(professor -> professor.getId().equals(id)) | ||
.findFirst(); | ||
} | ||
|
||
@Override | ||
public List<Professor> findAllOrderByRoleAndName() { | ||
return data.stream() | ||
.sorted(Comparator.comparing(Professor::getRole) | ||
.thenComparing(Professor::getName)) | ||
.toList(); | ||
} | ||
|
||
@Override | ||
public void deleteById(Long id) { | ||
data.removeIf(professor -> professor.getId().equals(id)); | ||
} | ||
minjo-on marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
34 changes: 34 additions & 0 deletions
34
aics-domain/src/testFixtures/java/professor/domain/ProfessorDomainTest.java
This file contains hidden or 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,34 @@ | ||
package professor.domain; | ||
|
||
import static kgu.developers.domain.professor.domain.Role.PROFESSOR; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import kgu.developers.domain.professor.domain.Professor; | ||
import kgu.developers.domain.professor.domain.Role; | ||
|
||
public class ProfessorDomainTest { | ||
|
||
@Test | ||
@DisplayName("PROFESSOR 객체를 생성할 수 있다") | ||
public void createProfessor_Success() { | ||
// given | ||
String name = "박민준"; | ||
Role role = PROFESSOR; | ||
String contact = "010-1234-5678"; | ||
String email = "alswns11346@kgu.ac.kr"; | ||
|
||
minjo-on marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// when | ||
Professor professor = Professor.create(name, role, contact, email); | ||
|
||
// then | ||
assertNotNull(professor); | ||
assertEquals(name, professor.getName()); | ||
assertEquals(role, professor.getRole()); | ||
assertEquals(contact, professor.getContact()); | ||
assertEquals(email, professor.getEmail()); | ||
minjo-on marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.