Commit 9db57a1f authored by Jan Novák's avatar Jan Novák

basics of DiscountedItemTest.java

parent d5dbf2a5
Pipeline #4029 passed with stage
in 29 seconds
package cz.cvut.eshop.shop;
import org.junit.*;
import org.junit.runners.MethodSorters;
import java.util.Date;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class DiscountedItemTest {
private Date fromDate;
private Date toDate;
private int id;
private float price;
private int discountValid, discountInvalidSmall, discountInvalidLarge;
private String itemName, itemCategory;
@BeforeClass
public static void setUpClass() {
}
@Before
public void setUp() {
/*
Creating Date object using different constructor than Date() and Date(long milisSinceEpochBegining)
is deprecated!
*/
fromDate = new Date(1538352000L); // Oct-01-2018
toDate = new Date(1541030399L); // Oct-30-2018
id = 1;
price = 50.0f;
discountValid = 45;
discountInvalidSmall = -2;
discountInvalidLarge = 250;
itemName = "TestName";
itemCategory = "TestCategory";
}
@Test
public void Test001CreateDiscountedItemWithDateRangeByDateObject() {
/*
Creating Date object using different constructor than Date() and Date(long milisSinceEpochBegining)
is deprecated!
*/
DiscountedItem d = new DiscountedItem(id, itemName, price, itemCategory, discountValid, fromDate, toDate);
Assert.assertNotNull(d);
}
@Test
public void Test002CreateDiscountedItemWithDateRangeByValidDateString() {
/*
Creating Date object using different constructor than Date() and Date(long milisSinceEpochBegining)
is deprecated!
*/
String fromDate = "03.05.2002";
String toDate = "03.05.2003";
DiscountedItem d = new DiscountedItem(id, itemName, price, itemCategory, discountInvalidLarge, fromDate, toDate);
Assert.assertNotNull(d);
}
@Test
public void Test003CreateDiscountedItemWithDateRangeByInvalidFromDateString() {
/*
Creating Date object using different constructor than Date() and Date(long milisSinceEpochBegining)
is deprecated!
*/
// expected valid date format is dd.mm.yyyy, let's do an invalid one and await null upon object creation attempt
String fromDate = "3.2002";
String toDate = "03.05.2003";
DiscountedItem d = new DiscountedItem(id, itemName, price, itemCategory, discountInvalidSmall, fromDate, toDate);
Assert.assertNull(d.getDiscountFrom());
}
@Test
public void Test004CreateDiscountedItemWithDateRangeByInvalidFromDateString() {
/*
Creating Date object using different constructor than Date() and Date(long milisSinceEpochBegining)
is deprecated!
*/
// expected valid date format is dd.mm.yyyy, let's do an invalid one and await null upon object creation attempt
String fromDate = "3.5.2002";
String toDate = "03..2003";
int id = 2;
float price = 105.0f;
int discount = 200;
String name = "TestName";
String category = "TestCategory";
DiscountedItem d = new DiscountedItem(id, name, price, category, discount, fromDate, toDate);
Assert.assertNull(d.getDiscountTo());
}
@Test
public void Test0053DiscountedItemsAreEqual() {
}
@Test
public void Test006DiscountedItemsAreNotEqual() {
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment