Set<List<T>> getCartesianProduct() { return getCartesianProduct(argumentsSets); }
private void testArguments(List<Set<Argument>> argumentsLists, Class<? extends Exception> expectedException) { for (List<Argument> arguments : InvokableArguments.getCartesianProduct(argumentsLists)) { List<Object> argVals = arguments.stream().map(Argument::getValue).collect(Collectors.toList()); try { invokable.invoke(argVals.toArray(new Object[argVals.size()])); if (expectedException != null) { throw new AssertionError( "expected " + expectedException.getName() + " to be thrown for arguments: " + argVals); } } catch (Exception e) { Throwable t = e; if (t instanceof InvocationTargetException) { t = ((InvocationTargetException) t).getTargetException(); } if (expectedException == null) { throw new AssertionError("exception has been thrown for arguments: " + argVals, t); } if (!expectedException.isAssignableFrom(t.getClass())) { throw new AssertionError("expected " + expectedException.getClass() + " to be thrown but got " + t.getClass() + " for arguments: " + argVals, t); } } } }
public void testEquals() { arguments.checkAllArgumentsSet(); AccessibleRunner.run(constructor, () -> { EqualsTester tester = new EqualsTester(); for (List<Argument> args : arguments.getCartesianProduct()) { try { Object[] invokeArgs = args.stream().map(Argument::getValue).toArray(); Object o1 = constructor.newInstance(invokeArgs); Object o2 = constructor.newInstance(invokeArgs); tester.addEqualityGroup(o1, o2); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException | InstantiationException e) { throw new ConstructorInvocationException(e); } } tester.testEquals(); return null; }); }