mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-20 22:15:07 +08:00
简化 dict data 的单元测试,将新增、修改、删除涉及的公用方法,单独测试
This commit is contained in:
@ -28,6 +28,10 @@ public interface BaseMapperX<T> extends BaseMapper<T> {
|
||||
return selectOne(new QueryWrapper<T>().eq(field, value));
|
||||
}
|
||||
|
||||
default Integer selectCount(String field, Object value) {
|
||||
return selectCount(new QueryWrapper<T>().eq(field, value));
|
||||
}
|
||||
|
||||
default List<T> selectList() {
|
||||
return selectList(new QueryWrapper<>());
|
||||
}
|
||||
|
@ -15,13 +15,13 @@ import java.util.List;
|
||||
@Mapper
|
||||
public interface SysDictDataMapper extends BaseMapperX<SysDictDataDO> {
|
||||
|
||||
default SysDictDataDO selectByDictTypeAndLabel(String dictType, String value) {
|
||||
default SysDictDataDO selectByDictTypeAndValue(String dictType, String value) {
|
||||
return selectOne(new QueryWrapper<SysDictDataDO>().eq("dict_type", dictType)
|
||||
.eq("value", value));
|
||||
}
|
||||
|
||||
default int selectCountByDictType(String dictType) {
|
||||
return selectCount(new QueryWrapper<SysDictDataDO>().eq("dict_type", dictType));
|
||||
return selectCount("dict_type", dictType);
|
||||
}
|
||||
|
||||
default PageResult<SysDictDataDO> selectPage(SysDictDataPageReqVO reqVO) {
|
||||
|
@ -15,6 +15,7 @@ import cn.iocoder.dashboard.modules.system.dal.mysql.dict.SysDictDataMapper;
|
||||
import cn.iocoder.dashboard.modules.system.mq.producer.dict.SysDictDataProducer;
|
||||
import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService;
|
||||
import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import com.google.common.collect.ImmutableTable;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
@ -200,8 +201,9 @@ public class SysDictDataServiceImpl implements SysDictDataService {
|
||||
checkDictDataValueUnique(id, dictType, value);
|
||||
}
|
||||
|
||||
private void checkDictDataValueUnique(Long id, String dictType, String label) {
|
||||
SysDictDataDO dictData = dictDataMapper.selectByDictTypeAndLabel(dictType, label);
|
||||
@VisibleForTesting
|
||||
public void checkDictDataValueUnique(Long id, String dictType, String value) {
|
||||
SysDictDataDO dictData = dictDataMapper.selectByDictTypeAndValue(dictType, value);
|
||||
if (dictData == null) {
|
||||
return;
|
||||
}
|
||||
@ -214,7 +216,8 @@ public class SysDictDataServiceImpl implements SysDictDataService {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDictDataExists(Long id) {
|
||||
@VisibleForTesting
|
||||
public void checkDictDataExists(Long id) {
|
||||
if (id == null) {
|
||||
return;
|
||||
}
|
||||
@ -224,7 +227,8 @@ public class SysDictDataServiceImpl implements SysDictDataService {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDictTypeValid(String type) {
|
||||
@VisibleForTesting
|
||||
public void checkDictTypeValid(String type) {
|
||||
SysDictTypeDO dictType = dictTypeService.getDictType(type);
|
||||
if (dictType == null) {
|
||||
throw exception(DICT_TYPE_NOT_EXISTS);
|
||||
|
@ -10,6 +10,7 @@ import cn.iocoder.dashboard.modules.system.dal.dataobject.dict.SysDictTypeDO;
|
||||
import cn.iocoder.dashboard.modules.system.dal.mysql.dict.SysDictTypeMapper;
|
||||
import cn.iocoder.dashboard.modules.system.service.dict.SysDictDataService;
|
||||
import cn.iocoder.dashboard.modules.system.service.dict.SysDictTypeService;
|
||||
import com.google.common.annotations.VisibleForTesting;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
@ -97,7 +98,8 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
|
||||
checkDictTypeUnique(id, type);
|
||||
}
|
||||
|
||||
private void checkDictTypeNameUnique(Long id, String type) {
|
||||
@VisibleForTesting
|
||||
public void checkDictTypeNameUnique(Long id, String type) {
|
||||
SysDictTypeDO dictType = dictTypeMapper.selectByName(type);
|
||||
if (dictType == null) {
|
||||
return;
|
||||
@ -111,7 +113,8 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
|
||||
}
|
||||
}
|
||||
|
||||
private void checkDictTypeUnique(Long id, String type) {
|
||||
@VisibleForTesting
|
||||
public void checkDictTypeUnique(Long id, String type) {
|
||||
SysDictTypeDO dictType = dictTypeMapper.selectByType(type);
|
||||
if (dictType == null) {
|
||||
return;
|
||||
@ -125,7 +128,8 @@ public class SysDictTypeServiceImpl implements SysDictTypeService {
|
||||
}
|
||||
}
|
||||
|
||||
private SysDictTypeDO checkDictTypeExists(Long id) {
|
||||
@VisibleForTesting
|
||||
public SysDictTypeDO checkDictTypeExists(Long id) {
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
|
Reference in New Issue
Block a user