Rpm rpm = new MyRpm();
rpm.setProject(new org.apache.tools.ant.Project());
rpm.setFailOnError(true);
// execute
try {
rpm.execute();
fail("should have thrown a build exception");
} catch (BuildException ex) {
assertTrue(ex.getMessage()
.indexOf("' failed with exit code 2") != -1);
}