Skip to content

Commit c61aa9f

Browse files
김산김산
authored andcommitted
[#14] Feat, Test: converting kind of meal to its type
1 parent 7aa3c14 commit c61aa9f

File tree

5 files changed

+64
-13
lines changed

5 files changed

+64
-13
lines changed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ dependencies {
2525

2626
testImplementation 'org.springframework.boot:spring-boot-starter-test'
2727
testImplementation 'org.junit.platform:junit-platform-launcher:1.5.0'
28-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.5.0'
29-
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.5.0'
28+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.9.1'
29+
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.9.1'
3030

3131
}
3232

src/main/java/com/example/helper/constant/SpecMealInputsKor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,12 @@ public String getInputs() {
2828
return input;
2929
}
3030
public Integer getInputValue() { return inputValue; }
31+
32+
public static Integer getTypeByString(String str){
33+
for(SpecMealInputsKor each : values())
34+
if (each.getInputs().equals(str)) {
35+
return each.getInputValue();
36+
}
37+
return null;
38+
}
3139
}

src/main/java/com/example/helper/constant/Types.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ public enum Types {
1010
KIND_LUNCH(1),
1111
KIND_DINNER(2),
1212
KIND_LUNCH_CORNER(3),
13-
DATE_MON(0),
14-
DATE_TUE(1),
15-
DATE_WED(2),
16-
DATE_THR(3),
17-
DATE_FRI(4),
18-
DATE_SAT(5),
19-
DATE_SUN(6);
13+
DATE_MON(1),
14+
DATE_TUE(2),
15+
DATE_WED(3),
16+
DATE_THR(4),
17+
DATE_FRI(5),
18+
DATE_SAT(6),
19+
DATE_SUN(7);
2020

2121
private Integer type;
2222

src/main/java/com/example/helper/service/MealService.java

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ else if(19 <= hour && hour < 24) {
7272

7373
Optional<Meal> result = sqlMealRepository.findByDate(Types.BLDG2_1ST.getType(), langType, kindType, date);
7474

75+
// TODO: 함수로 분리
7576
if(result.isEmpty()) {
7677
//throw new IllegalStateException(Messages.EXIST_MEAL_ERROR.getMessages());
7778
if(langType == 0) {
@@ -86,10 +87,11 @@ else if(19 <= hour && hour < 24) {
8687
}
8788

8889
private Boolean specInputValidation(String dateCustom, String bld) {
89-
// len = 0 or null or ...
90-
Boolean ret = true;
91-
92-
return ret;
90+
// input arguments : null, empty, " "
91+
if (dateCustom == null || bld == null || dateCustom.isBlank() || bld.isBlank()) {
92+
return false;
93+
}
94+
return true;
9395
}
9496

9597
public String getNowKorMeal() {
@@ -105,8 +107,19 @@ public String getSpecKorMeal(String dateCustom, String bld) {
105107
return Messages.NO_MEAL_KOR.getMessages();
106108
}
107109

110+
LocalDateTime currentDateTime = LocalDateTime.now(ZoneId.of("Asia/Seoul"));
111+
108112
if(dateCustom.equals(SpecMealInputsKor.TODAY.getInputs())) {
109113
// 오늘
114+
String date = currentDateTime.getYear() + "-";
115+
date += String.format("%02d", currentDateTime.getMonth().getValue()) + "-";
116+
date += String.format("%02d", currentDateTime.getDayOfMonth()) + "";
117+
118+
Optional<Meal> result = sqlMealRepository.findByDate(
119+
Types.BLDG2_1ST.getType(),
120+
Types.LANG_KOR.getType(),
121+
SpecMealInputsKor.getTypeByString(bld),
122+
date);
110123
}
111124
else if(dateCustom.equals(SpecMealInputsKor.TOMORROW.getInputs())) {
112125
// 내일
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package com.example.helper.constant;
2+
3+
import static com.example.helper.constant.SpecMealInputsKor.*;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
6+
import java.util.stream.Stream;
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.Arguments;
9+
import org.junit.jupiter.params.provider.MethodSource;
10+
11+
class SpecMealInputsKorTest {
12+
13+
@ParameterizedTest
14+
@MethodSource("provideStringsForIsTypes")
15+
void enum_한국어식단_타입변환(String kind, Integer expected) {
16+
// given
17+
// when
18+
Integer result = getTypeByString(kind);
19+
// then
20+
assertEquals(expected, result);
21+
}
22+
23+
private static Stream<Arguments> provideStringsForIsTypes() {
24+
return Stream.of(
25+
Arguments.of(BREAKFAST.getInputs(), BREAKFAST.getInputValue()),
26+
Arguments.of(LUNCH.getInputs(), LUNCH.getInputValue()),
27+
Arguments.of(DINNER.getInputs(), DINNER.getInputValue())
28+
);
29+
}
30+
}

0 commit comments

Comments
 (0)