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; 018 019import org.springframework.context.ApplicationEvent; 020import org.springframework.test.context.TestContext; 021 022/** 023 * Base class for events published by the {@link EventPublishingTestExecutionListener}. 024 * 025 * @author Frank Scheffler 026 * @author Sam Brannen 027 * @since 5.2 028 */ 029@SuppressWarnings("serial") 030public abstract class TestContextEvent extends ApplicationEvent { 031 032 /** 033 * Create a new {@code TestContextEvent}. 034 * @param source the {@code TestContext} associated with this event 035 * (must not be {@code null}) 036 */ 037 public TestContextEvent(TestContext source) { 038 super(source); 039 } 040 041 /** 042 * Get the {@link TestContext} associated with this event. 043 * @return the {@code TestContext} associated with this event (never {@code null}) 044 * @see #getTestContext() 045 */ 046 @Override 047 public final TestContext getSource() { 048 return (TestContext) super.getSource(); 049 } 050 051 /** 052 * Alias for {@link #getSource()}. 053 * <p>This method may be favored over {@code getSource()} — for example, 054 * to improve readability in SpEL expressions for event processing 055 * {@linkplain org.springframework.context.event.EventListener#condition conditions}. 056 * @return the {@code TestContext} associated with this event (never {@code null}) 057 * @see #getSource() 058 */ 059 public final TestContext getTestContext() { 060 return getSource(); 061 } 062 063}