package org.apache.tools.ant.taskdefs.optional; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.taskdefs.Execute; import org.apache.tools.ant.taskdefs.ExecuteStreamHandler; import org.apache.tools.ant.types.Commandline; import junit.framework.TestCase; public class RpmTest extends TestCase { public void testShouldThrowExceptionWhenRpmFails() throws Exception { // setup // instantiate the RPM class and override some of the code so we can test // the handling of the return code only. Rpm rpm = new Rpm() { protected Execute getExecute(Commandline toExecute, ExecuteStreamHandler streamhandler) { return new Execute() { public int execute() { return -1; } }; } public void log(String msg) { } }; // execute try { rpm.execute(); fail("We should have thrown a build exception"); } catch (BuildException ex) { assertTrue(ex.getMessage().indexOf("' failed with exit code -1") != -1); } } }