test: ValidExchangeRequestValidatorTest more test cases & validator implementation

TODO: move disabled tests to future service / endpoint suite
This commit is contained in:
Piotr Dec 2024-05-23 18:22:25 +02:00
parent 8d722e3ce4
commit b5237c49bc
Signed by: stawros
GPG key ID: F89F27AD8F881A91
2 changed files with 46 additions and 12 deletions

View file

@ -2,8 +2,13 @@ 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.*;
@ -33,17 +38,13 @@ class ValidExchangeRequestValidatorTest extends ValidatorTest<ValidExchangeReque
.build()).isTrue();
}
@Test
@Disabled("Already validated (has field annotation)")
@DisplayName("Invalid PESEL value")
void invalidPeselTest() {
@ParameterizedTest
@MethodSource
void invalidPeselTest(String pesel) {
assertThatValidation(EntityCreator.exchangeRequest()
.pesel("INVALID")
.from(PLN_SYMBOL)
.to(USD_SYMBOL)
.toSell(USD_SELL)
.build()).isFalse();
assertThatValidation(EntityCreator.exchangeRequest()
.pesel(PESEL.replace('6', '7'))
.pesel(pesel)
.from(PLN_SYMBOL)
.to(USD_SYMBOL)
.toSell(USD_SELL)
@ -69,6 +70,26 @@ class ValidExchangeRequestValidatorTest extends ValidatorTest<ValidExchangeReque
.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() {
@ -100,4 +121,8 @@ class ValidExchangeRequestValidatorTest extends ValidatorTest<ValidExchangeReque
.build()).isFalse();
}
private static Stream<String> invalidPeselTest() {
return Stream.of("INVALID", PESEL.replace('6', '7'));
}
}