qa.justtestlah.utils.SpringContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of justtestlah-core Show documentation
Show all versions of justtestlah-core Show documentation
JustTestLah! is a JAVA test framework targeting projects that support multiple platforms, in particular Web, Android and iOS. It follows a BDD approach and allows testing against all platforms using the same feature files. JustTestLah's main aim is to make the configuration and the actual test code as easy as possible.
package qa.justtestlah.utils;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;
/** Helper class to provide access to Spring beans in classes not managed by Spring. */
@Component
public class SpringContext implements ApplicationContextAware {
private static ApplicationContext context;
/**
* Returns the Spring managed bean instance of the given class type if it exists. Returns null
* otherwise.
*
* @param type of the requested bean
* @param clazz the {@link Class} of the requested bean
* @return matching bean from the Spring context
*/
public static T getBean(Class clazz) {
return context.getBean(clazz);
}
@Override
public void setApplicationContext(ApplicationContext context) throws BeansException {
SpringContext.context = context;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy