使用Jmockit 测试 spring + mybatis plus 项目 - CRUD Mapper Mcok 查询样例
Jmockit 1.46+ junit4
package xxx;XXXProgress
import xxx;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.google.common.collect.Lists;
import mockit.Expectations;
import mockit.Injectable;
import mockit.Tested;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.junit4.SpringRunner;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.util.List;
@RunWith(SpringRunner.class)
public class XXXProgressServiceTest {
@Tested
XXXProgressService service=new XXXProgressServiceImpl();
@Injectable
private WindDataMapper windDataMapper;
@Injectable
private XXXProgressMapper XXXProgressMapper;
@Test
public void genProgressDay(@Tested XXXProgress progress) {
List<Timestamp> aTradeDays = Lists.newArrayList(Timestamp.valueOf("1999-2-11 00:00:00"));
List<Timestamp> hkTradeDays=Lists.newArrayList(Timestamp.valueOf("1999-7-11 00:00:00"));
progress.setNote("note");
progress.setXXXDay(20);
progress.setXXXId(BigDecimal.TEN);
progress.setXXXStatus("true");
List<XXXProgress> list=Lists.newArrayList(progress);
new Expectations(service){{
windDataMapper.getXXXCalendars("XXX","20120101","20130101");
result=aTradeDays;
windDataMapper.getXXXCalendars("SSS","20120101","20130101");
result=hkTradeDays;
XXXProgressMapper.selectList((Wrapper<XXXProgress>) any);
result=list;
}};
service.genProgressDay("20120101","20130101");
}
}