import com.alibaba.fastjson.JSON;
import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.when;
public class IApiCommonPlsadmServiceImplTest {
@InjectMocks
IApiCommonPlsadmServiceImpl apiCommonPlsadmServiceImpl;
@Mock
IOperatePreQuotaDao operatePreQuotaDao;
@Mock
IMMDLoanInfoDao immdLoanInfoDao;
@Mock
IRunBatchLoanDao iRunBatchLoanDao;
@Mock
IMvData iMvData;
@Mock
IRxdContractCreateDao iRxdContractCreateDao;
@Before
public void initMocks() {
MockitoAnnotations.initMocks(this);
}
@Test
public void queryQuotaStyleByIdsTest(){
Map<String,String> map = new HashMap<String,String>();
map.put("cardNo","123");
map.put("quotaType","123");
String requestJson = JSON.toJSONString(map);
PreCreditItemEntity entity = new PreCreditItemEntity();
entity.setQuotaStyle("123");
when(operatePreQuotaDao.queryPreCreditItemByMap(any(Map.class))).thenReturn(entity);
apiCommonPlsadmServiceImpl.queryQuotaStyleByIds(requestJson);
when(operatePreQuotaDao.queryPreCreditItemByMap(any(Map.class))).thenReturn(null);
apiCommonPlsadmServiceImpl.queryQuotaStyleByIds(requestJson);
try{
when(operatePreQuotaDao.queryPreCreditItemByMap(any(Map.class))).thenThrow(new RuntimeException("123"));
apiCommonPlsadmServiceImpl.queryQuotaStyleByIds(requestJson);
}catch(Exception e){
e.printStackTrace();
}
}
@Test
public void queryLoanSettleFalgByIds(){
Map<String,String> map = new HashMap<String,String>();
map.put("ids","aaaa");
String requestJson = JSON.toJSONString(map);
CustomerIdsRelationEntity customerIdsRelationEntity = new CustomerIdsRelationEntity();
customerIdsRelationEntity.setCustomerNo("1111");
customerIdsRelationEntity.setIds("aaaa");
when(immdLoanInfoDao.queryCustomerRelationByParams(any(Map.class))).thenReturn(null);
apiCommonPlsadmServiceImpl.queryLoanSettleFalgByIds(requestJson);
when(immdLoanInfoDao.queryCustomerRelationByParams(any(Map.class))).thenReturn(customerIdsRelationEntity);
when(iRunBatchLoanDao.queryRunBatchNewLoanMainCountByIds(any(Map.class))).thenReturn(1);
apiCommonPlsadmServiceImpl.queryLoanSettleFalgByIds(requestJson);
when(immdLoanInfoDao.queryCustomerRelationByParams(any(Map.class))).thenReturn(customerIdsRelationEntity);
when(iRunBatchLoanDao.queryRunBatchNewLoanMainCountByIds(any(Map.class))).thenReturn(0);
when(iMvData.getLoanMainDataByCustomerNo(any(Map.class))).thenReturn(null);
apiCommonPlsadmServiceImpl.queryLoanSettleFalgByIds(requestJson);
when(immdLoanInfoDao.queryCustomerRelationByParams(any(Map.class))).thenReturn(customerIdsRelationEntity);
when(iRunBatchLoanDao.queryRunBatchNewLoanMainCountByIds(any(Map.class))).thenReturn(0);
List<String> list= new ArrayList<>();
list.add("111");
list.add("222");
when(iMvData.getLoanMainDataByCustomerNo(any(Map.class))).thenReturn(list);
when(iRxdContractCreateDao.queryRxdRecorderCountByLoanNo(any(String.class))).thenReturn(1);
apiCommonPlsadmServiceImpl.queryLoanSettleFalgByIds(requestJson);
when(immdLoanInfoDao.queryCustomerRelationByParams(any(Map.class))).thenReturn(customerIdsRelationEntity);
when(iRunBatchLoanDao.queryRunBatchNewLoanMainCountByIds(any(Map.class))).thenReturn(0);
when(iMvData.getLoanMainDataByCustomerNo(any(Map.class))).thenReturn(list);
when(iRxdContractCreateDao.queryRxdRecorderCountByLoanNo(any(String.class))).thenReturn(0);
apiCommonPlsadmServiceImpl.queryLoanSettleFalgByIds(requestJson);
try{
when(immdLoanInfoDao.queryCustomerRelationByParams(any(Map.class))).thenThrow(new RuntimeException("123"));
apiCommonPlsadmServiceImpl.queryLoanSettleFalgByIds(requestJson);
}catch(Exception e){
e.printStackTrace();
}
}
}