org.springframework.test.context.TestExecutionListener Java Examples

The following examples show how to use org.springframework.test.context.TestExecutionListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AbstractTestContextBootstrapper.java    From spring-analysis-note with MIT License 6 votes vote down vote up
private List<TestExecutionListener> instantiateListeners(Collection<Class<? extends TestExecutionListener>> classes) {
	List<TestExecutionListener> listeners = new ArrayList<>(classes.size());
	for (Class<? extends TestExecutionListener> listenerClass : classes) {
		try {
			listeners.add(BeanUtils.instantiateClass(listenerClass));
		}
		catch (BeanInstantiationException ex) {
			if (ex.getCause() instanceof NoClassDefFoundError) {
				// TestExecutionListener not applicable due to a missing dependency
				if (logger.isDebugEnabled()) {
					logger.debug(String.format(
							"Skipping candidate TestExecutionListener [%s] due to a missing dependency. " +
							"Specify custom listener classes or make the default listener classes " +
							"and their required dependencies available. Offending class: [%s]",
							listenerClass.getName(), ex.getCause().getMessage()));
				}
			}
			else {
				throw ex;
			}
		}
	}
	return listeners;
}
 
Example #2
Source File: AbstractTestContextBootstrapper.java    From spring-analysis-note with MIT License 6 votes vote down vote up
/**
 * Get the default {@link TestExecutionListener} classes for this bootstrapper.
 * <p>This method is invoked by {@link #getTestExecutionListeners()} and
 * delegates to {@link #getDefaultTestExecutionListenerClassNames()} to
 * retrieve the class names.
 * <p>If a particular class cannot be loaded, a {@code DEBUG} message will
 * be logged, but the associated exception will not be rethrown.
 */
@SuppressWarnings("unchecked")
protected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses() {
	Set<Class<? extends TestExecutionListener>> defaultListenerClasses = new LinkedHashSet<>();
	ClassLoader cl = getClass().getClassLoader();
	for (String className : getDefaultTestExecutionListenerClassNames()) {
		try {
			defaultListenerClasses.add((Class<? extends TestExecutionListener>) ClassUtils.forName(className, cl));
		}
		catch (Throwable ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("Could not load default TestExecutionListener class [" + className +
						"]. Specify custom listener classes or make the default listener classes available.", ex);
			}
		}
	}
	return defaultListenerClasses;
}
 
Example #3
Source File: AbstractTestContextBootstrapper.java    From java-technology-stack with MIT License 6 votes vote down vote up
private List<TestExecutionListener> instantiateListeners(Collection<Class<? extends TestExecutionListener>> classes) {
	List<TestExecutionListener> listeners = new ArrayList<>(classes.size());
	for (Class<? extends TestExecutionListener> listenerClass : classes) {
		try {
			listeners.add(BeanUtils.instantiateClass(listenerClass));
		}
		catch (BeanInstantiationException ex) {
			if (ex.getCause() instanceof NoClassDefFoundError) {
				// TestExecutionListener not applicable due to a missing dependency
				if (logger.isDebugEnabled()) {
					logger.debug(String.format(
							"Skipping candidate TestExecutionListener [%s] due to a missing dependency. " +
							"Specify custom listener classes or make the default listener classes " +
							"and their required dependencies available. Offending class: [%s]",
							listenerClass.getName(), ex.getCause().getMessage()));
				}
			}
			else {
				throw ex;
			}
		}
	}
	return listeners;
}
 
Example #4
Source File: AbstractTestContextBootstrapper.java    From java-technology-stack with MIT License 6 votes vote down vote up
/**
 * Get the default {@link TestExecutionListener} classes for this bootstrapper.
 * <p>This method is invoked by {@link #getTestExecutionListeners()} and
 * delegates to {@link #getDefaultTestExecutionListenerClassNames()} to
 * retrieve the class names.
 * <p>If a particular class cannot be loaded, a {@code DEBUG} message will
 * be logged, but the associated exception will not be rethrown.
 */
@SuppressWarnings("unchecked")
protected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses() {
	Set<Class<? extends TestExecutionListener>> defaultListenerClasses = new LinkedHashSet<>();
	ClassLoader cl = getClass().getClassLoader();
	for (String className : getDefaultTestExecutionListenerClassNames()) {
		try {
			defaultListenerClasses.add((Class<? extends TestExecutionListener>) ClassUtils.forName(className, cl));
		}
		catch (Throwable ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("Could not load default TestExecutionListener class [" + className +
						"]. Specify custom listener classes or make the default listener classes available.", ex);
			}
		}
	}
	return defaultListenerClasses;
}
 
Example #5
Source File: AbstractTestContextBootstrapper.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
private List<TestExecutionListener> instantiateListeners(List<Class<? extends TestExecutionListener>> classesList) {
	List<TestExecutionListener> listeners = new ArrayList<TestExecutionListener>(classesList.size());
	for (Class<? extends TestExecutionListener> listenerClass : classesList) {
		NoClassDefFoundError ncdfe = null;
		try {
			listeners.add(BeanUtils.instantiateClass(listenerClass));
		}
		catch (NoClassDefFoundError err) {
			ncdfe = err;
		}
		catch (BeanInstantiationException ex) {
			if (ex.getCause() instanceof NoClassDefFoundError) {
				ncdfe = (NoClassDefFoundError) ex.getCause();
			}
		}
		if (ncdfe != null) {
			if (logger.isInfoEnabled()) {
				logger.info(String.format("Could not instantiate TestExecutionListener [%s]. "
						+ "Specify custom listener classes or make the default listener classes "
						+ "(and their required dependencies) available. Offending class: [%s]",
					listenerClass.getName(), ncdfe.getMessage()));
			}
		}
	}
	return listeners;
}
 
