public void MyTest { @Rule public final ExpectedSystemExit exit = ExpectedSystemExit.none(); @Test public void systemExitWithArbitraryStatusCode() { exit.expectSystemExit(); //the code under test, which calls System.exit(...); } @Test public void systemExitWithSelectedStatusCode0() { exit.expectSystemExitWithStatus(0); //the code under test, which calls System.exit(0); } }
public void expectSystemExitWithStatus(int status) { expectSystemExit(); expectedStatus = status; }
public void MyTest { @Rule public final ExpectedSystemExit exit = ExpectedSystemExit.none(); @Test public void noSystemExit() { //passes } @Test public void systemExitWithArbitraryStatusCode() { exit.expectSystemExit(); System.exit(0); } @Test public void systemExitWithSelectedStatusCode0() { exit.expectSystemExitWithStatus(0); System.exit(0); } }
public void expectSystemExitWithStatus(int status) { expectSystemExit(); expectedStatus = status; }
public class MyTest { @Rule public final ExpectedSystemExit exit = ExpectedSystemExit.none(); @Test public void systemExitWithArbitraryStatusCode() { exit.expectSystemExit(); /* the code under test, which calls System.exit(...) * with an arbitrary status */ } @Test public void systemExitWithSelectedStatusCode0() { exit.expectSystemExitWithStatus(0); //the code under test, which calls System.exit(0) } }
public void expectSystemExitWithStatus(int status) { expectSystemExit(); expectedStatus = status; }
public void executeSomeCodeAFTERsystemExit() { System.out.println("This is executed before everything."); exit.expectSystemExit(); exit.checkAssertionAfterwards(new Assertion() { @Override exit.expectSystemExit(); System.exit(0); exit.expectSystemExit();