@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void createCheckAndProcessTest1() {
PowerMockito.mockStatic(SpringContextUtils.class);
PowerMockito.when(SpringContextUtils.getBean(FieldRepo.class)).thenReturn(fieldRepo());
PowerMockito.when(fieldRepo.checkFieldExist(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1);
FieldBO fieldBO = new FieldBO();
thrown.expect(BusinessException.class);
thrown.expectMessage("字段名称或code重复");
fieldBO.createCheckAndProcess();
}
public FieldRepo fieldRepo() {
return new FieldRepo(){
@Override
public int countList(FieldPageInfoBO param) {
return 0;
}
@Override
public List<FieldBO> queryList(FieldPageInfoBO param) {
return null;
}
@Override
public int checkFieldExist(String code, String name, Long departmentId) {
return 0;
}
...
}
}
@Mock
FieldRepo fieldRepo;
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test
public void createCheckAndProcessTest1() {
PowerMockito.mockStatic(SpringContextUtils.class);
PowerMockito.when(SpringContextUtils.getBean(FieldRepo.class)).thenReturn(fieldRepo);
PowerMockito.when(fieldRepo.checkFieldExist(Mockito.any(), Mockito.any(), Mockito.any())).thenReturn(1);
FieldBO fieldBO = new FieldBO();
thrown.expect(BusinessException.class);
thrown.expectMessage("字段名称或code重复");
fieldBO.createCheckAndProcess();
}
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |