001/*
002 * Copyright 2002-2019 the original author or authors.
003 *
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 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
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 */
016
017package org.springframework.test.context.event.annotation;
018
019import java.lang.annotation.Documented;
020import java.lang.annotation.Retention;
021import java.lang.annotation.Target;
022
023import org.springframework.context.event.EventListener;
024import org.springframework.core.annotation.AliasFor;
025import org.springframework.test.context.event.AfterTestMethodEvent;
026
027import static java.lang.annotation.ElementType.ANNOTATION_TYPE;
028import static java.lang.annotation.ElementType.METHOD;
029import static java.lang.annotation.RetentionPolicy.RUNTIME;
030
031/**
032 * {@link EventListener @EventListener} annotation used to consume a
033 * {@link AfterTestMethodEvent} published by the
034 * {@link org.springframework.test.context.event.EventPublishingTestExecutionListener
035 * EventPublishingTestExecutionListener}.
036 *
037 * <p>This annotation may be used on {@code @EventListener}-compliant methods within
038 * a Spring test {@link org.springframework.context.ApplicationContext ApplicationContext}
039 * &mdash; for example, on methods in a
040 * {@link org.springframework.context.annotation.Configuration @Configuration}
041 * class. A method annotated with this annotation will be invoked as part of the
042 * {@link org.springframework.test.context.TestExecutionListener#afterTestMethod}
043 * lifecycle.
044 *
045 * <p>Event processing can optionally be made {@linkplain #value conditional} via
046 * a SpEL expression &mdash; for example,
047 * {@code @AfterTestMethod("event.testContext.testMethod.name matches 'test.*'")}.
048 *
049 * <p>The {@code EventPublishingTestExecutionListener} must be registered in order
050 * for this annotation to have an effect &mdash; for example, via
051 * {@link org.springframework.test.context.TestExecutionListeners @TestExecutionListeners}.
052 *
053 * @author Frank Scheffler
054 * @author Sam Brannen
055 * @since 5.2
056 * @see AfterTestMethodEvent
057 */
058@Retention(RUNTIME)
059@Target({ METHOD, ANNOTATION_TYPE })
060@Documented
061@EventListener(AfterTestMethodEvent.class)
062public @interface AfterTestMethod {
063
064        /**
065         * Alias for {@link EventListener#condition}.
066         */
067        @AliasFor(annotation = EventListener.class, attribute = "condition")
068        String value() default "";
069
070}