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
@PostMapping("/register/step2") | |
public String handleStep2(HttpServletRequest request) { | |
String agreeParam = request.getParameter("agree"); | |
} |
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
@PostMapping("/register/step2") | |
public String handleStep2(@RequestParam(value="agree", defaultValue="false") Boolean agreeVal) { | |
... | |
} |
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
package chap07; | |
import java.time.LocalDateTime; | |
public class AutoDebitRegister { | |
private CardNumberValidator validator; | |
private AutoDebitInfoRepository repository; | |
public AutoDebitRegister(final CardNumberValidator validator, final AutoDebitInfoRepository repository) { |
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
public class AutoDebitRegister { | |
private CardNumberValidator validator; | |
private AutoDebitInfoRepository repository; | |
public AutoDebitRegister(final CardNumberValidator validator, final AutoDebitInfoRepository repository) { | |
this.validator = validator; | |
this.repository = repository; | |
} |
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
public class CardNumberValidator { | |
public CardValidity validate(String cardNumber) { | |
HttpClient httpClient = HttpClient.newHttpClient(); | |
HttpRequest request = HttpRequest.newBuilder() | |
.uri(URI.create("https://some-external-pg.com/card")) | |
.header("Content-Type", "text/plain") | |
.POST(HttpRequest.BodyPublishers.ofString(cardNumber)) | |
.build(); | |
try { |
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
public class AutoDebitRegisterTest { | |
private AutoDebitRegister register; | |
@BeforeEach | |
void setUp() { | |
CardNumberValidator validator = new CardNumberValidator(); | |
AutoDebitInfoRepository repository = new JpaAutoDebitInfoRepository(); | |
register = new AutoDebitRegister(validator, repository); | |
} |
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
public class StubCardNumberValidator extends CardNumberValidator { | |
private String invalidNo; | |
@Override | |
public CardValidity validate(final String cardNumber) { | |
if (invalidNo != null && invalidNo.equals(cardNumber)) { | |
return CardValidity.INVALID; | |
} | |
return CardValidity.VALID; |
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
public interface AutoDebitInfoRepository { | |
void save(AutoDebitInfo info); | |
AutoDebitInfo findOne(String userId); | |
} |
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
public class StubAutoDebitInfoRepository implements AutoDebitInfoRepository { | |
private Map<String, AutoDebitInfo> infos = new HashMap<>(); | |
@Override | |
public void save(final AutoDebitInfo info) { | |
infos.put(info.getUserId(), info); | |
} | |
@Override |
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
public class AutoDebitRegisterStubTest { | |
private AutoDebitRegister register; | |
private StubCardNumberValidator stubValidator; | |
private MemoryAutoDebitInfoRepository repository; | |
@BeforeEach | |
void setUp() { | |
this.stubValidator = new StubCardNumberValidator(); | |
this.repository = new MemoryAutoDebitInfoRepository(); |