org.junit.rules.TestRulepublic class Jar extends Object implements org.junit.rules.TestRule
Simply declare a JUnit rule field:
@Rule
public Jar jar = new Jar();
and then use it in your test methods to compile and use code:
Jar.BuildOutput build = jar.from()
.classPathSources("/", "my/package/MySource.java")
.classPathResources("/", "META-INF/my-file-in-jar.txt")
.build();
Jar.Environment env = build.analyze();
TypeElement mySourceClass = env.elements().getElement("my.package.MySource");
...
File jarFile = build.jarFile();
Files.copy(jarFile.toPath(), Paths.get("/"));
...
If you use this class as a JUnit rule, you don't have to handle cleanup of the compilation results. It will be done
automagically.| Modifier and Type | Class | Description |
|---|---|---|
class |
Jar.Builder |
|
class |
Jar.BuildOutput |
Gives access to the compilation results.
|
static interface |
Jar.Environment |
| Constructor | Description |
|---|---|
Jar() |
| Modifier and Type | Method | Description |
|---|---|---|
org.junit.runners.model.Statement |
apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description) |
Applies a jar rule to a test method.
|
void |
cleanUp() |
If you're using the Jar instance as a JUnit rule, you don't have to call this method.
|
Jar.Builder |
from() |
Instantiates a builder using which the contents of a compiled jar file can be composed.
|
public org.junit.runners.model.Statement apply(org.junit.runners.model.Statement base,
org.junit.runner.Description description)
apply in interface org.junit.rules.TestRulepublic Jar.Builder from()
public void cleanUp()
Copyright © 2014-2018 Lukas Krejci. All Rights Reserved.