Skip to content
Snippets Groups Projects
Commit 9dc27f55 authored by cristiano's avatar cristiano
Browse files

Merge branch 'master' of gitlab.inf.unibz.it:TTST1920/clar

parents f834f9e5 1265f631
No related branches found
No related tags found
No related merge requests found
......@@ -23,5 +23,16 @@
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>
</classpath>
......@@ -80,7 +80,7 @@ public class AuctionManager {
public static Date parseDate(String value) {
Date date = null;
String format = "dd/MM/yyyy hh:mm:ss";
String format = "dd/MM/yyyy HH:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
......
package unitTest;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Random;
import java.util.function.Function;
import java.util.stream.Stream;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.function.Executable;
import org.junit.jupiter.api.function.ThrowingConsumer;
import exceptions.ImageInvalidException;
import project.Auction;
......@@ -25,7 +19,7 @@ import project.ItemPicture;
import project.User;
public class ItemPictureUnitTest {
@BeforeEach
public void reset() {
......@@ -37,40 +31,50 @@ public class ItemPictureUnitTest {
}
@TestFactory
public Collection<DynamicTest> ItemPictureUnitTest() throws ImageInvalidException {
public Collection<DynamicTest> addPictureAcceptanceTest() throws ImageInvalidException {
Item i = Item.getInstance();
ArrayList<ItemPicture> rightList = new ArrayList<ItemPicture>();
for(int x = 0; x < 10; x++) {
for (int x = 0; x < 10; x++) {
rightList.add(new ItemPicture(x));
}
i.addPicture(rightList);
ArrayList<ItemPicture> wrongList = new ArrayList<ItemPicture>();
for(int x = 10; x < 20; x++) {
for (int x = 10; x < 20; x++) {
wrongList.add(new ItemPicture(x));
}
Collection<DynamicTest> dynamicTests = new ArrayList<DynamicTest>();
for(int e = 0; e < rightList.size(); e++) {
for (int e = 0; e < rightList.size(); e++) {
ItemPicture toRemove = rightList.get(e);
Executable exec = () -> assertTrue(ItemPicture.remove(toRemove.getId(), i));
DynamicTest dTest = DynamicTest.dynamicTest("Existing images", exec);
dynamicTests.add(dTest);
}
for(int e = 0; e < wrongList.size(); e++) {
for (int e = 0; e < wrongList.size(); e++) {
ItemPicture toRemove = wrongList.get(e);
Executable exec = () -> assertFalse(ItemPicture.remove(toRemove.getId(), i));
DynamicTest dTest = DynamicTest.dynamicTest("Not existen images", exec);
dynamicTests.add(dTest);
}
return dynamicTests;
}
}
......@@ -24,7 +24,6 @@ import org.junit.jupiter.params.provider.ValueSource;
import exceptions.CategoryInvalidException;
import exceptions.DescriptionInvalidException;
import exceptions.ImageInvalidException;
import exceptions.PriceInvalidException;
import exceptions.TitleInvalidException;
import project.Auction;
import project.Category;
......@@ -33,7 +32,7 @@ import project.ItemPicture;
import project.User;
public class ItemUnitTest {
@BeforeEach
public void reset() {
......@@ -51,8 +50,7 @@ public class ItemUnitTest {
int itemId;
Random random = new Random();
@Override
public boolean hasNext() {
......@@ -112,34 +110,7 @@ public class ItemUnitTest {
}
@TestFactory
public Collection<DynamicTest> modifyTest() {
ArrayList<String> title = new ArrayList<String>(
Arrays.asList("", "9999", "t-#\\", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"));
ArrayList<String> description = new ArrayList<String>(Arrays.asList("", "9999",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"
+ "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n" + "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\r\n"
+ "aaaaaaaaaaaaaaaa"));
ArrayList<String> category = new ArrayList<String>(Arrays.asList("bike"));
ArrayList<String> titleTestNames = new ArrayList<String>(Arrays.asList("title empty", "numerical title",
"symbols present in the title", "title longer than 30 characters", "cateogry not correct"));
ArrayList<String> descriptionTestNames = new ArrayList<String>(
Arrays.asList("description empty", "numerical description", "title longer than 500 characters"));
ArrayList<String> categoryTestNames = new ArrayList<String>(Arrays.asList("cateogry not correct"));
ArrayList<Class<? extends Exception>> titleExceptions = new ArrayList<Class<? extends Exception>>(
Arrays.asList(TitleInvalidException.class, TitleInvalidException.class, TitleInvalidException.class,
TitleInvalidException.class));
ArrayList<Class<? extends Exception>> descriptionExceptions = new ArrayList<Class<? extends Exception>>(
Arrays.asList(DescriptionInvalidException.class, DescriptionInvalidException.class,
DescriptionInvalidException.class));
ArrayList<Class<? extends Exception>> categoryExceptions = new ArrayList<Class<? extends Exception>>(
Arrays.asList(CategoryInvalidException.class));
public Collection<DynamicTest> modifyAcceptanceTest() {
Collection<DynamicTest> dynamicTests = new ArrayList<DynamicTest>();
......@@ -148,30 +119,70 @@ public class ItemUnitTest {
item.setDescription("description");
item.setCategory(new Category("camera"));
for (int i = 0; i < title.size(); i++) {
ArrayList<String> titles = new ArrayList<String>(Arrays.asList("", "9999", "t-#\\", ""));
ArrayList<String> titleTestNames = new ArrayList<String>(Arrays.asList("title empty", "numerical title",
"symbols present in the title", "title longer than 30 characters", "cateogry not correct"));
ArrayList<Class<? extends Exception>> titleExceptions = new ArrayList<Class<? extends Exception>>(
Arrays.asList(TitleInvalidException.class, TitleInvalidException.class, TitleInvalidException.class,
TitleInvalidException.class));
for (int i = 0; i < titles.size(); i++) {
String prepareTitle = titles.get(i);
final int j = i;
if (i == 3) {
for (int k = 0; k < 60; k++) {
prepareTitle += "a";
}
}
final String title = prepareTitle;
final int j = i;
Executable exec = () -> assertThrows(titleExceptions.get(j),
() -> item.modify(title.get(j), "description", "camera"));
() -> item.modify(title, "description", "camera"));
DynamicTest dTest = DynamicTest.dynamicTest(titleTestNames.get(i), exec);
dynamicTests.add(dTest);
}
for (int i = 0; i < description.size(); i++) {
ArrayList<String> descriptions = new ArrayList<String>(Arrays.asList("", "9999", ""));
ArrayList<String> descriptionTestNames = new ArrayList<String>(
Arrays.asList("description empty", "numerical description", "title longer than 500 characters"));
ArrayList<Class<? extends Exception>> descriptionExceptions = new ArrayList<Class<? extends Exception>>(
Arrays.asList(DescriptionInvalidException.class, DescriptionInvalidException.class,
DescriptionInvalidException.class));
final int j = i;
for (int i = 0; i < descriptions.size(); i++) {
String prepareDescription = descriptions.get(i);
if (i == 2) {
for (int k = 0; k < 600; k++) {
prepareDescription += "a";
}
}
final String description = prepareDescription;
final int j = i;
Executable exec = () -> assertThrows(descriptionExceptions.get(j),
() -> item.modify("title", description.get(j), "camera"));
() -> item.modify("title", description, "camera"));
DynamicTest dTest = DynamicTest.dynamicTest(descriptionTestNames.get(i), exec);
dynamicTests.add(dTest);
}
ArrayList<String> category = new ArrayList<String>(Arrays.asList("bike"));
ArrayList<String> categoryTestNames = new ArrayList<String>(Arrays.asList("cateogry not correct"));
ArrayList<Class<? extends Exception>> categoryExceptions = new ArrayList<Class<? extends Exception>>(
Arrays.asList(CategoryInvalidException.class));
for (int i = 0; i < category.size(); i++) {
final int j = i;
......@@ -184,14 +195,20 @@ public class ItemUnitTest {
}
Executable exec = () -> assertTrue(item.modify("title", "description", "camera"));
DynamicTest dTest = DynamicTest.dynamicTest("Working test", exec);
dynamicTests.add(dTest);
return dynamicTests;
}
@Test
public void modifyTestTrue() throws CategoryInvalidException, DescriptionInvalidException, TitleInvalidException {
Item item = Item.getInstance();
new Category("camera");
assertTrue(item.modify("title", "description", "camera"));
}
@ParameterizedTest
@ValueSource(ints = { -1, 20 })
public void addPictureOutOfBoundTest(int arrayLength) {
......@@ -214,7 +231,9 @@ public class ItemUnitTest {
int value = 5;
for (int e = 0; e < value; e++) {
list.add(new ItemPicture());
}
Item i = Item.getInstance();
......
......@@ -69,35 +69,72 @@ public class SellerUnitTest {
@TestFactory
public Collection<DynamicTest> createAuctionAcceptanceTest() {
ArrayList<Integer> items = new ArrayList<Integer>(Arrays.asList(0, 1, 1, 1, 1, 1, 1, 1));
ArrayList<String> startTimes = new ArrayList<String>(
Arrays.asList("10/11/2019 11:20:12", "11/11/2019 11:20:12", "111112019", "10/11/2019", "111112019",
"10/11/2019 11:20:12", "10/11/2019 11:20:12", "10/11/2019 11:20:12"));
ArrayList<String> endTimes = new ArrayList<String>(
Arrays.asList("11/11/2019 11:20:12", "10/11/2019 11:20:12", "10112019", "111112019", "11/11/2019",
"11/11/2019 11:20:12", "11/11/2019 11:20:12", "11/11/2019 11:20:12"));
ArrayList<Integer> prices = new ArrayList<Integer>(Arrays.asList(20, 20, 20, 20, 20, -1, 0, 20, 20));
ArrayList<Integer> bidIncrements = new ArrayList<Integer>(Arrays.asList(5, 5, 5, 5, 5, 5, 5, 0, -1));
ArrayList<String> testNames = new ArrayList<String>(Arrays.asList("item not existent", "end before start",
"both dates wrong format", "end wrong format", "start wrong format", "negative price",
"price eqaul to zero", "increment equal to zero", "increment negative"));
ArrayList<Class<? extends Exception>> exceptions = new ArrayList<Class<? extends Exception>>(
Arrays.asList(ItemNonExistentException.class, DateInvalidException.class, DateInvalidException.class,
DateInvalidException.class, DateInvalidException.class, PriceInvalidException.class,
PriceInvalidException.class, PriceInvalidException.class, PriceInvalidException.class));
Collection<DynamicTest> dynamicTests = new ArrayList<DynamicTest>();
Seller s = Seller.getInstance();
Item item = Item.getInstance();
ArrayList<Integer> items = new ArrayList<Integer>(Arrays.asList(0));
Item item = new Item();
item.setId(1);
for (int i = 0; i < items.size(); i++) {
final int j = i;
Executable exec = () -> assertThrows(exceptions.get(j), () -> s.createAuction(Item.getItem(items.get(j)),
startTimes.get(j), endTimes.get(j), prices.get(j), bidIncrements.get(j)));
DynamicTest dTest = DynamicTest.dynamicTest(testNames.get(i), exec);
Executable exec = () -> assertThrows(ItemNonExistentException.class, () -> s
.createAuction(Item.getItem(items.get(j)), "11/12/2019 11:50:11", "12/12/2019 12:50:11", 10d, 5d));
DynamicTest dTest = DynamicTest.dynamicTest("Item not existent", exec);
dynamicTests.add(dTest);
}
ArrayList<String> startTimes = new ArrayList<String>(
Arrays.asList("11/11/2019 11:20:12", "111112019", "10/11/2019", "111112019"));
ArrayList<String> endTimes = new ArrayList<String>(
Arrays.asList("10/11/2019 11:20:12", "10112019", "111112019", "11/11/2019"));
ArrayList<String> testTimeNames = new ArrayList<String>(Arrays.asList("End time before Start time",
"Both dates in a wrong format", "End time in a wrong format", "Start time in a wrong format"));
for (int i = 0; i < startTimes.size(); i++) {
final int j = i;
Executable exec = () -> assertThrows(DateInvalidException.class,
() -> s.createAuction(Item.getItem(1), startTimes.get(j), endTimes.get(j), 10d, 5d));
DynamicTest dTest = DynamicTest.dynamicTest(testTimeNames.get(j), exec);
dynamicTests.add(dTest);
}
ArrayList<Integer> prices = new ArrayList<Integer>(Arrays.asList(-1, 0));
ArrayList<String> testPriceNames = new ArrayList<String>(
Arrays.asList("Negative price", "Price equal to zero"));
for (int i = 0; i < prices.size(); i++) {
final int j = i;
Executable exec = () -> assertThrows(PriceInvalidException.class, () -> s.createAuction(Item.getItem(1),
"11/12/2019 21:50:11", "12/12/2019 21:50:11", prices.get(j), 5d));
DynamicTest dTest = DynamicTest.dynamicTest(testPriceNames.get(j), exec);
dynamicTests.add(dTest);
}
ArrayList<Integer> bidIncrements = new ArrayList<Integer>(Arrays.asList(-1, 0));
ArrayList<String> testIncrementNames = new ArrayList<String>(
Arrays.asList("Negative increment", "Increment equal to zero"));
for (int i = 0; i < bidIncrements.size(); i++) {
final int j = i;
Executable exec = () -> assertThrows(PriceInvalidException.class, () -> s.createAuction(Item.getItem(1),
"11/12/2019 21:50:11", "12/12/2019 21:50:11", 10, bidIncrements.get(j)));
DynamicTest dTest = DynamicTest.dynamicTest(testIncrementNames.get(j), exec);
dynamicTests.add(dTest);
......@@ -110,23 +147,6 @@ public class SellerUnitTest {
@TestFactory
public Collection<DynamicTest> createItemAcceptanceTest() {
ArrayList<String> titles = new ArrayList<String>(
Arrays.asList("", "9999", "t-#\\", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "title",
"title", "title", "title", "title", "title"));
ArrayList<String> descriptions = new ArrayList<String>(Arrays.asList("description", "description",
"description", "description", "", "9999", "too long", "description", "description", "description"));
ArrayList<String> categories = new ArrayList<String>(Arrays.asList("Sport and Outdoor", "Sport and Outdoor",
"Sport and Outdoor", "Sport and Outdoor", "Sport and Outdoor", "Sport and Outdoor", "Sport and Outdoor",
"Sport and Outdoor", "Sport and Outdoor", ""));
ArrayList<String> testNames = new ArrayList<String>(Arrays.asList("title empty", "numeric title",
"symbols in the title", "title too long", "description empty", "numeric description",
"description too long", "no pictures inserted", "too many pictures", "category not existent"));
ArrayList<Class<? extends Exception>> exceptions = new ArrayList<Class<? extends Exception>>(
Arrays.asList(TitleInvalidException.class, TitleInvalidException.class, TitleInvalidException.class,
TitleInvalidException.class, DescriptionInvalidException.class,
DescriptionInvalidException.class, DescriptionInvalidException.class,
ImageInvalidException.class, ImageInvalidException.class, CategoryInvalidException.class));
Collection<DynamicTest> dynamicTests = new ArrayList<DynamicTest>();
Seller s = Seller.getInstance();
......@@ -138,28 +158,74 @@ public class SellerUnitTest {
ip1.setId(1);
ip2.setId(2);
ArrayList<String> titles = new ArrayList<String>(Arrays.asList("", "9999", "t-#\\", "too long"));
ArrayList<String> testTitleNames = new ArrayList<String>(
Arrays.asList("Title empty", "Numeric title", "Symbols in the title", "Title too long"));
for (int i = 0; i < titles.size(); i++) {
String prepareTitle = titles.get(i);
if (i == 3) {
for (int k = 0; k < 60; k++) {
prepareTitle += "a";
}
}
final String title = prepareTitle;
final int j = i;
Executable exec = () -> assertThrows(TitleInvalidException.class,
() -> s.createItem(title, "Beautiful bike", new int[] { 1, 2 }, "Sport and Outdoor"));
DynamicTest dTest = DynamicTest.dynamicTest(testTitleNames.get(j), exec);
dynamicTests.add(dTest);
}
ArrayList<String> descriptions = new ArrayList<String>(Arrays.asList("", "9999", "too long"));
ArrayList<String> testDescriptionNames = new ArrayList<String>(
Arrays.asList("Description empty", "Numeric description", "Description too long"));
for (int i = 0; i < descriptions.size(); i++) {
String prepareDescription = descriptions.get(i);
int[] prepareImages = { 1, 2 };
if (i == 6) {
if (i == 2) {
for (int k = 0; k < 600; k++) {
prepareDescription += "a";
}
}
if (i == 7) {
final String description = prepareDescription;
final int j = i;
prepareImages = new int[0];
Executable exec = () -> assertThrows(DescriptionInvalidException.class,
() -> s.createItem("Red bike", description, new int[] { 1, 2 }, "Sport and Outdoor"));
DynamicTest dTest = DynamicTest.dynamicTest(testDescriptionNames.get(j), exec);
}
dynamicTests.add(dTest);
}
ArrayList<String> testItemPictureNames = new ArrayList<String>(
Arrays.asList("No picture inserted", "Too many pictures"));
for (int i = 0; i < 2; i++) {
int[] prepareImages = { 1, 2 };
if (i == 8) {
if (i == 0) {
prepareImages = new int[0];
} else if (i == 1) {
prepareImages = new int[11];
......@@ -174,13 +240,25 @@ public class SellerUnitTest {
}
final String description = prepareDescription;
final int j = i;
final int[] images = prepareImages;
Executable exec = () -> assertThrows(exceptions.get(j),
() -> s.createItem(titles.get(j), description, images, categories.get(j)));
DynamicTest dTest = DynamicTest.dynamicTest(testNames.get(i), exec);
Executable exec = () -> assertThrows(ImageInvalidException.class,
() -> s.createItem("Red bike", "Beautiful bike", images, "Sport and Outdoor"));
DynamicTest dTest = DynamicTest.dynamicTest(testItemPictureNames.get(i), exec);
dynamicTests.add(dTest);
}
ArrayList<String> categories = new ArrayList<String>(Arrays.asList(""));
for (int i = 0; i < categories.size(); i++) {
final int j = i;
Executable exec = () -> assertThrows(CategoryInvalidException.class,
() -> s.createItem("Red bike", "Beautiful Bike", new int[] { 1, 2 }, categories.get(j)));
DynamicTest dTest = DynamicTest.dynamicTest("Category not existent", exec);
dynamicTests.add(dTest);
......
......@@ -7,7 +7,6 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
......@@ -23,13 +22,13 @@ import org.junit.jupiter.params.provider.ValueSource;
import exceptions.*;
import project.Auction;
import project.AuctionManager;
import project.Category;
import project.Item;
import project.User;
public class UserUnitTest {
@BeforeEach
public void reset() {
......@@ -39,7 +38,7 @@ public class UserUnitTest {
Category.categories = new ArrayList<Category>();
}
@Test
public void loginTest()
throws UsernameEmailEmptyException, PasswordInvalidException, MailInvalidException, LoginInvalidException {
......@@ -53,42 +52,18 @@ public class UserUnitTest {
assertTrue(User.login(username, email, password));
assertTrue(User.login("", email, password));
assertThrows(LoginInvalidException.class, () -> User.login(username, email, "wrong password"));
assertThrows(LoginInvalidException.class, () -> User.login("wrongUsername", email, "wrong password"));
assertThrows(LoginInvalidException.class, () -> User.login("", "wrongemail@gmail.com", "wrong password"));
assertThrows(LoginInvalidException.class, () -> User.login("", email, "wrong password"));
}
@TestFactory
public Collection<DynamicTest> loginAcceptanceTest() {
ArrayList<String> username = new ArrayList<String>(Arrays.asList("", "", "mario", "mario", ""));
ArrayList<String> email = new ArrayList<String>(
Arrays.asList("", "an.gmail.it", "mario@gmail.com", "", "mario@gmail.com"));
ArrayList<String> password = new ArrayList<String>(
Arrays.asList("test", "test", "", "wrong password", "wrong password"));
ArrayList<String> testNames = new ArrayList<String>(Arrays.asList("username and mail empty",
"wrong mail format", "password empty", "login invalid with username", "login invalid with email"));
ArrayList<Class<? extends Exception>> exceptions = new ArrayList<Class<? extends Exception>>(
Arrays.asList(UsernameEmailEmptyException.class, MailInvalidException.class,
PasswordInvalidException.class, LoginInvalidException.class, LoginInvalidException.class));
Collection<DynamicTest> dynamicTests = new ArrayList<DynamicTest>();
for (int i = 0; i < username.size(); i++) {
String us = username.get(i);
String em = email.get(i);
String pw = password.get(i);
final int j = i;
Executable exec = () -> assertThrows(exceptions.get(j), () -> User.login(us, em, pw));
DynamicTest dTest = DynamicTest.dynamicTest(testNames.get(i), exec);
dynamicTests.add(dTest);
}
@Test
public void loginAcceptanceTest() {
return dynamicTests;
assertThrows(UsernameEmailEmptyException.class, () -> User.login("", "", "test"));
assertThrows(MailInvalidException.class, () -> User.login("", "an.gmail.it", "test"));
assertThrows(PasswordInvalidException.class, () -> User.login("", "an.gmail.it", ""));
}
......@@ -118,34 +93,63 @@ public class UserUnitTest {
@TestFactory
public Collection<DynamicTest> searchAuctionAcceptanceTest() {
ArrayList<String> title = new ArrayList<String>(Arrays.asList("", "9999", "t-#\\",
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "title", "title", "title"));
ArrayList<String> category = new ArrayList<String>(
Arrays.asList("camera", "camera", "camera", "camera", "bike", "camera", "camera"));
ArrayList<Integer> price = new ArrayList<Integer>(Arrays.asList(20, 20, 20, 20, 20, 0, -1));
ArrayList<String> testNames = new ArrayList<String>(Arrays.asList("title empty", "numerical title",
"symbols present in the title", "title longer than 30 characters", "cateogry not correct",
"price eqaul to zero", "price is a negative number"));
ArrayList<Class<? extends Exception>> exceptions = new ArrayList<Class<? extends Exception>>(
Arrays.asList(TitleInvalidException.class, TitleInvalidException.class, TitleInvalidException.class,
TitleInvalidException.class, CategoryInvalidException.class, PriceInvalidException.class,
PriceInvalidException.class));
Collection<DynamicTest> dynamicTests = new ArrayList<DynamicTest>();
new Category("camera");
User u = User.getInstance();
new Category("camera");
ArrayList<String> titles = new ArrayList<String>(Arrays.asList("", "9999", "t-#\\", "too long"));
ArrayList<String> testTitleNames = new ArrayList<String>(
Arrays.asList("Title empty", "Numeric title", "Symbols in the title", "Title too long"));
for (int i = 0; i < titles.size(); i++) {
String prepareTitle = titles.get(i);
for (int i = 0; i < title.size(); i++) {
if (i == 3) {
Item item = Item.getInstance();
item.setTitle(title.get(i));
for (int k = 0; k < 60; k++) {
prepareTitle += "a";
}
}
final String title = prepareTitle;
final int j = i;
Executable exec = () -> assertThrows(exceptions.get(j),
() -> u.searchAuction(price.get(j), title.get(j), category.get(j)));
DynamicTest dTest = DynamicTest.dynamicTest(testNames.get(i), exec);
Executable exec = () -> assertThrows(TitleInvalidException.class,
() -> u.searchAuction(5, title, "camera"));
DynamicTest dTest = DynamicTest.dynamicTest(testTitleNames.get(j), exec);
dynamicTests.add(dTest);
}
ArrayList<String> categories = new ArrayList<String>(Arrays.asList(""));
for (int i = 0; i < categories.size(); i++) {
final int j = i;
Executable exec = () -> assertThrows(CategoryInvalidException.class,
() -> u.searchAuction(5, "Red Bike", categories.get(j)));
DynamicTest dTest = DynamicTest.dynamicTest("Category not existent", exec);
dynamicTests.add(dTest);
}
ArrayList<Integer> prices = new ArrayList<Integer>(Arrays.asList(-1, 0));
ArrayList<String> testPriceNames = new ArrayList<String>(
Arrays.asList("Negative price", "Price equal to zero"));
for (int i = 0; i < prices.size(); i++) {
final int j = i;
Executable exec = () -> assertThrows(PriceInvalidException.class,
() -> u.searchAuction(prices.get(j), "Red Bike", "camera"));
DynamicTest dTest = DynamicTest.dynamicTest(testPriceNames.get(j), exec);
dynamicTests.add(dTest);
......@@ -159,14 +163,11 @@ public class UserUnitTest {
public void searchAuctionTest()
throws CategoryInvalidException, TitleInvalidException, PriceInvalidException, ParseException {
String format = "dd/MM/yyyy hh:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
String title = "Red bike", category = "Sport and Outdoor", category2 = "Cars and Motorbikes";
Date start = null, end = null;
start = sdf.parse("22/06/2020 11:20:12");
end = sdf.parse("22/07/2020 11:20:12");
start = AuctionManager.parseDate("22/06/2020 11:20:12");
end = AuctionManager.parseDate("22/07/2020 11:20:12");
double price = 10;
int bid = 5;
......@@ -195,30 +196,47 @@ public class UserUnitTest {
@TestFactory
public Collection<DynamicTest> searchItemAcceptanceTest() {
ArrayList<String> title = new ArrayList<String>(
Arrays.asList("", "9999", "t-#\\", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "title"));
ArrayList<String> category = new ArrayList<String>(
Arrays.asList("camera", "camera", "camera", "camera", "bike"));
ArrayList<String> testNames = new ArrayList<String>(Arrays.asList("title empty", "numerical title",
"symbols present in the title", "title longer than 30 characters", "cateogry not correct"));
ArrayList<Class<? extends Exception>> exceptions = new ArrayList<Class<? extends Exception>>(
Arrays.asList(TitleInvalidException.class, TitleInvalidException.class, TitleInvalidException.class,
TitleInvalidException.class, CategoryInvalidException.class));
Collection<DynamicTest> dynamicTests = new ArrayList<DynamicTest>();
new Category("camera");
User u = User.getInstance();
for (int i = 0; i < title.size(); i++) {
ArrayList<String> titles = new ArrayList<String>(Arrays.asList("", "9999", "t-#\\", "too long"));
ArrayList<String> testTitleNames = new ArrayList<String>(
Arrays.asList("Title empty", "Numeric title", "Symbols in the title", "Title too long"));
for (int i = 0; i < titles.size(); i++) {
String prepareTitle = titles.get(i);
if (i == 3) {
for (int k = 0; k < 60; k++) {
prepareTitle += "a";
}
}
final String title = prepareTitle;
final int j = i;
Executable exec = () -> assertThrows(TitleInvalidException.class, () -> u.searchItem(title, "camera"));
DynamicTest dTest = DynamicTest.dynamicTest(testTitleNames.get(j), exec);
dynamicTests.add(dTest);
}
ArrayList<String> categories = new ArrayList<String>(Arrays.asList("", "bike"));
Item item = Item.getInstance();
item.setTitle(title.get(i));
for (int i = 0; i < categories.size(); i++) {
final int j = i;
Executable exec = () -> assertThrows(exceptions.get(j), () -> u.searchItem(title.get(j), category.get(j)));
DynamicTest dTest = DynamicTest.dynamicTest(testNames.get(i), exec);
Executable exec = () -> assertThrows(CategoryInvalidException.class,
() -> u.searchAuction(5, "Red Bike", categories.get(j)));
DynamicTest dTest = DynamicTest.dynamicTest("Category not existent", exec);
dynamicTests.add(dTest);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment