Class StartupErrorRule

  • All Implemented Interfaces:
    org.junit.rules.TestRule

    @Deprecated
    public final class StartupErrorRule
    extends java.lang.Object
    implements org.junit.rules.TestRule
    Deprecated.
    in favour of junit 5. But system-rules does not support junit 5 so there is no direct replacement. For system exit capturing you can use https://github.com/tginsberg/junit5-system-exit For system streams capturing there is no alternatives, but in any case it is impossible to do for parallel tests
    Dropwizard exit with code 1 in case of exception during command run. In order to test error situations system exit must be prevented. Rule use system rules to intercept exit and output streams (system.out, system.err).

    Extra dependency 'com.github.stefanbirkner:system-rules:1.16.0' is required.

    In spock tests, 'then' section must contain rule.indicatorExceptionType (or thrown(CheckExitCalled)) as rule can't intercept this exception. 'then' section can be used for assertions after system exit and so no need to register custom callback in the rule.

    Since:
    16.03.2017
    • Method Detail

      • create

        public static StartupErrorRule create()
        Deprecated.
        Use with spock tests or when no assertions required after system exit call.
        Returns:
        rule instance
      • create

        public static StartupErrorRule create​(StartupErrorRule.AfterExitAssertion check)
        Deprecated.
        This is useful for junit tests, because there is no other way to check anything after exit call. In spock, 'then' section is always called and so may be used for assertions.
        Parameters:
        check - assertion callback to execute after exit call
        Returns:
        activated rule
      • checkAfterExit

        public StartupErrorRule checkAfterExit​(StartupErrorRule.AfterExitAssertion check)
        Deprecated.
        In junit it is impossible to use assertion lines after System.exit() call. This method will register a custom check callback to validate state after system exit call. May be called multiple times.

        NOTE: in spock there is no need for it, because 'then' section will be called.

        Parameters:
        check - assertion command
        Returns:
        rule instance for chained calls
        See Also:
        ExpectedSystemExit.checkAssertionAfterwards(org.junit.contrib.java.lang.system.Assertion)
      • apply

        public org.junit.runners.model.Statement apply​(org.junit.runners.model.Statement base,
                                                       org.junit.runner.Description description)
        Deprecated.
        Specified by:
        apply in interface org.junit.rules.TestRule
      • getOutput

        public java.lang.String getOutput()
        Deprecated.
        NOTE: useful only for spock tests.
        Returns:
        content of system.out or empty string
      • getError

        public java.lang.String getError()
        Deprecated.
        Dropwizard exception will be presented here.

        NOTE: useful only for spock tests.

        Returns:
        content of system.err or empty string
      • getIndicatorExceptionType

        public java.lang.Class<? extends java.lang.Exception> getIndicatorExceptionType()
        Deprecated.
        Useful only for spock tests because in junit rule can intercept this exception implicitly.
        Returns:
        type of exception thrown when exit called