
com.github.jinahya.assertj.validation.ConstraintDescriptorAssert Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of assertj-bean-validation Show documentation
Show all versions of assertj-bean-validation Show documentation
An AssertJ extension for Bean-Validation
The newest version!
package com.github.jinahya.assertj.validation;
/*-
* #%L
* assertj-bean-validation
* %%
* Copyright (C) 2021 - 2022 Jinahya, Inc.
* %%
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.Assert;
import org.assertj.core.api.AssertFactory;
import org.assertj.core.api.CollectionAssert;
import org.assertj.core.api.ObjectAssertFactory;
import javax.validation.ConstraintTarget;
import javax.validation.metadata.ConstraintDescriptor;
import java.lang.annotation.Annotation;
import java.util.function.Function;
/**
* An assertion interface for verifying {@link ConstraintDescriptor} values.
*
* @param self type parameter
* @param actual type parameter
* @param type of constraint annotation
*/
public interface ConstraintDescriptorAssert<
SELF extends ConstraintDescriptorAssert,
ACTUAL extends ConstraintDescriptor extends T>,
T extends Annotation>
extends Assert {
// ------------------------------------------------------------------------------------------------------ annotation
> A extractingAnnotation(
final Function super ACTUAL, ? extends T> extractor,
final AssertFactory super T, ? extends A> factory);
default Assert, T> extractingAnnotation() {
return extractingAnnotation(ConstraintDescriptor::getAnnotation, new ObjectAssertFactory<>());
}
// ------------------------------------------------------------------------------------------------------ attributes
// , String, Object>> A extractingAttributes(
// final Function super ACTUAL, ? extends Map> attributesExtractor,
// final AssertFactory super U, ? extends A> assertFactory);
//
// default , String, Object>> A extractingAttributes(
// final AssertFactory super U, ? extends A> assertFactory) {
// return extractingAttributes(ConstraintDescriptor::getAttributes, assertFactory);
// }
// -------------------------------------------------------------------------------------------- composingConstraints
CollectionAssert> extractingComposingConstraints();
@SuppressWarnings({
"unchecked"
})
default SELF doesNotHaveComposingConstraints() {
extractingComposingConstraints().isEmpty();
return (SELF) this;
}
// -------------------------------------------------------------------------------------- constraintValidatorClasses
// ListAssert> extractingConstraintValidatorClasses();
// ---------------------------------------------------------------------------------------------------------- groups
CollectionAssert> extractingGroups();
// ------------------------------------------------------------------------------------------------- messageTemplate
// --------------------------------------------------------------------------------------------------------- payload
// --------------------------------------------------------------------------------------------- validationAppliesTo
SELF hostsConstraintTarget(ConstraintTarget constraintTarget);
default SELF doesNotHostAnyConstraintTarget() {
return hostsConstraintTarget(null);
}
// --------------------------------------------------------------------------------------------------- valueWrapping
// ----------------------------------------------------------------------------------------- reportAsSingleViolation
// ---------------------------------------------------------------------------------------------------------- unwrap
> A extractingAsUnwrapped(
final Class type,
final AssertFactory super U, ? extends A> assertFactory
);
/**
* Verifies that the {@code actual} constraint descriptor value is equal to specified value when
* {@link ConstraintDescriptor#unwrap(Class) unwrapped} as specified type.
*
* @param type the to be unwrapped as.
* @param expectedUnwrappedValue expected unwrapped value.
* @param the type of the unwrapped object.
* @return this assertion object.
* @see ConstraintDescriptor#unwrap(Class)
*/
@SuppressWarnings({
"unchecked"
})
default SELF isEqualToWhenUnwrappedAs(final Class type, final Object expectedUnwrappedValue) {
extractingAsUnwrapped(type, new ObjectAssertFactory<>())
.isEqualTo(expectedUnwrappedValue);
return (SELF) this;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy