test: ValidExchangeRequestValidatorTest test cases

This commit is contained in:
Piotr Dec 2024-05-23 17:31:34 +02:00
parent ca2a6c1795
commit 8d722e3ce4
Signed by: stawros
GPG key ID: F89F27AD8F881A91
2 changed files with 70 additions and 9 deletions

View file

@ -2,6 +2,7 @@ package eu.ztsh.wymiana;
import eu.ztsh.wymiana.data.entity.CurrencyEntity;
import eu.ztsh.wymiana.data.entity.UserEntity;
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
import eu.ztsh.wymiana.web.model.UserCreateRequest;
import java.util.ArrayList;
@ -16,6 +17,12 @@ public class EntityCreator {
public static String NAME = "Janina";
public static String SURNAME = "Kowalska";
public static double PLN = 20.10;
public static double USD_SELL = 5.18;
public static double USD_BUY = 5.08;
public static String PLN_SYMBOL = "PLN";
public static String USD_SYMBOL = "USD";
public static double BUY_RATE = 3.8804;
public static double SELL_RATE = 3.9572;
}
@ -30,6 +37,11 @@ public class EntityCreator {
.pln(Constants.PLN);
}
public static CurrencyExchangeRequest.CurrencyExchangeRequestBuilder exchangeRequest() {
return CurrencyExchangeRequest.builder().pesel(Constants.PESEL);
}
public static class UserEntityBuilder {
String name;

View file

@ -1,9 +1,12 @@
package eu.ztsh.wymiana.validation;
import eu.ztsh.wymiana.EntityCreator;
import eu.ztsh.wymiana.web.model.CurrencyExchangeRequest;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import static eu.ztsh.wymiana.EntityCreator.Constants.*;
class ValidExchangeRequestValidatorTest extends ValidatorTest<ValidExchangeRequestValidator, CurrencyExchangeRequest> {
protected ValidExchangeRequestValidatorTest() {
@ -13,42 +16,88 @@ class ValidExchangeRequestValidatorTest extends ValidatorTest<ValidExchangeReque
@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();
}
@Test
@DisplayName("Invalid PESEL value")
void invalidPeselTest() {
assertThatValidation(EntityCreator.exchangeRequest()
.pesel("INVALID")
.from(PLN_SYMBOL)
.to(USD_SYMBOL)
.toSell(USD_SELL)
.build()).isFalse();
assertThatValidation(EntityCreator.exchangeRequest()
.pesel(PESEL.replace('6', '7'))
.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();
}
@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 amount value")
void negativeAmountTest() {
@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();
}
}