test: NbpServiceTest completed?

This commit is contained in:
Piotr Dec 2024-05-23 22:38:20 +02:00
parent b2cbfad2ac
commit b38a507ce9
Signed by: stawros
GPG key ID: F89F27AD8F881A91
4 changed files with 59 additions and 15 deletions

View file

@ -0,0 +1,18 @@
package eu.ztsh.wymiana.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestClient;
@Configuration
public class RestClientConfiguration {
@Bean
public RestClient restClient() {
return RestClient.builder()
.baseUrl("http://api.nbp.pl")
.defaultHeader("Accept", "application/json")
.build();
}
}

View file

@ -4,6 +4,7 @@ import eu.ztsh.wymiana.model.Rates;
import lombok.RequiredArgsConstructor;
import org.assertj.core.util.VisibleForTesting;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClient;
import java.time.Clock;
import java.time.DayOfWeek;
@ -18,6 +19,8 @@ import java.time.temporal.TemporalAdjusters;
public class NbpService {
private final Clock clock;
private final RestClient restClient;
private static final String URI_PATTERN = "/api/exchangerates/rates/c/{code}/{date}/";
public double getSellRate(String currency) {
throw new UnsupportedOperationException("Not implemented yet");
@ -41,7 +44,7 @@ public class NbpService {
}
@VisibleForTesting
Rates fetchData(String date) {
Rates fetchData(String code, String date) {
throw new UnsupportedOperationException("Not implemented yet");
}
@ -49,6 +52,7 @@ public class NbpService {
return today.getDayOfWeek() == DayOfWeek.SATURDAY
|| today.getDayOfWeek() == DayOfWeek.SUNDAY;
}
private record RatesCache(LocalDate date, double buy, double sell) {
}