Skip to content
Snippets Groups Projects
Commit b9f963cc authored by Righi Andrea (Student Com17)'s avatar Righi Andrea (Student Com17)
Browse files

searchItem fitNesse implemented

parent c9a6996b
No related branches found
No related tags found
No related merge requests found
Showing
with 160 additions and 21 deletions
......@@ -2,4 +2,10 @@ package exceptions;
public class CategoryInvalidException extends Exception {
public CategoryInvalidException() {
super("Error: category not correct");
}
}
......@@ -2,4 +2,10 @@ package exceptions;
public class TitleInvalidException extends Exception{
public TitleInvalidException() {
super("Error: title not correct");
}
}
package project;
import java.util.ArrayList;
public class Category {
public static Category getCategory(int category) {
// TODO Auto-generated method stub
public static ArrayList<Category> categories = new ArrayList<Category>();
private static int idCounter;
private String description;
private int categoryId;
public Category(String descr) {
this.description = descr;
this.categoryId = idCounter++;
categories.add(this);
}
public static Category getCategory(String categoryDescription) {
for (Category c : categories) {
if (c.description.equals(categoryDescription)) {
return c;
}
}
return null;
}
......
......@@ -8,6 +8,8 @@ public class Item {
public static ArrayList<Item> items = new ArrayList<Item>();
public ArrayList<ItemPicture> images = new ArrayList<ItemPicture>();
private int id, userOwner;
private Category cat;
private String title;
public Item() {
......@@ -18,15 +20,21 @@ public class Item {
public Item(String title, String description, String images, String category) {
this.cat = Category.getCategory(category);
this.title = title;
id = idCounter++;
items.add(this);
}
public static Item getInstance() {
return null;
Item i = new Item();
return i;
}
public void setImages(ArrayList<ItemPicture> list) {
this.images = list;
}
......@@ -69,9 +77,9 @@ public class Item {
}
return null;
}
public ItemPicture getImage(int img) {
for (ItemPicture i : images) {
......@@ -84,10 +92,8 @@ public class Item {
}
return null;
}
}
public boolean modify(String title, String description, Category category) {
// TODO Auto-generated method stub
......@@ -109,4 +115,26 @@ public class Item {
}
public String getTitle() {
return this.title;
}
public Category getCategory() {
return this.cat;
}
public void setTitle(String title2) {
this.title = title2;
}
public void setCategory(Category c) {
this.cat = c;
}
}
......@@ -2,9 +2,11 @@ package project;
import java.util.ArrayList;
import exceptions.CategoryInvalidException;
import exceptions.LoginInvalidException;
import exceptions.MailInvalidException;
import exceptions.PasswordInvalidException;
import exceptions.TitleInvalidException;
import exceptions.UsernameEmailEmptyException;
public class User {
......@@ -84,7 +86,7 @@ public class User {
}
} else if (!email.equals("usr@mail.com")) {
} else if (!email.equals("usr@mail.com")) {
throw new MailInvalidException();
......@@ -136,9 +138,39 @@ public class User {
return false;
}
public boolean searchItem(String title, Category category) {
// TODO Auto-generated method stub
return false;
public ArrayList<Item> searchItem(String title, String category)
throws CategoryInvalidException, TitleInvalidException {
if (!title.matches("^[a-zA-Z]+$") || title.length() > 30) {
throw new TitleInvalidException();
} else {
Category c = Category.getCategory(category);
if (c == null) {
throw new CategoryInvalidException();
} else {
ArrayList<Item> toReturn = new ArrayList<Item>();
for (Item i : Item.items) {
if (i.getTitle().equals(title) || i.getCategory().equals(c)) {
toReturn.add(i);
}
}
return toReturn;
}
}
}
public boolean searchAuction(String startTime, String endTime, double price, double bidIncrement, String title,
......
package fitNesseFixture;
import project.User;
import java.util.ArrayList;
import exceptions.CategoryInvalidException;
import exceptions.LoginInvalidException;
import exceptions.MailInvalidException;
import exceptions.PasswordInvalidException;
import exceptions.TitleInvalidException;
import exceptions.UsernameEmailEmptyException;
import project.Category;
import project.Item;
public class UserFixture {
private String username, password, email, ssn, title, startTime, endTime;
private int category;
private String username, password, email, ssn, title, startTime, endTime, category;
private User u;
private double price, bidIncrement;
......@@ -20,6 +25,16 @@ public class UserFixture {
}
public UserFixture(String title, String category) {
Category c = new Category(category);
Item i = Item.getInstance();
i.setTitle(title);
i.setCategory(c);
}
public String userLogin() {
try {
......@@ -59,20 +74,42 @@ public class UserFixture {
}
public boolean searchItem() {
public String searchItem() {
u = User.getInstance();
return u.searchItem(title, Category.getCategory(category));
ArrayList<Item> a;
}
try {
a = u.searchItem(title, category);
if (a.size() >= 0) {
return "Search performed!";
}
} catch (CategoryInvalidException e) {
return e.getMessage();
} catch (TitleInvalidException e) {
return e.getMessage();
}
return null;
}
/*
public boolean searchAuction() {
u = User.getInstance();
return u.searchAuction(startTime, endTime, price, bidIncrement, title, Category.getCategory(category));
}
*/
public void setUsername(String username) {
this.username = username;
}
......@@ -105,7 +142,7 @@ public class UserFixture {
this.endTime = endTime;
}
public void setCategory(int category) {
public void setCategory(String category) {
this.category = category;
}
......
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
File added
|clar||16:42:43 gio, nov 21, 2019|
|clar||11:26:40 ven, nov 22, 2019|
|FitNesse.UserGuide.WritingAcceptanceTests.SliM.ExceptionHandling||11:49:07 mar, ott 29, 2019|
|FitNesse.SuiteAcceptanceTests.SuiteSlimTests.TestExceptionIsDisplayed||11:24:26 mar, ott 29, 2019|
......@@ -5,4 +5,6 @@ Suite
!note This page is automatically generated when running tests. It will be overwritten by the next Suite or Test execution.
Tests failed (first failure was at 2019-11-22T11:27:25.895859200):
!see [[clar][.clar]]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment