-
Notifications
You must be signed in to change notification settings - Fork 3
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
1 parent
5de1c6e
commit 0219de6
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/test/java/com/backendoori/ootw/weather/util/client/ForecastApiClientTest.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,65 @@ | ||
package com.backendoori.ootw.weather.util.client; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.NoSuchElementException; | ||
import java.util.stream.Stream; | ||
import com.backendoori.ootw.weather.dto.forecast.BaseDateTime; | ||
import com.backendoori.ootw.weather.util.BaseDateTimeCalculator; | ||
import net.datafaker.Faker; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.TestInstance.Lifecycle; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
@SpringBootTest | ||
@TestInstance(Lifecycle.PER_CLASS) | ||
class ForecastApiClientTest { | ||
|
||
static final Integer VALID_NX = 50; | ||
static final Integer VALID_NY = 127; | ||
static final BaseDateTime TEMP_BASE_DATETIME = BaseDateTimeCalculator.getRequestBaseDateTime(LocalDateTime.now()); | ||
static Faker faker = new Faker(); | ||
|
||
@Autowired | ||
ForecastApi forecastApi; | ||
@Autowired | ||
ForecastApiClient forecastApiClient; | ||
|
||
|
||
static Stream<Arguments> provideInvalidRange() { | ||
return Stream.of( | ||
Arguments.of(faker.number().negative(), VALID_NY), | ||
Arguments.of(VALID_NX, faker.number().negative()), | ||
Arguments.of(faker.number().numberBetween(1000, 10000), VALID_NY), | ||
Arguments.of(VALID_NX, faker.number().numberBetween(1000, 10000))); | ||
} | ||
|
||
@Test | ||
@DisplayName("정보가 없는 위치 값으로 현재 날씨 불러오기에 실패한다.") | ||
void requestUltraShortForecastItemsFailByNoSuchElementException() { | ||
// given | ||
Integer nx = 0; | ||
Integer ny = 0; | ||
|
||
// when // then | ||
assertThrows(NoSuchElementException.class, | ||
() -> forecastApiClient.requestUltraShortForecastItems(TEMP_BASE_DATETIME, nx, ny)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("provideInvalidRange") | ||
@DisplayName("유효하지 않은 파라미터 범위로 현재 날씨 불러오기에 실패한다.") | ||
void requestUltraShortForecastItemsFailByIllegalRange(Integer nx, Integer ny) { | ||
// given // when // then | ||
assertThrows(IllegalArgumentException.class, | ||
() -> forecastApiClient.requestUltraShortForecastItems(TEMP_BASE_DATETIME, nx, ny)); | ||
} | ||
|
||
} |