@Test
  public void shouldThrowExceptionIfCaseIdIsEmpty() {
    String instanceId = "myInstanceId";

    expectedException.expect(RuntimeException.class);
    expectedException.expectMessage(String.format("Empty case id found in form(%s)", instanceId));

    FormValueElement childCaseElement =
        new FormValueElementBuilder()
            .addAttribute("case_id", "")
            .addAttribute("date_modified", "2012-07-21T12:02:59.923+05:30")
            .build();

    FormValueElement childInfoElement = getFVE("case", childCaseElement);

    CommcareForm commcareForm =
        new CommcareFormBuilder().addSubElement("child_info", childInfoElement).build();
    commcareForm.setId(instanceId);

    when(infoParser.getCaseElement(childInfoElement)).thenReturn(childCaseElement);

    childInfoParser.parse(commcareForm);
    verify(infoParser, never()).parse(childCaseElement, true);
    verify(infoParser, never()).parse(childInfoElement, true);
  }
  @Test
  public void
      shouldIgnoreChildrenIfCaseElementNotFoundWhilePopulatingCaseInformationAndNotLogError()
          throws Exception {
    TestAppender.clear();
    String instanceId = "myInstanceId";
    String caseId1 = "3e8998ce-b19f-4fa7-b1a1-721b6951e3cf";
    String caseId2 = "3e8998ce-b19f-4fa7-b1a1-721b6951e3cc";

    String dateModified1 = "2012-07-21T12:02:59.923+05:30";
    String dateModified2 = null;
    String receivedOn = DateTime.now().toString();

    FormValueElement childCaseElement1 =
        new FormValueElementBuilder()
            .addAttribute("case_id", caseId1)
            .addAttribute("date_modified", dateModified1)
            .build();

    FormValueElement childCaseElement2 =
        new FormValueElementBuilder()
            .addAttribute("case_id", caseId2)
            .addAttribute("date_modified", dateModified2)
            .build();

    FormValueElement childInfoElement1 = getFVE("case", childCaseElement1);
    FormValueElement childInfoElement2 = getFVE("case", childCaseElement2);

    CommcareForm commcareForm =
        new CommcareFormBuilder()
            .addSubElement("child_info", childInfoElement1)
            .addSubElement("child_info", childInfoElement2)
            .withReceivedOn(receivedOn)
            .build();

    commcareForm.setId(instanceId);

    when(infoParser.getCaseElement(childInfoElement2)).thenReturn(childCaseElement2);
    when(infoParser.shouldReportMissingCaseElement()).thenReturn(false);

    List<Map<String, String>> childrenMapList = childInfoParser.parse(commcareForm);

    assertEquals(1, childrenMapList.size());

    verify(infoParser, never()).parse(childInfoElement1, true);
    verify(infoParser, never()).parse(childInfoElement1, true);
    verify(infoParser).parse(childCaseElement2, true);
    verify(infoParser).parse(childInfoElement2, true);

    Collections.sort(
        childrenMapList,
        new Comparator<Map<String, String>>() {
          @Override
          public int compare(Map<String, String> o1, Map<String, String> o2) {
            return new CompareToBuilder().append(o1.get("caseId"), o2.get("caseId")).toComparison();
          }
        });

    ReflectionAssert.assertReflectionEquals(
        getExpectedChild(caseId2, dateModified2, receivedOn), childrenMapList.get(0));

    assertNull(TestAppender.findMatching(new IsEqual(Level.ERROR), new IsAnything<String>()));
  }