title: Java unit tests set Manifest property
body: <p>Is there a way at test time, to inject a property into the Java Manifest (or inject an entire manifest)?</p>
  
  <p>We're reading a value from the manifest (version number) which at test time resolves to null. </p>
  
  <p>So far we've tried putting a hard coded MANIFEST.MF file in our test root, but it didn't work.</p>
  
  <p>This is the code we use to read the manifest:</p>
  
  <pre><code>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();
  }
  </code></pre>
  
  <p>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).</p>
  
  <p>Extra information: Java 7, Running Junit tests in IntelliJ or from Gradle.</p>