Multiplication implements Scalar<T> { @Override public T value(final Field<T> field) { final FieldMultiplication<T> mult = field.multiplication(); T result = mult.neutral(); for (final Scalar<T> operand : this.operands()) { result = mult.multiply(result, operand.value(field)); } return result; } Multiplication(final Iterable<? extends Scalar<T>> operands);  Multiplication(final Scalar<T> first, final Scalar<T> second); Iterable<Scalar<T>> operands(); @Override T value(final Field<T> field);  }
@Test public void multiplicationDelegatesToFieldMultiplication() { final Scalar<Object> first = new Scalar.Default<>(new Object()); final Scalar<Object> second = new Scalar.Default<>(new Object()); final MkMultiplication<Object> mult = new MkMultiplication<>(new Object()); final SpyField<Object> field = new SpyField<>( new MkField<Object>(new Object(), mult) ); final List<Scalar<Object>> operands = Arrays.asList(first, second); new Multiplication<>(operands).value(field); MatcherAssert.assertThat( field.calls().multiplicationed(), Matchers.is(true) ); MatcherAssert.assertThat( mult.neutraled(), Matchers.is(true) ); MatcherAssert.assertThat( mult.multiplied(), Matchers.is(operands.size()) ); }