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.api.object; 017 018import static de.cuioss.tools.collect.CollectionLiterals.immutableSet; 019 020import java.io.Serializable; 021import java.util.Set; 022 023import de.cuioss.test.valueobjects.contract.EqualsAndHashcodeContractImpl; 024import de.cuioss.test.valueobjects.contract.SerializableContractImpl; 025import de.cuioss.test.valueobjects.contract.ToStringContractImpl; 026import de.cuioss.test.valueobjects.objects.impl.DefaultInstantiator; 027import lombok.Getter; 028import lombok.RequiredArgsConstructor; 029 030/** 031 * Shorthand identifier / factory for the individual test contracts 032 * 033 * @author Oliver Wolff 034 */ 035@RequiredArgsConstructor 036public enum ObjectTestContracts { 037 038 /** 039 * Tests the existence and correct implementation of the 040 * {@link Object#equals(Object)} and {@link Object#hashCode()} at the level of 041 * the concrete Object. 042 */ 043 EQUALS_AND_HASHCODE(EqualsAndHashcodeContractImpl.class), 044 045 /** 046 * Tests the existence and correct implementation of {@link Object#toString()} 047 * at the level of the concrete Object. 048 */ 049 TO_STRING(ToStringContractImpl.class), 050 051 /** 052 * Tests whether the object under test is {@link Serializable} by first checking 053 * whether the object implements {@link Serializable} and than actually 054 * serializing and deserializing it. 055 */ 056 SERIALIZABLE(SerializableContractImpl.class); 057 058 @Getter 059 private final Class<? extends ObjectTestContract> implementationClass; 060 061 /** 062 * @return a new instance of a {@link ObjectTestContract}. 063 */ 064 public ObjectTestContract newObjectTestInstance() { 065 return new DefaultInstantiator<>(implementationClass).newInstance(); 066 } 067 068 /** Identifies the contract that are specific to Object contracts. */ 069 public static final Set<ObjectTestContracts> OBJECT_CONTRACTS = immutableSet(EQUALS_AND_HASHCODE, SERIALIZABLE, 070 TO_STRING); 071}