Compare commits
No commits in common. "b07fa4cb65c20ba30919459c6a2dbf690a3cf8b8" and "52ff4a67b3c8d0f900b68ac1f738f36edf309543" have entirely different histories.
b07fa4cb65
...
52ff4a67b3
3 changed files with 0 additions and 80 deletions
|
@ -1,9 +0,0 @@
|
||||||
package eu.ztsh.wymiana.exception;
|
|
||||||
|
|
||||||
public class InsufficientFundsException extends RuntimeException {
|
|
||||||
|
|
||||||
public InsufficientFundsException() {
|
|
||||||
super("Insufficient funds");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,21 +0,0 @@
|
||||||
package eu.ztsh.wymiana.service;
|
|
||||||
|
|
||||||
import eu.ztsh.wymiana.model.User;
|
|
||||||
import eu.ztsh.wymiana.validation.InstanceValidator;
|
|
||||||
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import org.springframework.stereotype.Service;
|
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
@Service
|
|
||||||
public class CurrencyService {
|
|
||||||
|
|
||||||
private final UserService userService;
|
|
||||||
private final NbpService nbpService;
|
|
||||||
private final InstanceValidator validator;
|
|
||||||
|
|
||||||
public User exchange(CurrencyExchangeRequest request) {
|
|
||||||
throw new UnsupportedOperationException("Not implemented yet");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,50 +0,0 @@
|
||||||
package eu.ztsh.wymiana.service;
|
|
||||||
|
|
||||||
import eu.ztsh.wymiana.EntityCreator;
|
|
||||||
import eu.ztsh.wymiana.RepositoryBasedTest;
|
|
||||||
import eu.ztsh.wymiana.data.repository.UserRepository;
|
|
||||||
import eu.ztsh.wymiana.exception.InsufficientFundsException;
|
|
||||||
import eu.ztsh.wymiana.validation.InstanceValidator;
|
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.mockito.Mockito;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
|
|
||||||
import static eu.ztsh.wymiana.EntityCreator.Constants.*;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
|
||||||
|
|
||||||
class CurrencyServiceTest extends RepositoryBasedTest {
|
|
||||||
|
|
||||||
private final CurrencyService currencyService;
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public CurrencyServiceTest(UserRepository userRepository, InstanceValidator instanceValidator) {
|
|
||||||
super(userRepository);
|
|
||||||
var nbp = Mockito.mock(NbpService.class);
|
|
||||||
Mockito.when(nbp.getSellRate("USD")).thenReturn(USD_SELL);
|
|
||||||
Mockito.when(nbp.getBuyRate("USD")).thenReturn(USD_BUY);
|
|
||||||
currencyService = new CurrencyService(new UserService(userRepository, instanceValidator), nbp, instanceValidator);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void successTest() {
|
|
||||||
var result = currencyService.exchange(EntityCreator.exchangeRequest()
|
|
||||||
.from(PLN_SYMBOL)
|
|
||||||
.to(USD_SYMBOL)
|
|
||||||
.toSell(PLN)
|
|
||||||
.build());
|
|
||||||
assertThat(result.currencies())
|
|
||||||
.matches(map -> map.get(PLN_SYMBOL).amount() == 0 && map.get(USD_SYMBOL).amount() == USD_BUY);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
void insufficientFundsTest() {
|
|
||||||
assertThatThrownBy(() -> currencyService.exchange(EntityCreator.exchangeRequest()
|
|
||||||
.from(PLN_SYMBOL)
|
|
||||||
.to(USD_SYMBOL)
|
|
||||||
.toBuy(PLN)
|
|
||||||
.build()))
|
|
||||||
.isInstanceOf(InsufficientFundsException.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
Loading…
Add table
Add a link
Reference in a new issue