Skip to content
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.

[#30] Owner 테스트 코드 작성 #33

Merged
merged 1 commit into from
Nov 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 2 additions & 1 deletion src/main/java/com/delfood/dto/OwnerDTO.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package com.delfood.dto;

import java.time.LocalDateTime;

import lombok.Builder;
import lombok.Getter;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;

import org.apache.ibatis.type.Alias;

@Builder
@Getter
@Setter
@ToString
Expand Down
63 changes: 63 additions & 0 deletions src/test/java/com/delfood/service/OwnerServiceTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.delfood.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import com.delfood.dto.OwnerDTO;
import com.delfood.mapper.OwnerMapper;
import com.delfood.utils.SHA256Util;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;


@RunWith(MockitoJUnitRunner.class)
public class OwnerServiceTest {

@InjectMocks // 의존성 주입이 필요한 mock에 설정, @Mock으로 등록된 객체를 주입시켜준다.
OwnerService service;

@Mock // mock 생성
OwnerMapper mapper;

/**
* 회원가입 성공 테스트.
*/
@Test
public void signUp_success() {
OwnerDTO ownerInfo = OwnerDTO.builder()
Copy link
Member

Choose a reason for hiding this comment

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

빌더 적용하신 아이디어 좋습니다.

Copy link
Collaborator

Choose a reason for hiding this comment

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

질문있습니다! 빌더를 적용한 경우 기본 생성자를 생성할 수 없게 변하던데, 이 경우 문제는 없는건가요?

Copy link
Member

Choose a reason for hiding this comment

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

기본생성자는 없어도 됩니다. 사실 구현의 자유인게 어차피 null을 넣을거라면 기본생성자나 빌더나 역할은 비슷하니까요

.id("ljy2134")
.password(SHA256Util.encryptSHA256("2134"))
.name("이진영")
.mail("asdf@naver.com")
.tel("010-3333-3333")
.build();

given(mapper.insertOwner(ownerInfo)).willReturn(1);
service.signUp(ownerInfo);
}

/**
* 회원가입 실패 테스트.
*/
@Test(expected = RuntimeException.class)
public void signUp_fail() {
OwnerDTO ownerInfo = OwnerDTO.builder()
.id("ljy2134")
.password(SHA256Util.encryptSHA256("2134"))
.name("이진영")
.mail("asdf@naver.com")
.tel("010-3333-3333")
.build();

given(mapper.insertOwner(ownerInfo)).willReturn(0);
service.signUp(ownerInfo);
}

}