[#12] Remove redundant validation
All checks were successful
DCO / DCO (pull_request) Successful in 34s
All checks were successful
DCO / DCO (pull_request) Successful in 34s
Signed-off-by: Ori Bruk <o.bruk@yadro.com>
This commit is contained in:
parent
23bbe08893
commit
15cf0893c7
2 changed files with 2 additions and 43 deletions
|
@ -1,42 +0,0 @@
|
|||
package info.frostfs.sdk.utils;
|
||||
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
|
||||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validation;
|
||||
import javax.validation.ValidationException;
|
||||
import javax.validation.Validator;
|
||||
import java.util.Set;
|
||||
|
||||
import static java.util.Objects.isNull;
|
||||
|
||||
public class ValidatorUtils {
|
||||
private static final String OBJECT_IS_NULL = "object is null";
|
||||
private static final String ERROR_PROPERTY_TEMPLATE = "property %s with value %s %s";
|
||||
|
||||
private static final Validator validator = Validation.buildDefaultValidatorFactory().getValidator();
|
||||
|
||||
|
||||
public static <T> void validate(T object, Class<?>... classes) {
|
||||
if (isNull(object)) {
|
||||
throw new ValidationException(OBJECT_IS_NULL);
|
||||
}
|
||||
|
||||
Set<ConstraintViolation<T>> violations = validator.validate(object, classes);
|
||||
|
||||
if (CollectionUtils.isEmpty(violations)) {
|
||||
return;
|
||||
}
|
||||
|
||||
String[] errors = (String[]) violations.stream()
|
||||
.map(violation -> String.format(
|
||||
ERROR_PROPERTY_TEMPLATE,
|
||||
violation.getPropertyPath().toString(),
|
||||
violation.getInvalidValue(),
|
||||
violation.getMessage()
|
||||
))
|
||||
.toArray();
|
||||
|
||||
throw new ValidationException(String.join(",", errors));
|
||||
}
|
||||
}
|
|
@ -8,6 +8,7 @@ import info.frostfs.sdk.dto.object.ObjectAttribute;
|
|||
import info.frostfs.sdk.dto.object.ObjectHeader;
|
||||
import info.frostfs.sdk.dto.object.OwnerId;
|
||||
import info.frostfs.sdk.enums.ObjectType;
|
||||
import info.frostfs.sdk.mappers.response.MetaHeaderMapper;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.EnumSource;
|
||||
|
@ -55,7 +56,7 @@ public class ObjectHeaderMapperTest {
|
|||
@Test
|
||||
void toGrpcMessage_null() {
|
||||
//When + Then
|
||||
assertNull(ObjectHeaderMapper.toGrpcMessage(null));
|
||||
assertThrows(IllegalArgumentException.class, () -> ObjectHeaderMapper.toGrpcMessage(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in a new issue