Skip to content
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

[#1] repository에서 도메인 모델 분리 #5

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 41 additions & 20 deletions src/test/java/com/study/bookcafe/borrow/MapperTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,47 @@ public class MapperTest {

private final Gson gson = JsonHelper.getGson();

interface BorrowObjectFactory {
Borrow createBorrow();
BorrowDto createBorrowDto();
BorrowEntity createBorrowEntity();
}

static class BorrowFactory implements BorrowObjectFactory {
@Override
public Borrow createBorrow() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

뭔가 일이 커졌군요 ㅋㅋㅋㅋㅋㅋ 저는 Period 를 두고 한 얘기 였어요 ㅎ
자세한건 내일 얘기로 풀어보시죠

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ㅋㅋㅋㅋㅋㅋ앗 팩토리 패턴에 대해서 공부해보고 적용할만한 곳이 어디일까 하다가 그만..

return Borrow.builder()
.member(Member.builder().id(1).build())
.book(Book.builder().id(1).ISBN(9788936433598L).build())
.period(new Period(LocalDateTime.now()))
.build();
}

@Override
public BorrowDto createBorrowDto() {
return BorrowDto.builder()
.member(MemberDto.builder().id(1).build())
.book(BookDto.builder().id(1).ISBN(9788936433598L).build())
.period(new Period(LocalDateTime.now()))
.build();
}

@Override
public BorrowEntity createBorrowEntity() {
return BorrowEntity.builder()
.member(MemberEntity.builder().id(1).build())
.book(BookEntity.builder().id(1).ISBN(9788936433598L).build())
.period(new Period(LocalDateTime.now()))
.build();
}
}

BorrowObjectFactory factory = new BorrowFactory();

@Test
@DisplayName("Mapper 테스트 : Borrow -> BorrowDto")
public void checkMapperBorrowToBorrowDto() {
Borrow borrow = Borrow.builder()
.member(Member.builder().id(1).build())
.book(Book.builder().id(1).ISBN(9788936433598L).build())
.period(new Period(LocalDateTime.now()))
.build();
Borrow borrow = factory.createBorrow();
BorrowDto borrowDto = borrowMapper.toBorrowDto(borrow);

System.out.println(gson.toJson(borrowDto));
Expand All @@ -47,11 +80,7 @@ public void checkMapperBorrowToBorrowDto() {
@Test
@DisplayName("Mapper 테스트 : BorrowDto -> Borrow")
public void checkMapperBorrowDtoToBorrow() {
BorrowDto borrowDto = BorrowDto.builder()
.member(MemberDto.builder().id(1).build())
.book(BookDto.builder().id(1).ISBN(9788936433598L).build())
.period(new Period(LocalDateTime.now()))
.build();
BorrowDto borrowDto = factory.createBorrowDto();
Borrow borrow = borrowMapper.toBorrow(borrowDto);

System.out.println(gson.toJson(borrow));
Expand All @@ -61,11 +90,7 @@ public void checkMapperBorrowDtoToBorrow() {
@Test
@DisplayName("Mapper 테스트 : Borrow -> BorrowEntity")
public void checkMapperBorrowToBorrowEntity() {
Borrow borrow = Borrow.builder()
.member(Member.builder().id(1).build())
.book(Book.builder().id(1).ISBN(9788936433598L).build())
.period(new Period(LocalDateTime.now()))
.build();
Borrow borrow = factory.createBorrow();
BorrowEntity borrowEntity = borrowMapper.toBorrowEntity(borrow);

System.out.println(gson.toJson(borrowEntity));
Expand All @@ -75,11 +100,7 @@ public void checkMapperBorrowToBorrowEntity() {
@Test
@DisplayName("Mapper 테스트 : BorrowEntity -> Borrow")
public void checkMapperBorrowEntityToBorrow() {
BorrowEntity borrowEntity = BorrowEntity.builder()
.member(MemberEntity.builder().id(1).build())
.book(BookEntity.builder().id(1).ISBN(9788936433598L).build())
.period(new Period(LocalDateTime.now()))
.build();
BorrowEntity borrowEntity = factory.createBorrowEntity();
Borrow borrow = borrowMapper.toBorrow(borrowEntity);

System.out.println(gson.toJson(borrow));
Expand Down
Loading