### Question:
OnlineBackupCommand implements AdminCommand { @Override public void execute( String[] args ) throws IncorrectUsage, CommandFailed { OnlineBackupContext onlineBackupContext = contextBuilder.createContext( args ); protocolWarn( onlineBackupContext ); try ( BackupSupportingClasses backupSupportingClasses = backupSupportingClassesFactory.createSupportingClasses( onlineBackupContext.getConfig() ) ) { checkDestination( onlineBackupContext.getRequiredArguments().getDirectory() ); checkDestination( onlineBackupContext.getRequiredArguments().getReportDir() ); BackupStrategyCoordinator backupStrategyCoordinator = backupStrategyCoordinatorFactory.backupStrategyCoordinator( onlineBackupContext, backupSupportingClasses.getBackupProtocolService(), backupSupportingClasses.getBackupDelegator(), backupSupportingClasses.getPageCache() ); backupStrategyCoordinator.performBackup( onlineBackupContext ); outsideWorld.stdOutLine( "Backup complete." ); } } OnlineBackupCommand( OutsideWorld outsideWorld, OnlineBackupContextFactory contextBuilder,
                         BackupSupportingClassesFactory backupSupportingClassesFactory,
                         BackupStrategyCoordinatorFactory backupStrategyCoordinatorFactory ); @Override void execute( String[] args );  }### Answer:
@Test public void nonExistingBackupDirectoryRaisesException() throws CommandFailed, IncorrectUsage, IOException { fileSystemAbstraction.deleteRecursively( backupDirectory.toFile() ); fileSystemAbstraction.create( backupDirectory.toFile() ).close(); expected.expect( CommandFailed.class ); expected.expectMessage( stringContainsInOrder( asList( "Directory '", "backupDirectory' does not exist." ) ) ); execute(); }
@Test public void nonExistingReportDirectoryRaisesException() throws CommandFailed, IncorrectUsage, IOException { fileSystemAbstraction.deleteRecursively( reportDirectory.toFile() ); fileSystemAbstraction.create( reportDirectory.toFile() ).close(); expected.expect( CommandFailed.class ); expected.expectMessage( stringContainsInOrder( asList( "Directory '", "reportDirectory' does not exist." ) ) ); execute(); }
@Test public void protocolOverrideWarnsUser() throws CommandFailed, IncorrectUsage { List<Object[]> cases = asList( new Object[]{SelectedBackupProtocol.CATCHUP, String.format( "The selected protocol `catchup` means that it is only compatible with causal clustering instances%n" )}, new Object[]{SelectedBackupProtocol.COMMON, String.format( "The selected protocol `common` means that it is only compatible with HA and single instances%n" )} ); for ( Object[] thisCase : cases ) { requiredArguments = new OnlineBackupRequiredArguments( address, backupDirectory, backupName, (SelectedBackupProtocol) thisCase[0], fallbackToFull, doConsistencyCheck, timeout, reportDirectory ); OnlineBackupContext onlineBackupContext = new OnlineBackupContext( requiredArguments, config, consistencyFlags ); subject = newOnlineBackupCommand( outsideWorld, onlineBackupContext, backupSupportingClassesFactory, backupStrategyCoordinatorFactory ); execute(); assertThat( baosOut.toString(), containsString( (String) thisCase[1] ) ); baosOut.reset(); } }