-
Notifications
You must be signed in to change notification settings - Fork 227
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
3단계 - 테스트를 통한 코드 보호 #844
Merged
Merged
3단계 - 테스트를 통한 코드 보호 #844
Changes from all commits
Commits
Show all changes
86 commits
Select commit
Hold shift + click to select a range
b031e18
feat(racingcar): carNameRuleTest01-이름5글자
Dongock c3c20fd
feat(racingcar) : stop&movingTest
Dongock 4406d32
feat(racingcar) : movingStrategyTest
Dongock 840ad93
feat(cal): nullCheckTest
b204e91
refactor(cal): beforeEach add
64a8142
feat(cal): onlyNumberCheck
Dongock c146750
docs(cal) : README 요구사항 1번 정리
Dongock db97850
docs(cal) : README 요구사항 1번 정리(내용추가)
Dongock ffb2f89
refactor(cal) : StringUtils 제거
Dongock f99307c
refactor(cal) : `NullAndEmptySource`로 변경
Dongock 1cc4d8c
feat(cal) : 숫자로 변환 가능하지 않은 문자 입력 시 예외 발생
Dongock 199cd05
doc(cal) : 예외사항 추가
Dongock 3fa268c
test(cal) : 구분자 검증 테스트 코드 추가
Dongock 89fa384
feat(cal) : 구분자를 컴마(,) 이외에 콜론(:)을 사용할 수 있다.
Dongock 881ba69
feat(cal) : "//"와 "\n" 문자 사이에 커스텀 구분자를 지정할 수 있다.
Dongock 504f6b2
feat(cal) : 음수를 전달할 경우 RuntimeException 예외가 발생해야 한다.
Dongock 9e4a0d5
refactor(cal) : 패턴 재사용 가능하게 축출 및 요구사항 정리
Dongock 75b5ff4
refactor(cal) : Empty 체크 리팩토링
Dongock 15f8e09
doc(cal) : 리팩토링을 위한 필요 정리 추가
Dongock 572c43b
doc(cal) : 리팩토링을 위한 필요 정리 추가(Front Controller)
Dongock dc7a993
feat(cal) : EmptyCalculator 클래스 및 Test 추가
Dongock 9d80278
feat(cal) : CustomCalculator 클래스 및 Test 추가
Dongock 3800b42
feat(cal) : DefaultCalculator 클래스 및 Test 추가
Dongock c1b0273
refactor(cal) : frontController 패턴 적용
Dongock eb118f0
refactor(cal) : 클래스 이름 변경
Dongock 3da5a4f
refactor(cal) : FeedBack 받은 부분 수정
Dongock bacb407
doc(force) : Product 요구사항 등록
Dongock c6aefa6
doc(force) : MenuGroup 요구사항 등록
Dongock b51a7e6
doc(force) : Menu 요구사항 등록
Dongock 71cf69e
doc(force) : Order 요구사항 등록
Dongock 845f4e1
doc(force) : OrderTable 요구사항 등록
Dongock 59c6019
doc(force) : ERD 추가
Dongock 4b51e15
doc(force) : 명칭 통일화_`정보` 제거
Dongock 2238762
doc(force) : 상품 요구사항 구체적으로 변경
Dongock 98b0fbd
doc(force) : 메뉴 모음 요구사항 구체적으로 변경
Dongock 9fa2336
doc(force) : 메뉴 요구사항 구체적으로 변경
Dongock 26a71b6
doc(force) : 주문 요구사항 구체적으로 변경
Dongock 9e5d029
doc(force) : 매장 테이블 요구사항 구체적으로 변경
Dongock 6579386
test(force) : ProductService Test 작성_create()
Dongock fc0e788
test(force) : ProductService Test 작성_minusPrice()
Dongock 7d532c1
test(force) : ProductService Test 작성_nullName()
Dongock a2336cc
test(force) : ProductService Test 작성_nullPrice()
Dongock b284778
test(force) : ProductService Test 작성_hasProfanity()
Dongock 7c1af64
test(force) : ProductService Test 작성_changePrice() & makeTestProduct …
Dongock 11c0ee2
test(pos) : ProductService Test 작성_compareMenuPrice() & makeTestMenu …
Dongock dbefacc
refactor(pos) : TextFixture 구조 생성 및 테스트 객체 생성 메소드 위치 변경
Dongock 3c4cdf7
test(pos) : MenuGroupServiceTest 생성 - create() 생성
Dongock 267b08f
test(pos) : MenuGroupServiceTest - nullName() 생성
Dongock b1e5b41
test(pos) : MenuServiceTest - create() 생성
Dongock 1b66912
test(pos) : MenuServiceTest - minusPrice() & noMenuInMenuGroup() 생성
Dongock 3277f12
test(pos) : MenuServiceTest - noProductInMenu()
Dongock 69ddc06
test(pos) : MenuServiceTest - noMenuProduct() 생성
Dongock f48490f
test(pos) : MenuServiceTest - hasProfanity() 생성
Dongock b26a63b
test(pos) : MenuServiceTest - changePrice() 생성
Dongock b41dc89
test(pos) : MenuServiceTest - compareMenuPrice() 생성
Dongock 891c839
test(pos) : MenuServiceTest - display() 생성
Dongock be9745a
test(pos) : MenuServiceTest - hide() 생성
Dongock e7a2a43
refactor(pos) : ProductServiceTest - findAll() 제거
Dongock 0915537
test(pos) : TextFixture - makeTestOrderTable() 생성
Dongock 169dbe5
refactor(pos) : TextFixture - name 매개변수로 변경
Dongock 0e8783e
test(pos) : OrderTableServiceTest - create() 생성
Dongock 4058c3d
test(pos) : OrderTableServiceTest - nullName() 생성
Dongock 788b51c
test(pos) : OrderTableServiceTest - sit() 생성
Dongock 969689c
test(pos) : OrderTableServiceTest - clear() 생성
Dongock 926b39f
refactor(pos) : TextFixture - makeTestOrderTable() 매개변수에 고객수 추가
Dongock 47e6451
test(pos) : OrderTableServiceTest - changeNumberOfGuests() 생성
Dongock d02cb1a
test(pos) : TestFixture - makeTestEatInOrder() & makeTestTakeOutOrder…
Dongock fa4e993
test(pos) : TestFixture - makeTestOrderLineItem() 생성
Dongock f1fcef2
test(pos) : OrderServiceTest - OrderServiceTest 테스트 및createEatInOrder…
Dongock 4252fe8
test(pos) : OrderServiceTest - createTakeOutOrder() 생성
Dongock 17ec2b7
test(pos) : OrderServiceTest - createDeliveryOrder() 생성
Dongock 678f914
test(pos) : OrderServiceTest - acceptEatInOrder() 생성
Dongock a6339fd
test(pos) : OrderServiceTest - acceptTakeOutOrder() 생성
Dongock 01e69f7
test(pos) : OrderServiceTest - acceptDeliveryOrder() 생성
Dongock fd55e81
test(pos) : OrderServiceTest - serveEatInOrder() 생성
Dongock 363a8a5
test(pos) : OrderServiceTest - serveTakeOutOrder() 생성
Dongock 2fb4b30
test(pos) : OrderServiceTest - serveDeliveryOrder() 생성
Dongock ad32cdf
test(pos) : OrderServiceTest - startDelivery() 생성
Dongock b5517eb
test(pos) : OrderServiceTest - completeDelivery() 생성
Dongock afb1747
test(pos) : OrderServiceTest - completeEatInOrder() 생성
Dongock cec4f6e
test(pos) : OrderServiceTest - completeTakeOutOrder() 생성
Dongock 5563b36
test(pos) : OrderServiceTest - completeDeliveryOrder() 생성
Dongock 772cc02
refactor(pos) : MenuServiceTest - minusPrice() 경계값 테스트
Dongock d91afb6
refactor(pos) : MenuGroupServiceTest - nullName() Emtpy 추가
Dongock 644d6c5
refactor(pos) : MenuGroupServiceTest - findAll 제거
Dongock 621183d
refactor(pos) : MenuGroupServiceTest - hasProfanity() / FakePurgomalu…
Dongock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,22 @@ | ||
# 문자열 계산기 요구사항 분석 | ||
|
||
1. 문자열이 들어왔을 때 형식에 맞는지 확인 | ||
1) 문자열 : String, 외부에서 입력된 글자 | ||
2) 형식 : 구분자를 기준으로 양쪽에 숫자로 변환이 가능한 글자가 있는지 | ||
- 예외1 : 빈 문자나 Null 입력 시 0 반환 | ||
- 예외2 : 구분자가 없이 숫자 하나만 들어왔을 경우 숫자를 반환 | ||
- 예외3 : 숫자로 변환 가능하지 않은 문자가 들어왔을 시 예외 발생 | ||
- 예외4 : 시작과 마지막이 숫자가 아니라면 예외 발생 | ||
3) 구분자 : 현재는 ,와 :인데 특정 상황에서 커스터마이징한 구분자 추가가 가능함 | ||
- 문제 : 구분자가 한개가 아니라면 그 사이 빈문자는 0으로 처리 | ||
4) 특정 상황 : 구분자로 정의한 문자 앞뒤에 `//`와 `\n`가 붙어 있음` | ||
- 예외 : 음수가 들어온다면 예외처리 | ||
|
||
2. 객체지향 필요 정리 | ||
1) Pattern은 무거우므로 재사용 가능하게 축출 | ||
2) 계산기의 역할이 너무 다양해지므로 관심사의 분리가 필요 | ||
- 구분자로 값을 처리하는 부분을 클래스 분리 | ||
- 예외 상황의 초기값이 들어왔을 때 처리를 클래스 분리 | ||
※ Front Controller | ||
- input이 들어왔을 때 어떤 계산 방법을 선택해야 하는지 확인하고(canCalculate) | ||
맞는 조건일 때 계산을 진행(sum) |
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,47 @@ | ||
package calculator; | ||
|
||
import java.util.Arrays; | ||
import java.util.regex.Pattern; | ||
|
||
public class BaseSeparatorStrategy implements CalculateStrategy { | ||
private static final Pattern CUSTOM_SEPARATOR_PATTERN = Pattern.compile("//(.)\\\\n(.*)"); | ||
private static final String SEPARATOR = "[,:]"; | ||
|
||
// 이 클래스가 과연 필요한가? | ||
@Override | ||
public int calculate(String input) { | ||
String[] splitInput = input.split(SEPARATOR); | ||
return sum(splitInput); | ||
} | ||
|
||
@Override | ||
public boolean canCalculate(String input) { | ||
return !CUSTOM_SEPARATOR_PATTERN.matcher(input).find() && !input.isEmpty(); | ||
} | ||
|
||
private int sum(String[] splitInput) { | ||
return Arrays.stream(splitInput) | ||
.mapToInt(this::convertToInt) | ||
.sum(); | ||
} | ||
|
||
private int convertToInt(String a) { | ||
if (a.isEmpty()) { | ||
return 0; | ||
} | ||
try { | ||
return convertToPositiveNumber(a); | ||
} catch (NumberFormatException e) { | ||
throw new RuntimeException("숫자의 형태가 아닙니다.", e); | ||
} | ||
|
||
} | ||
|
||
private int convertToPositiveNumber(String a) { | ||
int number = Integer.parseInt(a); | ||
if (number < 0) { | ||
throw new IllegalArgumentException("음수는 들어올 수 없습니다."); | ||
} | ||
return number; | ||
} | ||
} |
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 calculator; | ||
|
||
public interface CalculateStrategy { | ||
int calculate(String input); | ||
boolean canCalculate(String input); | ||
} |
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,24 @@ | ||
package calculator; | ||
|
||
import java.util.List; | ||
|
||
public class Calculator { | ||
|
||
private final List<CalculateStrategy> calculationStrategies; | ||
|
||
public Calculator() { | ||
this.calculationStrategies = List.of( | ||
new NoSeparatorStrategy(), | ||
new CustomSeparatorStrategy(), | ||
new BaseSeparatorStrategy() | ||
); | ||
} | ||
|
||
public int calculate(String input) { | ||
return calculationStrategies.stream() | ||
.filter(calculationStrategy -> calculationStrategy.canCalculate(input)) | ||
.findFirst() | ||
.map(calculationStrategy -> calculationStrategy.calculate(input)) | ||
.orElseThrow(() -> new RuntimeException("알맞는 계산기를 찾지 못했습니다.")); | ||
} | ||
} |
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,53 @@ | ||
package calculator; | ||
|
||
import java.util.Arrays; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
|
||
public class CustomSeparatorStrategy implements CalculateStrategy { | ||
private static final Pattern CUSTOM_SEPARATOR_PATTERN = Pattern.compile("//(.)\\\\n(.*)"); | ||
|
||
@Override | ||
public int calculate(String input) { | ||
Matcher m = CUSTOM_SEPARATOR_PATTERN.matcher(input); | ||
|
||
if (m.find()) { // find를 공통을 빼는 것? | ||
String customDelimiter = m.group(1); | ||
String[] splitInput = m.group(2).split(customDelimiter); | ||
return sum(splitInput); | ||
} else { | ||
throw new RuntimeException("커스텀 구분자가 들어오지 않았습니다."); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean canCalculate(String input) { | ||
return CUSTOM_SEPARATOR_PATTERN.matcher(input).find(); | ||
} | ||
|
||
private int sum(String[] splitInput) { | ||
return Arrays.stream(splitInput) | ||
.mapToInt(this::convertToInt) | ||
.sum(); | ||
} | ||
|
||
private int convertToInt(String a) { | ||
if (a.isEmpty()) { | ||
return 0; | ||
} | ||
try { | ||
return convertToPositiveNumber(a); | ||
} catch (NumberFormatException e) { | ||
throw new RuntimeException("숫자의 형태가 아닙니다.", e); | ||
} | ||
|
||
} | ||
|
||
private int convertToPositiveNumber(String a) { | ||
int number = Integer.parseInt(a); | ||
if (number < 0) { | ||
throw new IllegalArgumentException("음수는 들어올 수 없습니다."); | ||
} | ||
return number; | ||
} | ||
} |
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,17 @@ | ||
package calculator; | ||
|
||
public class NoSeparatorStrategy implements CalculateStrategy { | ||
@Override | ||
public int calculate(String input) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean canCalculate(String input) { | ||
return isEmpty(input); | ||
} | ||
|
||
private boolean isEmpty(String input) { | ||
return input == null || input.isBlank(); | ||
} | ||
} |
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,19 @@ | ||
package kitchenpos.infra; | ||
|
||
import org.springframework.boot.web.client.RestTemplateBuilder; | ||
|
||
import java.util.List; | ||
|
||
public class FakePurgomalumClient extends PurgomalumClient { | ||
|
||
private static final List<String> profanities = List.of("fuck", "shit"); | ||
|
||
public FakePurgomalumClient() { | ||
super(new RestTemplateBuilder()); | ||
} | ||
|
||
@Override | ||
public boolean containsProfanity(final String text) { | ||
return profanities.contains(text); | ||
} | ||
} |
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,25 @@ | ||
package racingcar; | ||
|
||
import java.util.Random; | ||
|
||
public class Car { | ||
private final String name; | ||
private int position; | ||
|
||
public Car(final String name) { | ||
if (name.length() > 5) { | ||
throw new IllegalArgumentException(); | ||
} | ||
this.name = name; | ||
} | ||
|
||
public int getPosition() { | ||
return position; | ||
} | ||
|
||
public void move(MovingStrategy movingStrategy) { | ||
if (movingStrategy.movable()) { | ||
position++; | ||
} | ||
} | ||
} |
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,5 @@ | ||
package racingcar; | ||
|
||
public interface MovingStrategy { | ||
boolean movable(); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 👍 👍 💯