### Question:
SetDefaultAdminCommand implements AdminCommand { @Override public void execute( String[] args ) throws IncorrectUsage, CommandFailed { try { setDefaultAdmin( arguments.parse( args ).get( 0 ) ); } catch ( IncorrectUsage | CommandFailed e ) { throw e; } catch ( Throwable throwable ) { throw new CommandFailed( throwable.getMessage(), new RuntimeException( throwable ) ); } } SetDefaultAdminCommand( Path homeDir, Path configDir, OutsideWorld outsideWorld ); static Arguments arguments(); @Override void execute( String[] args ); static final String ADMIN_INI; static final String COMMAND_NAME; }### Answer:
@Test public void shouldFailForNoArguments() { assertException( () -> setDefaultAdmin.execute( new String[0] ), IncorrectUsage.class, "not enough arguments" ); }
@Test public void shouldFailForTooManyArguments() { String[] arguments = {"", "123", "321"}; assertException( () -> setDefaultAdmin.execute( arguments ), IncorrectUsage.class, "unrecognized arguments: '123 321'" ); }
@Test public void shouldSetDefaultAdmin() throws Throwable { assertFalse( fileSystem.fileExists( adminIniFile ) ); String[] arguments = {"jake"}; setDefaultAdmin.execute( arguments ); assertAdminIniFile( "jake" ); }
@Test public void shouldNotSetDefaultAdminForNonExistentUser() throws Throwable { expect.expect( CommandFailed.class ); expect.expectMessage( "no such user: 'noName'" ); String[] arguments = {"noName"}; setDefaultAdmin.execute( arguments ); }