Skip to content
This repository has been archived by the owner on Feb 3, 2021. It is now read-only.

kay/assert-exit

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
src
 
 
 
 
 
 
 
 
 
 

Project now defunct. Please check out this wonderful project instead: http://stefanbirkner.github.io/system-rules/

assert-exit

JUnit @Rule annotation that provides the ability to assert that System.exit(...) is called with the expected status code.

This is done using JUnit's @Rule annotation. Consider the following:

public class ExpectedExitTest {

  @Rule
  public ExpectedExit expectedExit = ExpectedExit.noAttempt();
  
  @Test
  public void invokesExitAsExpected() {
	  this.expectedExit.expectExit(7);
	  System.exit(7);
  }
}

Your test will pass if:

  • You expected no call to System.exit(...) and none was made
  • You expected a call to System.exit(...) with an expected status code and the same call was made

Your test will fail if:

  • You expected a call to System.exit(...) but none was made
  • You did not expect a call to System.exit(...) but one was made

This is done through manipulating the Java system SecurityManager.

This is designed as a test library and is not intended for general purpose applications.

Maven

To use with Maven currently you must clone these sources, run mvn install to install into your location maven repository and then include the following dependency:

<dependency>
  <groupId>org.neverfear</groupId>
  <artifactId>assert-exit</artifactId>
  <version>1.0-SNAPSHOT</version>
  <scope>test</scope>
</dependency>

About

JUnit @rule annotation that provides the ability to assert that System.exit(...) is called with the expected status code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages