001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.junit.bct.annotations; 018 019import java.lang.annotation.*; 020 021import org.apache.juneau.commons.lang.*; 022import org.apache.juneau.junit.bct.*; 023import org.junit.jupiter.api.extension.*; 024 025/** 026 * Annotation for configuring BCT settings in JUnit 5 tests. 027 * 028 * <p> 029 * This annotation can be applied to test classes or test methods to automatically configure 030 * BCT settings before tests run and clear them after tests complete. 031 * 032 * <h5 class='section'>Example:</h5> 033 * <p class='bjava'> 034 * <ja>@BctConfig</ja>(sortMaps=TriState.<jsf>TRUE</jsf>) 035 * <jk>class</jk> MyTest { 036 * <ja>@Test</ja> 037 * <ja>@BctConfig</ja>(sortCollections=TriState.<jsf>TRUE</jsf>) 038 * <jk>void</jk> testFoo() { 039 * <jc>// sortMaps and sortCollections are both enabled</jc> 040 * } 041 * } 042 * </p> 043 * 044 * <p> 045 * Method-level annotations override class-level annotations. 046 */ 047@Target({ElementType.TYPE, ElementType.METHOD}) 048@Retention(RetentionPolicy.RUNTIME) 049@ExtendWith(BctConfigExtension.class) 050public @interface BctConfig { 051 052 /** 053 * Enable sorting of maps in BCT assertions. 054 * 055 * @return {@link TriState#TRUE} to enable map sorting, {@link TriState#FALSE} to disable, 056 * or {@link TriState#UNSET} to inherit from class-level annotation. 057 */ 058 TriState sortMaps() default TriState.UNSET; 059 060 /** 061 * Enable sorting of collections in BCT assertions. 062 * 063 * @return {@link TriState#TRUE} to enable collection sorting, {@link TriState#FALSE} to disable, 064 * or {@link TriState#UNSET} to inherit from class-level annotation. 065 */ 066 TriState sortCollections() default TriState.UNSET; 067 068 /** 069 * Custom bean converter class to use for BCT assertions. 070 * 071 * <p> 072 * If specified (not the default {@link BeanConverter}), the class will be instantiated using 073 * its no-arg constructor and set as the converter for the current thread. 074 * 075 * <h5 class='section'>Example:</h5> 076 * <p class='bjava'> 077 * <ja>@BctConfiguration</ja>(beanConverter=MyCustomConverter.<jk>class</jk>) 078 * <jk>class</jk> MyTest { 079 * <ja>@Test</ja> 080 * <jk>void</jk> testFoo() { 081 * <jc>// Uses MyCustomConverter for all assertions</jc> 082 * } 083 * } 084 * </p> 085 * 086 * @return The bean converter class to instantiate and use, or {@link BeanConverter} to use the default. 087 */ 088 Class<? extends BeanConverter> beanConverter() default BeanConverter.class; 089} 090