-
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.
chore: Controller 및 DateProvider 테스트 코드 작성
- DateProviderTest: findNearestWeekDay() 관련 테스트 코드 작성 - EveryCalendarControllerTest: URL validate 관련 테스트 코드 작성 issue: #35
- Loading branch information
1 parent
6147292
commit b41ce4d
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
src/test/java/dev/whteb/everyCalendar/Controller/EveryCalendarControllerTest.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,20 @@ | ||
package dev.whteb.everyCalendar.Controller; | ||
|
||
|
||
import dev.whteb.everyCalendar.DTO.GetIcsDTO; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Date; | ||
|
||
class EveryCalendarControllerTest { | ||
|
||
@Test | ||
void 캘린더_URL이_잘못된_경우_예외를_던진다() { | ||
EveryCalendarController everyCalendarController = new EveryCalendarController(null); | ||
Assertions.assertThrows(Exception.class, () -> { | ||
everyCalendarController.getIcs(new GetIcsDTO("https://whiteb.dev/@3a123adkl1", new Date(), new Date()), null); | ||
}); | ||
|
||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/dev/whteb/everyCalendar/Provider/DateProviderTest.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,45 @@ | ||
package dev.whteb.everyCalendar.Provider; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.Calendar; | ||
import java.util.Date; | ||
import java.util.Locale; | ||
import java.util.TimeZone; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
class DateProviderTest { | ||
static Date base; | ||
static DateProvider dateProvider; | ||
@BeforeAll | ||
static void beforeAll() { | ||
base = getSpecificDate(2024, Calendar.JANUARY, 5); | ||
dateProvider = new DateProvider(); | ||
System.out.println("base = " + base); | ||
} | ||
|
||
@Test | ||
void 특정_요일_가장_가까운_날짜를_반환한다() { | ||
Date thursday = dateProvider.findNearestWeekDay(Calendar.THURSDAY, base); | ||
System.out.println("thursday = " + thursday); | ||
assertThat(thursday).isEqualTo(getSpecificDate(2024, Calendar.JANUARY, 11)); | ||
} | ||
|
||
@Test | ||
void 시작일은_기간에_포함된다() { | ||
Date friday = dateProvider.findNearestWeekDay(Calendar.FRIDAY, base); | ||
System.out.println("friday = " + friday); | ||
assertThat(friday.getTime()).isEqualTo(base.getTime()); | ||
} | ||
|
||
static Date getSpecificDate(int year, int month, int date) { | ||
Calendar calendar = Calendar.getInstance(Locale.KOREA); | ||
calendar.setTimeZone(TimeZone.getTimeZone("Asia/Seoul")); | ||
calendar.setTimeInMillis(0); | ||
calendar.set(year, month, date, 0, 0, 0); | ||
return new Date(calendar.getTimeInMillis()); | ||
} | ||
|
||
} |