package springapp.service;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import springapp.domain.Product;
import springapp.repository.InMemoryProductDao;
import springapp.repository.ProductDao;
public class SimpleProductManagerTests extends TestCase {
private SimpleProductManager productManager;
private List<Product> products;
private static int PRODUCT_COUNT = 2;
private static Double CHAIR_PRICE = new Double(20.50);
private static String CHAIR_DESCRIPTION = "Chair";
private static String TABLE_DESCRIPTION = "Table";
private static Double TABLE_PRICE = new Double(150.10);
private static int POSITIVE_PRICE_INCREASE = 10;
protected void setUp() throws Exception {
productManager = new SimpleProductManager();
products = new ArrayList<Product>();
// stub up a list of products
Product product = new Product();
product.setDescription("Chair");
product.setPrice(CHAIR_PRICE);
products.add(product);
product = new Product();
product.setDescription("Table");
product.setPrice(TABLE_PRICE);
products.add(product);
ProductDao productDao = new InMemoryProductDao(products);
productManager.setProductDao(productDao);
//productManager.setProducts(products);
}
public void testGetProductsWithNoProducts() {
productManager = new SimpleProductManager();
productManager.setProductDao(new InMemoryProductDao(null));
assertNull(productManager.getProducts());
}
public void testGetProducts() {
List<Product> products = productManager.getProducts();
assertNotNull(products);
assertEquals(PRODUCT_COUNT, productManager.getProducts().size());
Product product = products.get(0);
assertEquals(CHAIR_DESCRIPTION, product.getDescription());
assertEquals(CHAIR_PRICE, product.getPrice());
product = products.get(1);
assertEquals(TABLE_DESCRIPTION, product.getDescription());
assertEquals(TABLE_PRICE, product.getPrice());
}
public void testIncreasePriceWithNullListOfProducts() {
try {
productManager = new SimpleProductManager();
productManager.setProductDao(new InMemoryProductDao(null));
productManager.increasePrice(POSITIVE_PRICE_INCREASE);
} catch (NullPointerException ex) {
fail("Products list is null.");
}
}
public void testIncreasePriceWithEmptyListOfProducts() {
try {
productManager = new SimpleProductManager();
productManager.setProductDao(new InMemoryProductDao(new ArrayList<Product>()));
//productManager.setProducts(new ArrayList<Product>());
productManager.increasePrice(POSITIVE_PRICE_INCREASE);
} catch (Exception ex) {
fail("Products list is empty.");
}
}
public void testIncreasePriceWithPositivePercentage() {
productManager.increasePrice(POSITIVE_PRICE_INCREASE);
double expectedChairPriceWithIncrease = 22.55;
double expectedTablePriceWithIncrease = 165.11;
List<Product> products = productManager.getProducts();
Product product = products.get(0);
assertEquals(expectedChairPriceWithIncrease, product.getPrice());
product = products.get(1);
assertEquals(expectedTablePriceWithIncrease, product.getPrice());
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
springapp.rar (81个子文件)
springapp
.project 573B
bin
springapp
repository
ProductDao.class 291B
InMemoryProductDao.class 929B
JdbcProductDao$ProductMapper.class 2KB
JdbcProductDao.class 3KB
JdbcProductDaoTests.class 2KB
domain
Product.class 1KB
ProductTests.class 1KB
web
InventoryControllerTests.class 2KB
PriceIncreaseFormController.class 2KB
InventoryController.class 2KB
service
PriceIncrease.class 1KB
ProductManager.class 298B
SimpleProductManager.class 2KB
PriceIncreaseValidator.class 3KB
SimpleProductManagerTests.class 4KB
test
test-context.xml 1KB
.settings
.jsdtscope 454B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
db
test.properties 428B
load_data.sql 218B
server.bat 78B
test.lck 16B
create_products.sql 173B
test.log 3KB
war
WEB-INF
springapp-servlet.xml 1KB
web.xml 962B
tld
spring-form.tld 71KB
applicationContext.xml 2KB
jsp
hello.jsp 569B
include.jsp 159B
priceincrease.jsp 887B
lib
commons-dbcp.jar 119KB
commons-logging.jar 59KB
junit-3.8.2.jar 118KB
spring-webmvc.jar 395KB
jstl.jar 20KB
hsqldb.jar 610KB
servlet-api.jar 90KB
spring-test.jar 176KB
commons-pool.jar 61KB
spring.jar 2.81MB
aspectjweaver.jar 1.82MB
standard.jar 384KB
classes
messages.properties 420B
springapp
repository
JdbcProductDao$1.class 235B
ProductDao.class 291B
InMemoryProductDao.class 929B
JdbcProductDao$ProductMapper.class 2KB
JdbcProductDao.class 3KB
JdbcProductDaoTests.class 2KB
domain
Product.class 1KB
ProductTests.class 1KB
web
InventoryControllerTests.class 2KB
PriceIncreaseFormController.class 2KB
InventoryController.class 2KB
service
PriceIncrease.class 1KB
ProductManager.class 298B
SimpleProductManager.class 2KB
PriceIncreaseValidator.class 2KB
SimpleProductManagerTests.class 3KB
jdbc.properties 115B
index.jsp 156B
src
springapp
repository
InMemoryProductDao.java 405B
JdbcProductDao.java 2KB
ProductDao.java 209B
JdbcProductDaoTests.java 1KB
domain
ProductTests.java 639B
Product.java 750B
web
InventoryControllerTests.java 1KB
PriceIncreaseFormController.java 1KB
InventoryController.java 1KB
service
SimpleProductManagerTests.java 3KB
PriceIncreaseValidator.java 2KB
ProductManager.java 262B
SimpleProductManager.java 937B
PriceIncrease.java 447B
.classpath 917B
build.xml 9KB
build.properties 456B
共 81 条
- 1
资源评论
- zhen5992012-10-08真是好文章。值得下 可以研读。
- 覃宇琨2014-06-24值得下载看看
ypdcom
- 粉丝: 1
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- n.cpp
- jdk-8u411-windows-x64下载安装可用
- vgg模型-图像分类算法对水果识别-不含数据集图片-含逐行注释和说明文档.zip
- KMP算法(Knuth-Morris-Pratt算法
- vgg模型-python语言pytorch框架训练识别化妆品分类-不含数据集图片-含逐行注释和说明文档.zip
- KMP算法(Knuth-Morris-Pratt算法
- shufflenet模型-基于人工智能的卷积网络训练识别狗的表情-不含数据集图片-含逐行注释和说明文档.zip
- shufflenet模型-python语言pytorch框架训练识别张嘴闭嘴-不含数据集图片-含逐行注释和说明文档.zip
- resnet模型-基于人工智能的卷积网络训练识别面部表情识别-不含数据集图片-含逐行注释和说明文档
- resnet模型-python语言pytorch框架训练识别香蕉品质-不含数据集图片-含逐行注释和说明文档.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功