Added/updated tests
This commit is contained in:
@@ -1,33 +1,56 @@
|
||||
package de.rwu.easydrop.api.dto;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class ProductDTOTest {
|
||||
|
||||
@Test
|
||||
void testToString1() {
|
||||
ProductDTO product1 = new ProductDTO("12345", "Amazon");
|
||||
product1.setMerchant("Merchant A");
|
||||
product1.setCurrentPrice(19.99);
|
||||
product1.setAvailable(true);
|
||||
void constructor_SetsProductIdAndDataOrigin() {
|
||||
// Arrange
|
||||
String productId = "12345";
|
||||
String dataOrigin = "Amazon";
|
||||
|
||||
String expectedString1 = "ProductDTO{12345 from Merchant A (Amazon) at 19,99 € (available: yes)}";
|
||||
String result1 = product1.toString();
|
||||
// Act
|
||||
ProductDTO productDTO = new ProductDTO(productId, dataOrigin);
|
||||
|
||||
assertEquals(expectedString1, result1);
|
||||
// Assert
|
||||
assertEquals(productId, productDTO.getProductId());
|
||||
assertEquals(dataOrigin, productDTO.getDataOrigin());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testToString2() {
|
||||
ProductDTO product2 = new ProductDTO("67890", "eBay");
|
||||
product2.setMerchant("Merchant B");
|
||||
product2.setCurrentPrice(9.99);
|
||||
product2.setAvailable(false);
|
||||
void gettersAndSetters_WorkAsExpected() {
|
||||
// Arrange
|
||||
ProductDTO productDTO = new ProductDTO("12345", "Amazon");
|
||||
|
||||
String expectedString2 = "ProductDTO{67890 from Merchant B (eBay) at 9,99 € (available: no)}";
|
||||
String result2 = product2.toString();
|
||||
// Act and Assert
|
||||
assertEquals("12345", productDTO.getProductId());
|
||||
assertEquals("Amazon", productDTO.getDataOrigin());
|
||||
|
||||
assertEquals(expectedString2, result2);
|
||||
// Modify fields
|
||||
productDTO.setProductId("54321");
|
||||
productDTO.setDataOrigin("eBay");
|
||||
|
||||
// Assert
|
||||
assertEquals("54321", productDTO.getProductId());
|
||||
assertEquals("eBay", productDTO.getDataOrigin());
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultConstructor_SetsDefaultValues() {
|
||||
// Act
|
||||
ProductDTO productDTO = new ProductDTO(null, null);
|
||||
|
||||
// Assert
|
||||
assertNull(productDTO.getProductId());
|
||||
assertNull(productDTO.getDataOrigin());
|
||||
assertEquals(0.0, productDTO.getCurrentPrice());
|
||||
assertNull(productDTO.getMerchant());
|
||||
assertEquals(0.0, productDTO.getDeliveryPrice());
|
||||
assertFalse(productDTO.isAvailable());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user