billserviceimpltest.java

来自「自己做的关于spring框架的使用」· Java 代码 · 共 58 行

JAVA
58
字号
/**
 * 
 */
package test.myspring.v3.ts;

import org.springframework.dao.DataIntegrityViolationException;

import myspring.v3.ts.BillServiceImpl;
import junit.framework.TestCase;

/**
 * @author maboli
 * @date Oct 24, 2008
 *
 */
public class BillServiceImplTest extends TestCase {

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	/**
	 * Test method for {@link myspring.v3.ts.BillServiceImpl#buy(int, int, float)}.
	 */
	public void testBuy() {
		BillServiceImpl service = new BillServiceImpl();
		
		service.setAccountDao(new AccountDaoMock());
		service.setBillDao(new BillDaoMock());
		
		assertTrue(service.buy(1, 1, new Float(20.5)));
		assertFalse(service.buy(23, 343, new Float(20.5)));
		assertFalse(service.buy(0, 0, new Float(20.5)));
		
		assertFalse(service.buy(1, 1, new Float(-20.5)));
		
		try {
			service.buy(0, 1, new Float(20.5));
			fail("未抛出预料的异常!");
		} catch (DataIntegrityViolationException e){
			assertFalse(false);
		}
		
		
	}

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?