EasyMock测试service

实例:

  /**Extension选择器*/
    @Autowired
    private ExtensionSelector extensionSelector;

    /**明细Dao*/
    @Autowired
    private DetailDao detailDao;

    @Override
    public Map<String, Object> qryDetails(
            QueryDetailVo qryDetail) {
        logger.info("----------查询记录明细Serivce开始----------");

        String id = qryDetail.getId();
        String no = qryDetail.getNo();
        String natural_key = qryDetail.getNatural_key();


        Map<String, Object> resultMap = new HashMap<String, Object>();

        //获取策略是否从本地获取记录明细
        IDetailStrategy detailStrategy = extensionSelector
                .getExtensionStrategy(id,StrategyName.DetailStrategy);

        Map<String, Object> info = new HashMap<String, Object>();
        Detail detail = new Detail();
        detail.setNo(no);
        detail.setDetail_status("2");
        List<Detail> detailList = detailDao.getDetailListByNo(detail);
        if(null != detailList && detailList.size() > 0){
             info.put("create_time", detailList.get(0).getCreate_time());
             info.put("id", id);
             info.put("no", no);     
          }

        Map<String, Object> detailStrategyMap = detailStrategy.detailRule(info);
        if(null != detailStrategyMap.get("isDetailFromLocal") && (boolean)detailStrategyMap.get("isDetailFromLocal")){
             List<DetailVo> localDetailList = detailDao.getDetails(id, natural_key);
             resultMap.put(Constants.ROWS, localDetailList);
        }
       logger.info("----------查询记录明细Serivce结束----------");
       return resultMap;
    }

测试;

@Test
    public void qryDetailsTest(){
        IDetailService detailService = new DetailServiceImpl();
        //输入参数
        QueryDetailVo queryFee = new QueryDetailVo();
        String id = "123";
        String no = "85025fd80bcd2a";
        String natural_key = "912639";
        queryFee.setNatural_key(natural_key);
        queryFee.setId(id);
        queryFee.setNo(no);

        Map<String, Object> map = new HashMap<String, Object>();
        map.put("isDetailFromLocal", Boolean.TRUE);

        List<Detail> detailList = new ArrayList<Detail>();
        Detail detail = new Detail();
        detail.setNatural_key(natural_key);
        detail.setNo(no);
        detail.setCreate_time(new Date());
        detail.setDetail_status("2");
        detailList.add(detail);

        List<DetailVo> detaiVoList = new ArrayList<DetailVo>();
        DetailVo detaiVo = new DetailVo();
        detaiVo.setCreate_date(new  Date());
        detaiVo.setItem_name("测试项目");
        detaiVo.setPrice("1800");
        detaiVo.setNumber("10");
        detaiVo.setTotle_amt("18000");
        detaiVoList.add(detaiVo);

        DetailDao detailDao = autowiredMockObject(outpatientFeeService, DetailDao.class);

        IMocksControl mockExtensionSelector = EasyMock.createStrictControl();
        ExtensionSelector extensionSelector = mockExtensionSelector.createMock(ExtensionSelector.class);
        IMocksControl mock = EasyMock.createStrictControl();
        IDetailStrategy detailStrategy = mock.createMock(IDetailStrategy.class);



        //录制
        EasyMock.expect(extensionSelector.getExtensionStrategy(id.intern(),StrategyName.DetailStrategy)).andReturn(paymentStrategy);
        ReflectionTestUtils.setField(detailService, "extensionSelector", extensionSelector, ExtensionSelector.class);
        EasyMock.expect(detailStrategy.detailRule(EasyMock.anyObject(Map.class))).andReturn(map);
        EasyMock.expect(detailDao.getDetailListByNo(EasyMock.anyObject(Detail.class))).andReturn(detailList);
        EasyMock.expect(detailDao.getFeeDetails(id, natural_key)).andReturn(detaiVoList);


        //回放
        EasyMock.replay(extensionSelector);
        EasyMock.replay(detailStrategy);
        EasyMock.replay(detailDao);

        Map<String, Object> returnMap = detailService.qryDetails(queryFee);
        System.out.println(returnMap);

    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值