### Question:
AbstractCommand implements Command { protected void addLoginArgument(MaskedArgumentListBuilder arguments) { if ((Util.fixEmpty(config.getUserName()) != null) && (config.getUserPassword()!= null)) { arguments.addMasked(String.format("-login:%s,%s", config.getUserName(), config.getUserPassword())); } } AbstractCommand(ServerConfigurationProvider configurationProvider); ServerConfigurationProvider getConfig();  }### Answer:
@Test public void assertAddingUserCredentials() { ServerConfigurationProvider config = mock(ServerConfigurationProvider.class); when(config.getUserName()).thenReturn("user"); when(config.getUserPassword()).thenReturn("password"); AbstractCommand command = new AbstractCommandImpl(config); MaskedArgumentListBuilder builder = new MaskedArgumentListBuilder(); command.addLoginArgument(builder); assertEquals("The login argument was incorrect", "-login:user,password", builder.toCommandArray()[0]); assertTrue("The login argument was not masked", builder.toMaskArray()[0]); }
@Test public void assertNotAddingInvalidUserCredentials() { ServerConfigurationProvider config = mock(ServerConfigurationProvider.class); when(config.getUserName()).thenReturn("user"); when(config.getUserPassword()).thenReturn(null); AbstractCommand command = new AbstractCommandImpl(config); MaskedArgumentListBuilder builder = new MaskedArgumentListBuilder(); command.addLoginArgument(builder); assertTrue("The login argument was added", builder.toCommandArray().length == 0); assertTrue("The login argument was added", builder.toMaskArray().length == 0); }
@Test public void assertNotAddingUserCredentialsForEmptyName() { ServerConfigurationProvider config = mock(ServerConfigurationProvider.class); when(config.getUserName()).thenReturn(""); when(config.getUserPassword()).thenReturn(""); AbstractCommand command = new AbstractCommandImpl(config); MaskedArgumentListBuilder builder = new MaskedArgumentListBuilder(); command.addLoginArgument(builder); assertTrue("The login argument was added", builder.toCommandArray().length == 0); assertTrue("The login argument was added", builder.toMaskArray().length == 0); }
@Test public void assertAddingUserCredentialsForEmptyPassword() { ServerConfigurationProvider config = mock(ServerConfigurationProvider.class); when(config.getUserName()).thenReturn("aname"); when(config.getUserPassword()).thenReturn(""); AbstractCommand command = new AbstractCommandImpl(config); MaskedArgumentListBuilder builder = new MaskedArgumentListBuilder(); command.addLoginArgument(builder); assertEquals("The login argument was incorrect", "-login:aname,", builder.toCommandArray()[0]); assertTrue("The login argument was not masked", builder.toMaskArray()[0]); }