@Test void shouldNotPrintTheStacktraceWhenTheCommandThrowsARuntimeExceptionIfTheDebugFlagIsNotSet() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); RuntimeException exception = new RuntimeException( "" ); AdminCommand command = args -> { throw exception; }; new AdminTool( cannedCommand( "exception", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "exception" ); verify( outsideWorld, never() ).printStacktrace( exception ); }
@Test void shouldProvideFeedbackIfTheCommandReportsAUsageProblem() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); AdminCommand command = args -> { throw new IncorrectUsage( "the-usage-message" ); }; new AdminTool( cannedCommand( "exception", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "exception" ); InOrder inOrder = inOrder( outsideWorld ); inOrder.verify( outsideWorld ).stdErrLine( "the-usage-message" ); verify( outsideWorld ).exit( STATUS_ERROR ); }
@Test void shouldPrintTheStacktraceWhenTheCommandFailsIfTheDebugFlagIsSet() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); CommandFailed exception = new CommandFailed( "" ); AdminCommand command = args -> { throw exception; }; new AdminTool( cannedCommand( "exception", command ), new NullBlockerLocator(), outsideWorld, true ) .execute( null, null, "exception" ); verify( outsideWorld ).printStacktrace( exception ); }
@Test void shouldProvideFeedbackIfTheCommandThrowsARuntimeException() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); AdminCommand command = args -> { throw new RuntimeException( "the-exception-message" ); }; new AdminTool( cannedCommand( "exception", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "exception" ); verify( outsideWorld ).stdErrLine( "unexpected error: the-exception-message" ); verify( outsideWorld ).exit( STATUS_ERROR ); }
@Test void shouldProvideFeedbackIfTheCommandFails() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); AdminCommand command = args -> { throw new CommandFailed( "the-failure-message" ); }; new AdminTool( cannedCommand( "exception", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "exception" ); verify( outsideWorld ).stdErrLine( "command failed: the-failure-message" ); verify( outsideWorld ).exit( STATUS_ERROR ); }
@Test void shouldPrintTheStacktraceWhenTheCommandThrowsARuntimeExceptionIfTheDebugFlagIsSet() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); RuntimeException exception = new RuntimeException( "" ); AdminCommand command = args -> { throw exception; }; new AdminTool( cannedCommand( "exception", command ), new NullBlockerLocator(), outsideWorld, true ) .execute( null, null, "exception" ); verify( outsideWorld ).printStacktrace( exception ); }
@Test void shouldNotPrintTheStacktraceWhenTheCommandFailsIfTheDebugFlagIsNotSet() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); CommandFailed exception = new CommandFailed( "" ); AdminCommand command = args -> { throw exception; }; new AdminTool( cannedCommand( "exception", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "exception" ); verify( outsideWorld, never() ).printStacktrace( exception ); }
@Test void shouldAddTheHelpCommandToThoseProvidedByTheLocator() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); new AdminTool( new NullCommandLocator(), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "help" ); verify( outsideWorld ).stdOutLine( " help" ); }
@Test void helpArgumentPrintsHelp() { AdminCommand command = mock( AdminCommand.class ); OutsideWorld outsideWorld = mock( OutsideWorld.class ); new AdminTool( cannedCommand( "command", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "--help" ); verifyNoMoreInteractions( command ); verify( outsideWorld ).stdErrLine( "unrecognized command: --help" ); verify( outsideWorld ).stdErrLine( "usage: neo4j-admin <command>" ); verify( outsideWorld ).exit( STATUS_ERROR ); }
@Test void shouldExecuteTheCommand() throws CommandFailed, IncorrectUsage { AdminCommand command = mock( AdminCommand.class ); new AdminTool( cannedCommand( "command", command ), new NullBlockerLocator(), new NullOutsideWorld(), false ) .execute( null, null, "command", "the", "other", "args" ); verify( command ).execute( new String[]{"the", "other", "args"} ); }
@Test void helpArgumentPrintsHelpForCommand() { AdminCommand command = mock( AdminCommand.class ); OutsideWorld outsideWorld = mock( OutsideWorld.class ); new AdminTool( cannedCommand( "command", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "command", "--help" ); verifyNoMoreInteractions( command ); verify( outsideWorld ).stdErrLine( "unknown argument: --help" ); verify( outsideWorld ).stdErrLine( "usage: neo4j-admin command " ); verify( outsideWorld ).exit( STATUS_ERROR ); }
@Test void shouldExit0WhenEverythingWorks() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); new AdminTool( new CannedLocator( new NullCommandProvider() ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "null" ); verify( outsideWorld ).exit( STATUS_SUCCESS ); }
@Test void versionArgumentPrintsVersion() { AdminCommand command = mock( AdminCommand.class ); OutsideWorld outsideWorld = mock( OutsideWorld.class ); new AdminTool( cannedCommand( "command", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "--version" ); verifyNoMoreInteractions( command ); verify( outsideWorld ).stdOutLine( "neo4j-admin " + neo4jVersion() ); verify( outsideWorld ).exit( STATUS_SUCCESS ); }
@Test void versionArgumentPrintsVersionEvenWithCommand() { AdminCommand command = mock( AdminCommand.class ); OutsideWorld outsideWorld = mock( OutsideWorld.class ); new AdminTool( cannedCommand( "command", command ), new NullBlockerLocator(), outsideWorld, false ) .execute( null, null, "command", "--version" ); verifyNoMoreInteractions( command ); verify( outsideWorld ).stdOutLine( "neo4j-admin " + neo4jVersion() ); verify( outsideWorld ).exit( STATUS_SUCCESS ); }
@Test void shouldProvideFeedbackWhenNoCommandIsProvided() { OutsideWorld outsideWorld = mock( OutsideWorld.class ); new AdminTool( new NullCommandLocator(), new NullBlockerLocator(), outsideWorld, false ).execute( null, null ); verify( outsideWorld ).stdErrLine( "you must provide a command" ); verify( outsideWorld ).stdErrLine( "usage: neo4j-admin <command>" ); verify( outsideWorld ).exit( STATUS_ERROR ); }