GeneralSchema extends AbstractSchema { @Override public IntSet indicesOf(final EvaluationExpression expression) { final int index = this.mappings.indexOf(expression); if (index == -1) throw new IllegalArgumentException("Field not found."); return IntSets.singleton(index); } GeneralSchema(final EvaluationExpression... mappings);  GeneralSchema(final List<EvaluationExpression> mappings); List<EvaluationExpression> getMappings(); @Override IntSet indicesOf(final EvaluationExpression expression); @Override PactRecord jsonToRecord(final IJsonNode value, PactRecord target, final EvaluationContext context); @Override IJsonNode recordToJson(final PactRecord record, final IJsonNode target);  }
@Test public void shouldProvideTheCorrectIndex() { final IntSet expected = IntSets.singleton(1); final EvaluationExpression exp = new ArithmeticExpression(new ArrayAccess(0), ArithmeticExpression.ArithmeticOperator.MULTIPLICATION, new ArrayAccess(1)); final IntSet result = this.schema.indicesOf(exp); Assert.assertEquals(expected, result); }
@Test(expected = IllegalArgumentException.class) public void shouldFailIfExpressionIsNotFound() { this.schema.indicesOf(new ConstantExpression(IntNode.valueOf(42))); }