Skip to content

Commit

Permalink
DB 연동 코드도 대역을 사용 - #71
Browse files Browse the repository at this point in the history
  • Loading branch information
hou27 committed Feb 7, 2023
1 parent c7c95c8 commit 241092d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.hou27.chap07;

public interface AutoDebitInfoRepository {
AutoDebitInfo findOne(String userId);
void save(AutoDebitInfo info);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.hou27.chap07;

import static org.junit.jupiter.api.Assertions.assertEquals;

import java.time.LocalDateTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class AutoDebitRegister_Fake_Test {
private AutoDebitRegister register;
private StubCardNumberValidator stubValidator;
private AutoDebitInfoRepository repository;

@BeforeEach
void setUp() {
stubValidator = new StubCardNumberValidator();
repository = new MemoryAutoDebitInfoRepository();
register = new AutoDebitRegister(stubValidator, repository);
}

@Test
void alreadyRegistered_InfoUpdated() {
repository.save(new AutoDebitInfo("user1", "123412349876", LocalDateTime.now()));

AutoDebitReq req = new AutoDebitReq("user1", "123412349999");
RegisterResult result = register.register(req);

AutoDebitInfo saved = repository.findOne("user1");
assertEquals("1234123412341235", saved.getCardNumber());
}

@Test
void notYetRegistered_newInfoRegistered() {
AutoDebitReq req = new AutoDebitReq("user1", "1234123412341234");
RegisterResult result = register.register(req);

AutoDebitInfo saved = repository.findOne("user1");
assertEquals("1234123412341234", saved.getCardNumber());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.hou27.chap07;

import java.util.HashMap;
import java.util.Map;

public class MemoryAutoDebitInfoRepository implements AutoDebitInfoRepository {
private Map<String, AutoDebitInfo> infos = new HashMap<>();

@Override
public AutoDebitInfo findOne(String userId) {
return infos.get(userId);
}

@Override
public void save(AutoDebitInfo info) {
infos.put(info.getUserId(), info);
}
}

0 comments on commit 241092d

Please sign in to comment.