If extends GenericInput<I> implements InputOutput<I, O>, Operations<Operation> { @Override public void updateOperations(final Collection<Operation> operations) { if (null == operations || 3 != operations.size()) { throw new IllegalArgumentException("Unable to update operations - exactly 3 operations are required. Received " + (null != operations ? operations.size() : 0) + " operations"); } final Iterator<Operation> itr = operations.iterator(); final Operation transform = extractNextOp(itr); if (null == conditional) { if (null != transform) { conditional = new Conditional(); conditional.setTransform(transform); } } else { conditional.setTransform(transform); } then = extractNextOp(itr); otherwise = extractNextOp(itr); }  @Override TypeReference<O> getOutputTypeReference(); @Override If<I, O> shallowClone(); @Override Map<String, String> getOptions(); @Override void setOptions(final Map<String, String> options); @Override @JsonIgnore Collection<Operation> getOperations(); @Override void updateOperations(final Collection<Operation> operations); Boolean getCondition(); void setCondition(final Boolean condition); Operation getThen(); void setThen(final Operation then); Operation getOtherwise(); void setOtherwise(final Operation otherwise); Conditional getConditional(); void setConditional(final Conditional conditional); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void shouldThrowErrorForTryingToUpdateOperationsWithEmptyList() { final If<Object, Object> ifOp = new If.Builder<>() .condition(true) .build(); final Collection<Operation> opList = Collections.emptyList(); try { ifOp.updateOperations(opList); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertEquals("Unable to update operations - exactly 3 operations are required. Received 0 operations", e.getMessage()); } }
@Test public void shouldThrowErrorForTryingToUpdateOperationsWithTooFewOps() { final GetElements getElements = new GetElements.Builder() .input(new EntitySeed("1")) .build(); final If<Object, Object> ifOp = new If.Builder<>() .condition(false) .build(); final Collection<Operation> opList = Lists.newArrayList(getElements); try { ifOp.updateOperations(opList); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertEquals("Unable to update operations - exactly 3 operations are required. Received 1 operations", e.getMessage()); } }
@Test public void shouldThrowErrorForTryingToUpdateOperationsWithTooManyOps() { final GetElements getElements = new GetElements.Builder() .input(new EntitySeed("2")) .build(); final GetAllElements getAllElements = new GetAllElements(); final Limit limit = new Limit(5); final If<Object, Object> ifOp = new If.Builder<>() .build(); final Collection<Operation> opList = Lists.newArrayList(getElements, getAllElements, limit, limit); try { ifOp.updateOperations(opList); fail("Exception expected"); } catch (final IllegalArgumentException e) { assertEquals("Unable to update operations - exactly 3 operations are required. Received 4 operations", e.getMessage()); } }