Refactor repository
This commit is contained in:
@@ -2,8 +2,8 @@ package com.yam.app.account.domain;
|
||||
|
||||
public interface AccountRepository {
|
||||
|
||||
Account save(Account entity);
|
||||
void save(Account entity);
|
||||
|
||||
Account update(Account entity);
|
||||
void update(Account entity);
|
||||
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ public final class RegisterAccountProcessor {
|
||||
|
||||
String encodedPassword = passwordEncrypter.encode(password);
|
||||
|
||||
return accountRepository.save(Account.of(email, nickname, encodedPassword));
|
||||
accountRepository.save(Account.of(email, nickname, encodedPassword));
|
||||
return accountReader.findByEmail(email)
|
||||
.orElseThrow(IllegalArgumentException::new);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,14 +23,12 @@ public final class MybatisAccountRepository implements AccountRepository, Accoun
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account update(Account entity) {
|
||||
public void update(Account entity) {
|
||||
int result = template.update(UPDATE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new RuntimeException(
|
||||
String.format("There was a problem updating the object : %s", entity));
|
||||
}
|
||||
return findByEmail(entity.getEmail())
|
||||
.orElseThrow(IllegalArgumentException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -39,14 +37,12 @@ public final class MybatisAccountRepository implements AccountRepository, Accoun
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account save(Account entity) {
|
||||
public void save(Account entity) {
|
||||
int result = template.insert(SAVE_FQCN, entity);
|
||||
if (result != 1) {
|
||||
throw new RuntimeException(
|
||||
String.format("There was a problem saving the object : %s", entity));
|
||||
}
|
||||
return findByEmail(entity.getEmail())
|
||||
.orElseThrow(IllegalArgumentException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -15,14 +15,15 @@ final class ConfirmRegisterAccountProcessorTest {
|
||||
@TestFactory
|
||||
@DisplayName("이메일 검증 시나리오")
|
||||
Collection<DynamicTest> verify_account_scenarios() {
|
||||
var accountRepository = new FakeAccountRepository();
|
||||
var accountReader = accountRepository;
|
||||
var tokenVerifier = new TokenVerifier(accountReader);
|
||||
var confirmRegisterAccountProcessor = new ConfirmRegisterAccountProcessor(accountReader,
|
||||
accountRepository, tokenVerifier);
|
||||
final var fakeObject = new FakeAccountRepository();
|
||||
final var accountRepository = fakeObject;
|
||||
final var accountReader = fakeObject;
|
||||
final var tokenVerifier = new TokenVerifier(accountReader);
|
||||
final var confirmRegisterAccountProcessor = new ConfirmRegisterAccountProcessor(
|
||||
accountReader, accountRepository, tokenVerifier);
|
||||
|
||||
var account = accountRepository.save(
|
||||
Account.of("jiwonDev@gmail.com", "jiwon", "password!"));
|
||||
accountRepository.save(Account.of("jiwonDev@gmail.com", "jiwon", "password!"));
|
||||
final var account = accountReader.findByEmail("jiwonDev@gmail.com").get();
|
||||
|
||||
return Arrays.asList(
|
||||
DynamicTest.dynamicTest("회원 이메일 토큰검증에 성공한다.", () -> {
|
||||
|
||||
@@ -24,8 +24,8 @@ public final class FakeAccountRepository implements AccountRepository, AccountRe
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account update(Account entity) {
|
||||
return data.putIfAbsent(entity.getId(), entity);
|
||||
public void update(Account entity) {
|
||||
data.putIfAbsent(entity.getId(), entity);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -35,9 +35,8 @@ public final class FakeAccountRepository implements AccountRepository, AccountRe
|
||||
}
|
||||
|
||||
@Override
|
||||
public Account save(Account entity) {
|
||||
public void save(Account entity) {
|
||||
entity.setId(idGenerator.incrementAndGet());
|
||||
data.put(entity.getId(), entity);
|
||||
return entity;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,8 @@ final class TokenVerifierTest {
|
||||
//Arrange
|
||||
var accountRepository = new FakeAccountRepository();
|
||||
var tokenVerifier = new TokenVerifier(accountRepository);
|
||||
var account = accountRepository.save(
|
||||
Account.of("jijiwon@gmail.com", "jiwon", "password!"));
|
||||
accountRepository.save(Account.of("jiwon@gmail.com", "jiwon", "password!"));
|
||||
var account = accountRepository.findByEmail("jiwon@gmail.com").get();
|
||||
|
||||
//Act
|
||||
var throwable = catchThrowable(
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
package com.yam.app.account.infrastructure;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import com.yam.app.account.domain.Account;
|
||||
import com.yam.app.account.domain.AccountReader;
|
||||
import com.yam.app.account.domain.AccountRepository;
|
||||
import com.yam.app.account.domain.Role;
|
||||
import java.util.Optional;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.DisplayName;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
@SpringBootTest
|
||||
@Disabled
|
||||
final class MybatisAccountRepositoryTest {
|
||||
|
||||
@Autowired
|
||||
private AccountRepository accountRepository;
|
||||
|
||||
@Autowired
|
||||
private AccountReader accountReader;
|
||||
|
||||
@Test
|
||||
@DisplayName("이메일 중복 쿼리 학습 테스트")
|
||||
void existsByEmail() {
|
||||
boolean result = accountReader.existsByEmail("jiwonDev@gmail.com");
|
||||
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("닉네임 중복 쿼리 학습 테스트")
|
||||
void existsByNickname() {
|
||||
boolean result = accountReader.existsByNickname("jiwon");
|
||||
|
||||
assertThat(result).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("사용자 이메일을 사용한 조회 테스트")
|
||||
void findByEmail() {
|
||||
Optional<Account> account = accountReader.findByEmail("jiwonDev@gmail.com");
|
||||
|
||||
assertThat(account.isPresent()).isTrue();
|
||||
assertThat(account.get().getId()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Account 객체 저장 테스트")
|
||||
void save() {
|
||||
Account account = accountRepository.save(
|
||||
Account.of("rebwon@gmail.com", "rebwon", "password!"));
|
||||
|
||||
assertThat(account.getRole()).isEqualTo(Role.DEFAULT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Account 객체 갱신 테스트")
|
||||
void update() {
|
||||
Account account = accountRepository.save(
|
||||
Account.of("jiwon22@gmail.com", "jiwon2", "password!"));
|
||||
|
||||
account.completeRegister();
|
||||
Account updatedAccount = accountRepository.update(account);
|
||||
|
||||
assertThat(updatedAccount.isEmailVerified()).isTrue();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user