konta-walutowe/src/test/java/eu/ztsh/wymiana/validation/ValidExchangeRequestValidatorTest.java
2024-05-23 18:22:25 +02:00

128 lines
3.7 KiB
Java

package eu.ztsh.wymiana.validation;
import eu.ztsh.wymiana.EntityCreator;
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.stream.Stream;
import static eu.ztsh.wymiana.EntityCreator.Constants.*;
class ValidExchangeRequestValidatorTest extends ValidatorTest<ValidExchangeRequestValidator, CurrencyExchangeRequest> {
protected ValidExchangeRequestValidatorTest() {
super(new ValidExchangeRequestValidator());
}
@Test
@DisplayName("Valid request with buy value specified")
void validRequestWithBuyTest() {
assertThatValidation(EntityCreator.exchangeRequest()
.from(PLN_SYMBOL)
.to(USD_SYMBOL)
.toBuy(USD_BUY)
.build()).isTrue();
}
@Test
@DisplayName("Valid request with sell value specified")
void validRequestWithSellTest() {
assertThatValidation(EntityCreator.exchangeRequest()
.from(PLN_SYMBOL)
.to(USD_SYMBOL)
.toSell(USD_SELL)
.build()).isTrue();
}
@Disabled("Already validated (has field annotation)")
@DisplayName("Invalid PESEL value")
@ParameterizedTest
@MethodSource
void invalidPeselTest(String pesel) {
assertThatValidation(EntityCreator.exchangeRequest()
.pesel(pesel)
.from(PLN_SYMBOL)
.to(USD_SYMBOL)
.toSell(USD_SELL)
.build()).isFalse();
}
@Test
@DisplayName("From and To have same value")
void sameFromToTest() {
assertThatValidation(EntityCreator.exchangeRequest()
.from(USD_SYMBOL)
.to(USD_SYMBOL)
.toSell(USD_SELL)
.build()).isFalse();
}
@Test
@DisplayName("Empty amounts")
void emptyBuySellTest() {
assertThatValidation(EntityCreator.exchangeRequest()
.from(PLN_SYMBOL)
.to(USD_SYMBOL)
.build()).isFalse();
}
@Disabled("Already validated (has field annotation)")
@Test
@DisplayName("Empty 'from' value")
void emptyFromTest() {
assertThatValidation(EntityCreator.exchangeRequest()
.to(USD_SYMBOL)
.toSell(USD_SELL)
.build()).isFalse();
}
@Disabled("Already validated (has field annotation)")
@Test
@DisplayName("Empty 'to' value")
void emptyToTest() {
assertThatValidation(EntityCreator.exchangeRequest()
.from(PLN_SYMBOL)
.toSell(USD_SELL)
.build()).isFalse();
}
@Test
@DisplayName("Both Buy and Sell params filled in")
void bothFilledBuySellTest() {
assertThatValidation(EntityCreator.exchangeRequest()
.from(PLN_SYMBOL)
.to(USD_SYMBOL)
.toBuy(USD_BUY)
.toSell(USD_SELL)
.build()).isFalse();
}
@Test
@DisplayName("Negative buy amount value")
void negativeBuyAmountTest() {
assertThatValidation(EntityCreator.exchangeRequest()
.from(PLN_SYMBOL)
.to(USD_SYMBOL)
.toBuy(-1.0)
.build()).isFalse();
}
@Test
@DisplayName("Negative sell amount value")
void negativeSellAmountTest() {
assertThatValidation(EntityCreator.exchangeRequest()
.from(PLN_SYMBOL)
.to(USD_SYMBOL)
.toSell(-1.0)
.build()).isFalse();
}
private static Stream<String> invalidPeselTest() {
return Stream.of("INVALID", PESEL.replace('6', '7'));
}
}