AllIpAddressCheckRequest 类只有一个属性,List
private static final Logger log=LoggerFactory. getLogger(RespUtils. class);
private RespUtils(){
}
public static void setSuccess(BaseResponse response){
response. setSuccess();
、
public static void setError( Exception e, ErrCodeBaseEnum errCode, BaseResponse response){
if (e instanceof BaseBizException){
BaseBizException exception=(BaseBizException)e;
response. setErrCode( exception. getErrCode());
response. setErrMsg( exception. getErrMsg());
} else if (errCode!= null){
response. setErrCode(errCode. getErrCode());
response. setErrMsg(errCode. getErrMsg());
} else{
log. error("errCode为空, 设置默认错误");
response. setErrCode(HadesErrCodeEnum. BIZ_UNKNOWN_ERROR. getErrCode());
response. setErrMsg(HadesErrCodeEnum. BIZ_UNKNOWN_ERROR. getErrMsg());
}
)
public static void setError(ErrCodeBaseEnum errCode, BaseResponse response){setError(( Exception) null, errCode, response);
}
public static Object newReturn( Class returnType, String errCode, String errMsg){ if (returnType == null){
return null;
} else{
Object ret= null;
try{ret=returnType. newInstance();
if ( ret instanceof BaseResponse){
BaseResponse response=(BaseResponse) ret;
response. setErrCode(errCode);
response. setErrMsg(errMsg);
ret= response;
}
} catch (IllegalAccessException| InstantiationException var5){
log.info ((String)null,var5);
}
return ret;
}
)
public static Object newReturn( Class returnType, BaseBizExceptione){
return newReturn(returnType, e. getErrCode(), e. getErrMsg());
}
public static Object newReturn( Class<?> returnType, ErrCodeBaseEnum
errCodeBaseEnum){
return newReturn(returnType, errCodeBaseEnum. getErrCode(),
errCodeBaseEnum. getErrMsg());
}
)
TitanException定义如下public class Titan Exception extends RuntimeException{
public TitanException(){
super();}
public TitanException(String message){
super(message);}
public TitanException(String message,Throwable cause){
super(message,cause);}
public TitanException(Throwable cause){
super(cause);}
}IpCheckService 接口及其方法 asyncIpCheck 的定义如下public class IpCheckService{
@Async(value="asyncIpCheckExecutor")
public void asyncIpCheck(String ipAdress,Map<String,Boolean> map,CountDownLatch latch){
try{
InetAdress adress=InetAdress.getByName(ipAdress);
map.put(ipAdress,true);
if(address.isReachable(3000)){
map.put(ipAdress,false);}
}catch(Exception e){
log.error("IP校验异常",e);
throw new TitanException("IP校验异常",e);
}finally{
latch.countDown();
}
}
}Maps类就采用常用情况即可。请你重新进行单元测试