-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
김정호/src/test/java/com/hou27/chap07/AutoDebitInfoRepository.java
This file contains 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,6 @@ | ||
package com.hou27.chap07; | ||
|
||
public interface AutoDebitInfoRepository { | ||
AutoDebitInfo findOne(String userId); | ||
void save(AutoDebitInfo info); | ||
} |
40 changes: 40 additions & 0 deletions
40
김정호/src/test/java/com/hou27/chap07/AutoDebitRegister_Fake_Test.java
This file contains 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,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()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
김정호/src/test/java/com/hou27/chap07/MemoryAutoDebitInfoRepository.java
This file contains 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,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); | ||
} | ||
} |