Java Code Examples for org.springframework.test.context.TestExecutionListener

The following examples show how to use org.springframework.test.context.TestExecutionListener. These examples are extracted from open source projects. 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
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
/**
 * 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
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
/**
 * 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
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
/**
 * 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
@Bean
public TestExecutionListener listener() {
	return mock(TestExecutionListener.class);
}
 
Example 8
AsyncTestEventComponent(TestExecutionListener listener) {
	this.listener = listener;
}
 
Example 9
/**
 * 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
/**
 * 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
/**
 * 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);
}