### Question:
ScriptExecutionAdderImpl implements ScriptExecutionAdder { @Override public ScriptExecutionAdder withArguments(final Argument... arguments) { if (arguments == null) { throw new IllegalArgumentException("Arguments cannot be null."); } if (arguments.length == 0) { throw new IllegalArgumentException("At least one argument must be supplied."); } for (final Argument argument : arguments) { if (argument == null) { throw new IllegalArgumentException("Null arguments are not allowed: " + Arrays.toString(arguments)); } } this.arguments = Arrays.asList(arguments); return this; } ScriptExecutionAdderImpl(final String scriptName, final CommandQueue queue); @Override void commit(); @Override ScriptExecutionAdder withReplace(final String recordName, final Record record); @Override ScriptExecutionAdder withArguments(final Argument... arguments); @Override ScriptExecutionAdder withAuthentication(final boolean authenticate);  }### Answer:
@Test public void testWithArguments() throws Exception { final ArgumentCaptor<Object> argumentCaptorAll = ArgumentCaptor.forClass(Object.class); final ScriptExecutionCommand command = mock(ScriptExecutionCommand.class); whenNew(ScriptExecutionCommand.class) .withArguments(argumentCaptorAll.capture(), argumentCaptorListArgument.capture(), eq(false)) .thenReturn(command); final Argument arg1 = mock(Argument.class); final Argument arg2 = mock(Argument.class); adder.withArguments(arg1, arg2).commit(); verify(commandQueue).addInCclSessionCommand(command); final String scriptName = (String) argumentCaptorAll.getAllValues().get(0); assertThat(scriptName).isEqualTo(THE_SCRIPT_NAME); final List<Argument> args = argumentCaptorListArgument.getAllValues().get(0); assertThat(args).containsOnly(arg1, arg2); }
@Test public void testWithEmptyArguments() { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { adder.withArguments(); }); assertThat(e.getMessage()).isEqualTo("At least one argument must be supplied."); }
@Test public void testWithNullArgument() { final Argument[] args = new Argument[] { mock(Argument.class), null, mock(Argument.class) }; IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { adder.withArguments(args); }); assertThat(e.getMessage()).isEqualTo("Null arguments are not allowed: " + Arrays.toString(args)); }
@Test public void testWithNullArguments() { IllegalArgumentException e = assertThrows(IllegalArgumentException.class, () -> { adder.withArguments((Argument[]) null); }); assertThat(e.getMessage()).isEqualTo("Arguments cannot be null."); }