Example #6
Source File: AbstractTestContextBootstrapper.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
/**
 * Get the default {@link TestExecutionListener} classes for this bootstrapper.
 * <p>This method is invoked by {@link #getTestExecutionListeners()} and
 * delegates to {@link #getDefaultTestExecutionListenerClassNames()} to
 * retrieve the class names.
 * <p>If a particular class cannot be loaded, a {@code DEBUG} message will
 * be logged, but the associated exception will not be rethrown.
 */
@SuppressWarnings("unchecked")
protected Set<Class<? extends TestExecutionListener>> getDefaultTestExecutionListenerClasses() {
	Set<Class<? extends TestExecutionListener>> defaultListenerClasses = new LinkedHashSet<Class<? extends TestExecutionListener>>();
	ClassLoader cl = getClass().getClassLoader();
	for (String className : getDefaultTestExecutionListenerClassNames()) {
		try {
			defaultListenerClasses.add((Class<? extends TestExecutionListener>) ClassUtils.forName(className, cl));
		}
		catch (Throwable ex) {
			if (logger.isDebugEnabled()) {
				logger.debug("Could not load default TestExecutionListener class [" + className
						+ "]. Specify custom listener classes or make the default listener classes available.", ex);
			}
		}
	}
	return defaultListenerClasses;
}
 
Example #7
Source File: EventPublishingTestExecutionListenerIntegrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
@Bean
public TestExecutionListener listener() {
	return mock(TestExecutionListener.class);
}
 
Example #8
Source File: EventPublishingTestExecutionListenerIntegrationTests.java    From spring-analysis-note with MIT License 4 votes vote down vote up
AsyncTestEventComponent(TestExecutionListener listener) {
	this.listener = listener;
}
 
Example #9
Source File: AbstractTestContextBootstrapper.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Get the names of the default {@link TestExecutionListener} classes for
 * this bootstrapper.
 * <p>The default implementation looks up all
 * {@code org.springframework.test.context.TestExecutionListener} entries
 * configured in all {@code META-INF/spring.factories} files on the classpath.
 * <p>This method is invoked by {@link #getDefaultTestExecutionListenerClasses()}.
 * @return an <em>unmodifiable</em> list of names of default {@code TestExecutionListener}
 * classes
 * @see SpringFactoriesLoader#loadFactoryNames
 */
protected List<String> getDefaultTestExecutionListenerClassNames() {
	List<String> classNames =
			SpringFactoriesLoader.loadFactoryNames(TestExecutionListener.class, getClass().getClassLoader());
	if (logger.isInfoEnabled()) {
		logger.info(String.format("Loaded default TestExecutionListener class names from location [%s]: %s",
				SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION, classNames));
	}
	return Collections.unmodifiableList(classNames);
}
 
Example #10
Source File: AbstractTestContextBootstrapper.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Get the names of the default {@link TestExecutionListener} classes for
 * this bootstrapper.
 * <p>The default implementation looks up all
 * {@code org.springframework.test.context.TestExecutionListener} entries
 * configured in all {@code META-INF/spring.factories} files on the classpath.
 * <p>This method is invoked by {@link #getDefaultTestExecutionListenerClasses()}.
 * @return an <em>unmodifiable</em> list of names of default {@code TestExecutionListener}
 * classes
 * @see SpringFactoriesLoader#loadFactoryNames
 */
protected List<String> getDefaultTestExecutionListenerClassNames() {
	List<String> classNames =
			SpringFactoriesLoader.loadFactoryNames(TestExecutionListener.class, getClass().getClassLoader());
	if (logger.isInfoEnabled()) {
		logger.info(String.format("Loaded default TestExecutionListener class names from location [%s]: %s",
				SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION, classNames));
	}
	return Collections.unmodifiableList(classNames);
}
 
Example #11
Source File: AbstractTestContextBootstrapper.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Get the names of the default {@link TestExecutionListener} classes for
 * this bootstrapper.
 * <p>The default implementation looks up all
 * {@code org.springframework.test.context.TestExecutionListener} entries
 * configured in all {@code META-INF/spring.factories} files on the classpath.
 * <p>This method is invoked by {@link #getDefaultTestExecutionListenerClasses()}.
 * @return an <em>unmodifiable</em> list of names of default {@code TestExecutionListener}
 * classes
 * @see SpringFactoriesLoader#loadFactoryNames
 */
protected List<String> getDefaultTestExecutionListenerClassNames() {
	final List<String> classNames = SpringFactoriesLoader.loadFactoryNames(TestExecutionListener.class,
		getClass().getClassLoader());

	if (logger.isInfoEnabled()) {
		logger.info(String.format("Loaded default TestExecutionListener class names from location [%s]: %s",
			SpringFactoriesLoader.FACTORIES_RESOURCE_LOCATION, classNames));
	}
	return Collections.unmodifiableList(classNames);
}