001/* 002 * Copyright 2023 the original author or authors. 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * https://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package de.cuioss.test.valueobjects.contract; 017 018import java.util.ArrayList; 019import java.util.List; 020import java.util.Optional; 021 022import de.cuioss.test.valueobjects.api.TestContract; 023import de.cuioss.test.valueobjects.property.PropertyMetadata; 024import lombok.experimental.UtilityClass; 025 026/** 027 * Helper class handling the registration of {@link TestContract}s 028 * 029 * @author Oliver Wolff 030 * 031 */ 032@UtilityClass 033public class ContractRegistry { 034 035 /** 036 * Resolves the concrete {@link TestContract}s to be tested. They are derived by 037 * the corresponding annotations 038 * 039 * @param targetBeanClass The actual class underTest 040 * @param unitTestClass The test-class 041 * @param propertyMetadata 042 * @return a list of configured {@link TestContract}s 043 */ 044 public static <T> List<TestContract<T>> resolveTestContracts(Class<T> targetBeanClass, Class<?> unitTestClass, 045 final List<PropertyMetadata> propertyMetadata) { 046 047 final List<TestContract<T>> builder = new ArrayList<>(); 048 Optional<? extends TestContract<T>> contract = BeanPropertyContractImpl 049 .createBeanPropertyTestContract(targetBeanClass, unitTestClass, propertyMetadata); 050 contract.ifPresent(builder::add); 051 contract = BuilderContractImpl.createBuilderTestContract(targetBeanClass, unitTestClass, propertyMetadata); 052 contract.ifPresent(builder::add); 053 builder.addAll(ObjectCreatorContractImpl.createTestContracts(targetBeanClass, unitTestClass, propertyMetadata)); 054 055 contract = CopyConstructorContractImpl.createTestContract(targetBeanClass, unitTestClass, propertyMetadata, 056 builder); 057 contract.ifPresent(builder::add); 058 059 return builder; 060 } 061}