created mapOffer test
This commit is contained in:
@@ -1,5 +1,63 @@
|
||||
package de.rwu.easydrop.service.mapping;
|
||||
|
||||
public class OfferMapperTest {
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Modifier;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import de.rwu.easydrop.api.dto.OfferDTO;
|
||||
import de.rwu.easydrop.model.Offer;
|
||||
import de.rwu.easydrop.model.Product;
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
|
||||
class OfferMapperTest {
|
||||
|
||||
@Test
|
||||
void testConstructorIsPrivate()
|
||||
throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
|
||||
// Check for private constructor
|
||||
Constructor<OfferMapper> constructor = OfferMapper.class.getDeclaredConstructor();
|
||||
assertTrue(Modifier.isPrivate(constructor.getModifiers()));
|
||||
|
||||
// Make sure exception is thrown when instantiating
|
||||
constructor.setAccessible(true);
|
||||
assertThrows(InvocationTargetException.class, () -> {
|
||||
constructor.newInstance();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void mapOfferToDTO() {
|
||||
// Arrange
|
||||
Product product = new Product();
|
||||
product.setProductId("12345");
|
||||
product.setDataOrigin(Webshop.AMAZON);
|
||||
product.setAvailable(true);
|
||||
product.setCurrentPrice(9.99);
|
||||
product.setDeliveryPrice(2.50);
|
||||
product.setMerchant("Seller1");
|
||||
|
||||
Offer offer = new Offer();
|
||||
offer.setOfferId("68735");
|
||||
offer.setLastUpdate("2020-07-07");
|
||||
offer.setSourceProduct(product);
|
||||
offer.setTargetProduct(product);
|
||||
|
||||
// Act
|
||||
OfferDTO dto = OfferMapper.mapOfferToDTO(offer);
|
||||
|
||||
// Assert
|
||||
assertEquals("68735", dto.getOfferId());
|
||||
assertEquals("2020-07-07", dto.getLastUpdate());
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ import de.rwu.easydrop.exception.InvalidOfferException;
|
||||
import de.rwu.easydrop.model.Offer;
|
||||
|
||||
|
||||
public class OfferValidatorTest {
|
||||
class OfferValidatorTest {
|
||||
|
||||
@Test
|
||||
void validate_Offer_ValidProduct_NoExceptionThrown() {
|
||||
|
||||
@@ -16,7 +16,7 @@ import de.rwu.easydrop.model.Offer;
|
||||
import de.rwu.easydrop.model.Product;
|
||||
import de.rwu.easydrop.model.Webshop;
|
||||
|
||||
public class OfferWriterTest {
|
||||
class OfferWriterTest {
|
||||
|
||||
@Mock
|
||||
private OfferDTO offerDTO;
|
||||
|
||||
Reference in New Issue
Block a user