一个JUNIT4测试


/**
*
*/
package bookstore.testcase;

import static org.junit.Assert.assertEquals;

import org.junit.Before;
import org.junit.Test;

import bookstore.exception.StockLineEmptyException;
import bookstore.exception.StockLineExistedException;
import bookstore.model.Item;
import bookstore.model.Stock;


/**
* @author badboy
*
*/
public class TestStock {
private Stock stock;
Item stockLine1;
Item stockLine2;
Item stockLine3;
Item stockLine4;

@Before
public void before() throws StockLineExistedException{
stock = new Stock();
stockLine1 = new Item("book1","This is book1",99.9f,100);
stockLine2 = new Item("book2","This is book2",88,2);
stockLine3 = new Item("book3","This is book3",99,1);
stockLine4 = new Item("book4","This is book4",10,0);
stock.createStockLine(stockLine1);
stock.createStockLine(stockLine2);
stock.createStockLine(stockLine3);
stock.createStockLine(stockLine4);
}

@Test(expected=StockLineExistedException.class)
/*
* test duplicate case
*/
public void testCreateStockLine() throws StockLineExistedException{
stock.createStockLine(stockLine1);
}



@Test
public void testGetStockLine(){
String bookId = "book1";
Item item = stock.getStockLine(bookId);
assertEquals(bookId,item.getId());
assertEquals("This is book1",item.getDescription());
assertEquals(new Float(99.9f),new Float(item.getPrice()));
assertEquals(100,item.getRemaining());
}

@Test
public void testQuantityOperation() throws StockLineEmptyException{
Item item = stock.getStockLine("book1");
stock.removeQuantity(item,99);
assertEquals(1,stock.getStockLine("book1").getRemaining());
stock.addQuantity(item, 50);
assertEquals(51,stock.getStockLine("book1").getRemaining());
}
@Test(expected = StockLineEmptyException.class)
public void testQuantityException() throws StockLineEmptyException {
Item item = stock.getStockLine("book3");
stock.removeQuantity(item,2);


}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值