@Test
  public void testFromAccumulateCompositePatternMissingValuesWithExistingFrom() throws Exception {
    FactPattern pattern1 = new FactPattern("Person");
    SingleFieldConstraint constraint1 = new SingleFieldConstraint("name");
    constraint1.setOperator("==");
    pattern1.addConstraint(constraint1);

    FactPattern pattern2 = new FactPattern("Address");
    SingleFieldConstraint constraint2 = new SingleFieldConstraint("street");
    constraint2.setOperator("!=");
    pattern2.addConstraint(constraint2);

    FromAccumulateCompositeFactPattern fromAccumulateCompositeFactPattern =
        new FromAccumulateCompositeFactPattern();
    fromAccumulateCompositeFactPattern.setSourcePattern(pattern1);
    fromAccumulateCompositeFactPattern.setFactPattern(pattern2);
    fromAccumulateCompositeFactPattern.setInitCode("int i = 0");
    fromAccumulateCompositeFactPattern.setActionCode(" i++;");
    fromAccumulateCompositeFactPattern.setReverseCode("i--;");
    fromAccumulateCompositeFactPattern.setResultCode("return i");

    model.lhs = new IPattern[] {fromAccumulateCompositeFactPattern};

    assertFalse(validator.isValid());
    assertEquals(2, validator.getErrors().size());

    verify(constants, never()).WhenUsingFromTheSourceNeedsToBeSet();
    verify(constants)
        .FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator(
            "Person", "name");
    verify(constants)
        .FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator(
            "Address", "street");
  }
  @Test
  public void testFromAccumulateCompositePattern() throws Exception {
    FactPattern pattern1 = new FactPattern("Person");
    SingleFieldConstraint constraint1 = new SingleFieldConstraint("name");
    constraint1.setOperator("==");
    constraint1.setValue("Toni");
    pattern1.addConstraint(constraint1);

    FactPattern pattern2 = new FactPattern("Address");
    SingleFieldConstraint constraint2 = new SingleFieldConstraint("street");
    constraint2.setOperator("!=");
    constraint2.setValue("some street");
    pattern2.addConstraint(constraint2);

    FromAccumulateCompositeFactPattern fromAccumulateCompositeFactPattern =
        new FromAccumulateCompositeFactPattern();
    fromAccumulateCompositeFactPattern.setSourcePattern(pattern1);
    fromAccumulateCompositeFactPattern.setFactPattern(pattern2);
    ExpressionFormLine expression = new ExpressionFormLine();
    expression.setBinding("person.addresses");
    fromAccumulateCompositeFactPattern.setExpression(expression);

    model.lhs = new IPattern[] {fromAccumulateCompositeFactPattern};

    assertTrue(validator.isValid());
  }
  @Test
  public void testMissingValueInFrom() throws Exception {
    FactPattern boundPattern = new FactPattern("Person");
    boundPattern.setBoundName("person");
    boundPattern.addConstraint(new SingleFieldConstraint("addresses"));

    FactPattern pattern = new FactPattern("Address");

    SingleFieldConstraint constraint = new SingleFieldConstraint("street");
    constraint.setOperator("!=");
    pattern.addConstraint(constraint);

    FromCompositeFactPattern fromCompositeFactPattern = new FromCompositeFactPattern();
    fromCompositeFactPattern.setFactPattern(pattern);
    ExpressionFormLine expression = new ExpressionFormLine();
    expression.setBinding("person.addresses");
    fromCompositeFactPattern.setExpression(expression);

    model.lhs = new IPattern[] {boundPattern, fromCompositeFactPattern};

    assertFalse(validator.isValid());
    assertEquals(1, validator.getErrors().size());
    assertEquals(MISSING_VALUE_WHEN_OPERATOR_IS_SET, validator.getErrors().get(0));

    verify(constants)
        .FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator(
            "Address", "street");
  }
  @Test
  public void testComparingFieldToExpression() throws Exception {
    FactPattern f1 = new FactPattern();
    f1.setBoundName("f1");

    FactPattern f2 = new FactPattern();
    SingleFieldConstraint constraint = new SingleFieldConstraint();
    constraint.setOperator("==");
    constraint
        .getExpressionValue()
        .appendPart(new ExpressionVariable("field", "java.lang.Number", "Number"));
    f2.addConstraint(constraint);

    model.lhs = new IPattern[] {f1, f2};

    assertTrue(validator.isValid());
  }
  @Test
  public void testMissingValueWhenOperatorExists() throws Exception {

    FactPattern pattern = new FactPattern("Person");

    SingleFieldConstraint constraint = new SingleFieldConstraint("age");
    constraint.setOperator("==");
    pattern.addConstraint(constraint);
    model.lhs = new IPattern[] {pattern};

    assertFalse(validator.isValid());
    assertEquals(1, validator.getErrors().size());
    assertEquals(MISSING_VALUE_WHEN_OPERATOR_IS_SET, validator.getErrors().get(0));

    verify(constants)
        .FactType0HasAField1ThatHasAnOperatorSetButNoValuePleaseAddAValueOrRemoveTheOperator(
            "Person", "age");
  }
  @Test
  public void testMissingValueWhenOperatorExistsIsNotNull() throws Exception {

    FactPattern pattern = new FactPattern("Person");

    SingleFieldConstraint constraint = new SingleFieldConstraint("age");
    constraint.setOperator("!= null");
    pattern.addConstraint(constraint);

    CompositeFactPattern not = new CompositeFactPattern();
    not.setType("not");
    not.addFactPattern(pattern);

    model.lhs = new IPattern[] {not};

    assertTrue(validator.isValid());
    assertTrue(validator.getErrors().isEmpty());
  }