@Override
public void updateRuleName(Long ruleId, String newRuleName, Long ucId) {
Assert.notNull(ruleId, "规则ID不能为Null");
Assert.notNull(newRuleName, "规则名称不能为Null");
Assert.notNull(ucId, "操作人的UCID不能为Null");
String cleanNewRuleName = StringUtils.trim(newRuleName);
if (StringUtils.isBlank(cleanNewRuleName)) {
throw new IllegalArgumentException("新的规则名称不能为空");
}
// 查询规则对象
Rule rule = queryRuleById(ruleId);
if (null == rule) {
throw new IllegalDataException("没有查到该规则");
}
rule.setRuleId(ruleId);
rule.setRuleName(cleanNewRuleName);
rule.setUpdateUcid(ucId);
rule.setUpdateTime(new Date());
ruleDao.updateSelective(rule);
}
@Test
public void testUpdateRuleName() {
Long ruleId = 1L;
String newRuleName = "newRuleName";
Long ucId = 123L;
List<Rule> rules = new ArrayList<Rule>();
Rule rule = new Rule();
rule.setRuleStatus((byte) DBValueSetting.RULE_STATUS_TAKE_EFFECT);
rules.add(rule);
// 查询规则对象
Map<String, Object> params = new HashMap<String, Object>();
params.put("ruleId", ruleId);
Mockito.when(ruleDao.queryRulesByCondition(params)).thenReturn(rules);
Mockito.doAnswer(new Answer<Object>() {
public Object answer(InvocationOnMock invocation) {
// 断点2:这里随后执行
Rule rule = (Rule) invocation.getArguments()[0];
Assert.assertTrue(rule.getRuleName().equals("newRuleName"));
return null;
}
}).when(ruleDao).updateSelective(Mockito.any(Rule.class));
// 断点1:先执行到这里
ruleService.updateRuleName(ruleId, newRuleName, ucId);
}
public interface Answer<T> {
/**
* @param invocation the invocation on the mock.
*
* @return the value to be returned
*
* @throws Throwable the throwable to be thrown
*/
T answer(InvocationOnMock invocation) throws Throwable;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有