????????????????????????????????????????£????????????????μ??????????????????????????????????????8000.00???????1520.00????÷???193.00????????????????????????Mock?????????????????????????????????????????????????????????????????????

 

/**
* Copyright ? 2008-2013?? WheatMark?? All Rights Reserved
*/
package com.fitweber.wheat.test;
import static org.easymock.EasyMock.*;
import junit.framework.Assert;
import org.easymock.IMocksControl;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import com.fitweber.wheat.Accountant;
import com.fitweber.wheat.interfaces.IPersonalIncomeTax;
/**
* ??????????
* @author wheatmark hajima11@163.com
* @Blog http://blog.csdn.net/super2007
* @version 1.00.00
* @project wheatMock
* @file com.fitweber.wheat.test.AccountantTest.java
* @bulidDate 2013-9-1
* @modifyDate 2013-9-1
* <pre>
*    ?????
*    ????汾:     ??????  ???????:     ???????:
* </pre>
*/
public class AccountantTest {
private IPersonalIncomeTax personalIncomeTax;
private Accountant accountant;
/**
* @throws java.lang.Exception
*/
@Before
public void setUp() throws Exception {
IMocksControl control = createControl();
personalIncomeTax = control.createMock(IPersonalIncomeTax.class);
accountant = new Accountant();
accountant.setPersonalIncomeTax(personalIncomeTax);
}
/**
* @throws java.lang.Exception
*/
@After
public void tearDown() throws Exception {
System.out.println("----------AccountantTest?е???????????????---------");
}
@Test
public void testCalculateSalary(){
//??????????????????????????????????????????д?????????????
//?????????Mock????????????
//???????????????????????????????????8000.00???????1520.00????÷???193.00.
expect(personalIncomeTax.calculate(8000.00??1520.00)).andReturn(193.00);
//??????????
replay(personalIncomeTax);
//????????????????????????
Assert.assertEquals(8000.00-1520.00-193.00?? accountant.calculateSalary(8000.00));
verify(personalIncomeTax);
}
}

????4. ??в???
???????????????????????AccountantTest.java??Run As —> JUnit Test???????????????檔