### Question:
JoinFunction implements FreeFunction { @Override public Object call(Object... args) { if (args.length != 2) { throw new RuntimeException(String.format("Invalid number of arguments (%s) supplied to a join function", args.length)); } else if (args[0].getClass() != String.class) { throw new RuntimeException(String.format("%s: Is not a valid first argument to join. It should be a string delimiter", args[0].getClass())); } else if (args[1].getClass() != StringArrayInput.class) { throw new RuntimeException(String.format("%s: Is not a valid second argument to join. It should be a list of strings", args[1].getClass())); } else { final String separator = (String)args[0]; final StringArrayInput entries = (StringArrayInput) args[1]; return String.join(separator, entries.getValues()); } }  @Override Object call(Object... args);  }### Answer:
@Test public void testWhenCalledWithADelimiterAndAnArrayOfStringReturnsAStringJoinedByTheDelimiter() { final JoinFunction joinFunction = new JoinFunction(); final String delimiter = ","; final List<String> items = generateTestData(); final Object ret = joinFunction.call(delimiter, new StringArrayInput(items)); assertThat(ret.getClass()).isEqualTo(String.class); assertThat(ret).isEqualTo(String.join(delimiter, items)); }
@Test(expected = RuntimeException.class) public void testWhenCalledWithInvalidTypesThrowsException() { final JoinFunction joinFunction = new JoinFunction(); joinFunction.call(new Object(), new Object()); joinFunction.call(",", new Object()); joinFunction.call(new Object(), generateTestData()); }
@Test(expected = RuntimeException.class) public void testThrowsWhenCalledWithInvalidNumberOfArguments() { final JoinFunction joinFunction = new JoinFunction(); joinFunction.call(","); joinFunction.call(",", generateTestData(), new Object()); }