Is there a way at test time, to inject a property into the Java Manifest (or inject an entire manifest)?
We're reading a value from the manifest (version number) which at test time resolves to null.
So far we've tried putting a hard coded MANIFEST.MF file in our test root, but it didn't work.
This is the code we use to read the manifest:
private Attributes getManifest() {
URLClassLoader cl = (URLClassLoader) getClass().getClassLoader();
Manifest manifest;
try {
URL url = cl.findResource("META-INF/MANIFEST.MF");
manifest = new Manifest(url.openStream());
} catch (IOException e) {
throw Throwables.propagate(e);
}
return manifest.getMainAttributes();
}
As a last resort we'll wrap the functionality that reads the manifest and mock it, but these are integration tests, and are supposed to be black box (ie, we're avoiding mocking).
Extra information: Java 7, Running Junit tests in IntelliJ or from Gradle.