added ParameterizedTest for offer validator

This commit is contained in:
Alexander Maier
2023-06-27 18:32:15 +02:00
parent 0eb0f903c6
commit 7056d34688
2 changed files with 26 additions and 1 deletions

View File

@@ -28,6 +28,9 @@ public final class OfferValidator {
if (offer.getOfferId().equals("")) { if (offer.getOfferId().equals("")) {
throw new InvalidOfferException("Offer ID cannot be empty"); throw new InvalidOfferException("Offer ID cannot be empty");
} }
if (offer.getLastUpdate().equals("")) {
throw new InvalidOfferException("LastUpdate cannot be empty");
}
} catch (NullPointerException e) { } catch (NullPointerException e) {
throw new InvalidOfferException("Required information is missing in the offer", e); throw new InvalidOfferException("Required information is missing in the offer", e);
} }

View File

@@ -3,6 +3,8 @@ package de.rwu.easydrop.service.validation;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;
import java.util.stream.Stream;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource; import org.junit.jupiter.params.provider.MethodSource;
@@ -25,11 +27,31 @@ public class OfferValidatorTest {
} }
@ParameterizedTest @ParameterizedTest
@MethodSource("invalidOffer") @MethodSource("invalidOfferProvider")
void validate_InvalidOffer_ThrowsInvalidOfferException(Offer offer) { void validate_InvalidOffer_ThrowsInvalidOfferException(Offer offer) {
// Act and Assert // Act and Assert
assertThrows(InvalidOfferException.class, () -> OfferValidator.validate(offer)); assertThrows(InvalidOfferException.class, () -> OfferValidator.validate(offer));
} }
static Stream<Offer> invalidOfferProvider() {
return Stream.of(
createOfferWithEmptylastUpdate(),
createOfferWithEmptyId());
}
private static Offer createOfferWithEmptylastUpdate() {
Offer offer = new Offer();
offer.setOfferId("3729798");
offer.setLastUpdate("");
return offer;
}
private static Offer createOfferWithEmptyId() {
Offer offer = new Offer();
offer.setOfferId("");
offer.setLastUpdate("8798476");
return offer;
}
} }