Skip to content
Snippets Groups Projects
Commit 0d6dfcf7 authored by cristiano's avatar cristiano
Browse files

Fitnesse update

parent 7551d0eb
No related branches found
No related tags found
No related merge requests found
Showing
with 195 additions and 31 deletions
......@@ -90,5 +90,4 @@
| | *precondition: user logged in and subscribed to the auction* | |
| A null value bid | the method checks if the input for the bid is a positive integer: if it is not, it does not do any operation and show an error message | no operation is done and an error message is showed: "your offer cannot be equal to zero, please try again" |
| A negative value bid | the method checks if the input for the bid is a positive integer: if it is not, it does not do any operation and show an error message | no operation is done and an error message is showed: "your offer cannot be a negative number, please try again" |
| A decimal value bid | the method checks if the input for the bid is a positive integer: if it is not, it does not do any operation and show an error message | no operation is done and an error message is showed: "your offer cannot be a decimal number, please try again" |
| A integer value bid | the method checks if the input for the bid is a positive integer: if it is, it multiply it for the increment set by the user who is selling, it computes the actual price, sets the user which owns the bid as current winnter and returns true | price is computed, the user is set as winner and returns true |
package exceptions;
public class BidBelowZeroException extends Exception {
public BidBelowZeroException() {
super("your offer cannot be below 1");
}
}
package exceptions;
public class BidNullException extends Exception{
public BidNullException() {
super("your offer is invalid");
}
}
......@@ -12,6 +12,7 @@ public class Auction {
private Item item;
private Date start, end;
private double price, bidIncrement;
private User currentLeader;
public Auction(Item item, Date start, Date end, double price, double bidIncrement) {
......@@ -116,4 +117,13 @@ public class Auction {
return price;
}
public void setCurrentLeader(User u) {
this.currentLeader = u;
}
public void incrementPrice(int value) {
this.price += value;
}
}
package project;
import exceptions.BidBelowZeroException;
import exceptions.BidNullException;
public class AuctionManager {
Auction auction;
public AuctionManager() {
this.setAuction(new Auction());
}
public void setAuction(Auction a) {
this.auction = a;
}
public static AuctionManager getInstance() {
// TODO Auto-generated method stub
return null;
return new AuctionManager();
}
public boolean placeBid(int value) {
public boolean placeBid(int user, Integer value) throws BidBelowZeroException, BidNullException {
if (value.equals(null)) {
throw new BidNullException();
} else if (value < 1) {
throw new BidBelowZeroException();
} else if (value > 1) {
User u = User.getUserById(user);
auction.incrementPrice(value);
auction.setCurrentLeader(u);
return true;
}
return false;
// TODO Auto-generated method stub
}
public void computePrice(int value) {
// TODO Auto-generated method stub
}
}
......@@ -2,21 +2,26 @@ package project;
import java.util.ArrayList;
import exceptions.CategoryInvalidException;
import exceptions.DescriptionInvalidException;
import exceptions.ImageInvalidException;
import exceptions.TitleInvalidException;
public class Item {
static int idCounter;
public static ArrayList<Item> items = new ArrayList<Item>();
private ArrayList<ItemPicture> images = new ArrayList<ItemPicture>();
private int id, userOwner;
private Category cat;
private String title, description;
Category cat;
public Item() {
this.cat = new Category();
this.title = "";
this.description = "";
id = idCounter++;
items.add(this);
......@@ -60,9 +65,14 @@ public class Item {
}
public boolean addPicture(Item item, ItemPicture itemPic) {
return false;
// TODO Auto-generated method stub
public boolean addPicture(ArrayList<ItemPicture> picList) throws ImageInvalidException {
if (picList.size() < 1 || picList.size() > 10) {
throw new ImageInvalidException();
} else {
this.setImages(picList);
return true;
}
}
......@@ -101,9 +111,36 @@ public class Item {
}
public boolean modify(String title, String description, Category category) {
// TODO Auto-generated method stub
return false;
public boolean modify(String title, String description, String category)
throws CategoryInvalidException, DescriptionInvalidException, TitleInvalidException {
if (!title.matches("^[a-zA-Z]+$") || title.length() > 30 || title.length() < 1) {
throw new TitleInvalidException();
} else if (description.matches("^\\W+$|\\d+") || description.length() > 500 || description.length() < 1) {
throw new DescriptionInvalidException();
} else {
Category c = Category.getCategory(category);
if (c == null) {
throw new CategoryInvalidException();
} else {
this.setDescription(description);
this.setCategory(Category.getCategory(category));
this.setTitle(title);
return true;
}
}
}
private void setDescription(String d) {
this.description = d;
}
public void setId(int i) {
......@@ -138,9 +175,9 @@ public class Item {
}
public void setCategory(Category c) {
public void setCategory(Category category) {
this.cat = c;
this.cat = category;
}
}
......@@ -32,6 +32,17 @@ public class User {
users.add(this);
}
public User(int id) {
username = "";
email = "";
password = "";
this.id = id;
users.add(this);
}
public User(String usernameInput, String mailInput, String passwordInput) {
......@@ -179,7 +190,8 @@ public class User {
}
public ArrayList<Auction> searchAuction(String startTime, String endTime, double price, String title,
String category) throws CategoryInvalidException, TitleInvalidException, DateInvalidException, PriceInvalidException {
String category)
throws CategoryInvalidException, TitleInvalidException, DateInvalidException, PriceInvalidException {
String format = "dd/MM/yyyy hh:mm:ss";
SimpleDateFormat sdf = new SimpleDateFormat(format);
......@@ -278,4 +290,13 @@ public class User {
this.password = passwordInput;
}
public static User getUserById(int user) {
for (User u : users) {
if (u.getId() == user) {
return u;
}
}
return null;
}
}
package fitNesseFixture;
import exceptions.BidBelowZeroException;
import exceptions.BidNullException;
import project.AuctionManager;
import project.User;
public class AuctionManagerFixture {
private AuctionManager ab;
private int value;
private int usr;
private Integer value = null;
public AuctionManagerFixture(int usr) {
User user = new User(usr);
this.usr = usr;
}
public boolean placeBid() {
public String placeBid() {
ab = AuctionManager.getInstance();
return ab.placeBid(value);
try {
if(ab.placeBid(usr, value)) {
return "Bid placed!";
}
} catch (BidBelowZeroException e) {
return e.getMessage();
} catch (BidNullException e) {
return e.getMessage();
}
return null;
}
public void setValue(int value) {
......
package fitNesseFixture;
import java.util.ArrayList;
import exceptions.CategoryInvalidException;
import exceptions.DescriptionInvalidException;
import exceptions.ImageInvalidException;
import exceptions.TitleInvalidException;
import project.Category;
import project.Item;
import project.ItemPicture;
......@@ -7,19 +13,51 @@ import project.ItemPicture;
public class ItemFixture {
private Item i;
private int item, picture, category;
private String title, description;
public boolean modify() {
i = Item.getInstance();
return i.modify(title, description, Category.getCategory(category));
private int item, picture;
private String title, description, category;
private ArrayList<ItemPicture> images;
public ItemFixture(String cat) {
this.category = cat;
Category c = new Category(cat);
}
public boolean addPicture() {
i = Item.getInstance();
return i.addPicture(Item.getItem(item), ItemPicture.getItemPicture(picture));
public ItemFixture(int[] imagesToCreate) {
for (int i : imagesToCreate) {
ItemPicture ip = new ItemPicture();
ip.setId(i);
}
}
public String modify() {
i = Item.getInstance();
try {
if (i.modify(title, description, category)) {
return "Item modified!";
}
} catch (TitleInvalidException e) {
return e.getMessage();
} catch (DescriptionInvalidException e) {
return e.getMessage();
} catch (CategoryInvalidException e) {
return e.getMessage();
}
return null;
}
public String addPicture() {
i = Item.getInstance();
try {
if(i.addPicture(images)) {
return "Pictures added!";
}
} catch (ImageInvalidException e) {
return e.getMessage();
}
return null;
}
public void setI(Item i) {
this.i = i;
}
......@@ -36,7 +74,7 @@ public class ItemFixture {
this.picture = picture;
}
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment