![JAR search and dependency download from the Maven repository](/logo.png)
link.jfire.testsupport.runner.JfireContextRunner Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfire-testsupport Show documentation
Show all versions of jfire-testsupport Show documentation
Testsupport is test of jfire system support framework
The newest version!
package link.jfire.testsupport.runner;
import java.io.File;
import java.net.URISyntaxException;
import link.jfire.core.JfireContext;
import link.jfire.core.JfireContextImpl;
import org.junit.runners.BlockJUnit4ClassRunner;
import org.junit.runners.model.InitializationError;
public class JfireContextRunner extends BlockJUnit4ClassRunner
{
private Class> klass;
private JfireContext beanContext;
public JfireContextRunner(Class> klass) throws InitializationError, URISyntaxException
{
super(klass);
this.klass = klass;
ConfigPath path = klass.getAnnotation(ConfigPath.class);
String value = path.value();
beanContext = new JfireContextImpl();
File config = null;
if (value.startsWith("classpath:"))
{
try
{
config = new File(this.getClass().getClassLoader().getResource(value.substring(10)).toURI());
}
catch (Exception e)
{
throw new RuntimeException("文件无法找到", e);
}
}
else if (value.startsWith("file:"))
{
try
{
config = new File(value.substring(5));
}
catch (Exception e)
{
throw new RuntimeException("文件无法找到", e);
}
}
beanContext.readConfig(config);
beanContext.addBean(klass.getName(), false, klass);
beanContext.initContext();
}
protected Object createTest()
{
return beanContext.getBean(klass);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy