All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.beanvalidation.tck.tests.metadata.MetaDataTestUtil Maven / Gradle / Ivy

There is a newer version: 3.0.1
Show newest version
/**
 * Jakarta Bean Validation TCK
 *
 * License: Apache License, Version 2.0
 * See the license.txt file in the root directory or .
 */
package org.hibernate.beanvalidation.tck.tests.metadata;

import static org.assertj.core.api.Assertions.assertThat;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import jakarta.validation.metadata.ConstraintDescriptor;
import jakarta.validation.metadata.ContainerElementTypeDescriptor;

/**
 * @author Guillaume Smet
 */
class MetaDataTestUtil {

	static ContainerElementTypeDescriptor getContainerElementDescriptor(Set containerElementTypeDescriptors,
			Class containerClass, int typeArgumentIndex) {
		for ( ContainerElementTypeDescriptor containerElementTypeDescriptor : containerElementTypeDescriptors ) {
			if ( containerClass.equals( containerElementTypeDescriptor.getContainerClass() ) &&
					typeArgumentIndex == containerElementTypeDescriptor.getTypeArgumentIndex() ) {
				return containerElementTypeDescriptor;
			}
		}

		throw new IllegalStateException(
				String.format( "Container element descriptor not found for container class %1$s and type parameter %2$s", containerClass, typeArgumentIndex ) );
	}

	@SafeVarargs
	static void assertConstraintDescriptors(Set> constraintDescriptors, Class... expectedConstraints) {
		List> actualConstraints = new ArrayList<>();
		for ( ConstraintDescriptor constraintDescriptor : constraintDescriptors ) {
			actualConstraints.add( constraintDescriptor.getAnnotation().annotationType() );
		}
		assertThat( actualConstraints ).containsExactlyInAnyOrder( expectedConstraints );
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy