/**
   * This is Bob's original test, re-written only to allow it to execute as a normal junit test
   * within Eclipse.
   */
  @Test
  public void origTestOfRewritingMHLDtoSameBib() throws IOException {
    String mhldRecFileName = testDataParentPath + File.separator + "summaryHld_1-1000.mrc";
    String bibRecFileName = testDataParentPath + File.separator + "u335.mrc";

    InputStream inStr = null;
    ByteArrayOutputStream resultMrcOutStream = new ByteArrayOutputStream();
    String[] mergeMhldArgs = new String[] {"-s", mhldRecFileName, bibRecFileName};

    // call the code for mhldfile summaryHld_1-1000.mrc  and bibfile u335.mrc
    CommandLineUtils.runCommandLineUtil(
        MERGE_MHLD_CLASS_NAME, MAIN_METHOD_NAME, inStr, resultMrcOutStream, mergeMhldArgs);

    RecordTestingUtils.assertMarcRecsEqual(mergedSummaryHoldingsOutput, resultMrcOutStream);

    // Now merge record again to test the deleting of existing summary holdings info
    ByteArrayInputStream mergedMarcBibRecAsInStream =
        new ByteArrayInputStream(resultMrcOutStream.toByteArray());
    resultMrcOutStream.close();
    resultMrcOutStream = new ByteArrayOutputStream();
    //  do the merge by piping the bib record in to the merge class
    CommandLineUtils.runCommandLineUtil(
        MERGE_MHLD_CLASS_NAME,
        MAIN_METHOD_NAME,
        mergedMarcBibRecAsInStream,
        resultMrcOutStream,
        new String[] {"-s", mhldRecFileName});

    RecordTestingUtils.assertMarcRecsEqual(mergedSummaryHoldingsOutput, resultMrcOutStream);
    System.out.println("Test origTestOfRewritingMHLDtoSameBib() successful");
  }
  // FIXME: fails!  needs MarcCombiningReader for mhld or at least a diff version of RawRecordReader
  @Test
  public void testMultMHLDsWithSameID() throws IOException {
    // bib134, multMhlds1
    String bibFilePath = testDataParentPath + File.separator + "mhldMergeBibs134.mrc";
    String mhldFilePath = testDataParentPath + File.separator + "mhldMergeMhlds1Mult.mrc";
    Map<String, Record> mergedRecs =
        MergeSummaryHoldings.mergeMhldsIntoBibRecordsAsMap(bibFilePath, mhldFilePath);

    Record mergedRec = mergedRecs.get("a1");
    assertEquals("Expected three 852", 3, mergedRec.getVariableFields("852").size());
    Set<String> expectedVals = new HashSet<String>();
    expectedVals.add("Location1");
    expectedVals.add("Location2");
    RecordTestingUtils.assertSubfieldHasExpectedValues(mergedRec, "852", 'b', expectedVals);

    expectedVals.clear();
    expectedVals.add("(month)");
    expectedVals.add("(season)");
    RecordTestingUtils.assertSubfieldHasExpectedValues(mergedRec, "853", 'b', expectedVals);

    assertEquals("Expected one 863", 2, mergedRec.getVariableFields("863").size());
    assertEquals("Expected one 866", 1, mergedRec.getVariableFields("866").size());
    // fail("Implement me");
    System.out.println("Test testMultMHLDsWithSameID() successful");
  }
  /** code should output the unchanged bib records if no mhlds match */
  @Test
  public void testNoMatches() throws IOException {
    // bib46, mhld235
    String bibFilePath = testDataParentPath + File.separator + "mhldMergeBibs46.mrc";
    String mhldFilePath = testDataParentPath + File.separator + "mhldMergeMhlds235.mrc";
    Map<String, Record> mergedRecs =
        MergeSummaryHoldings.mergeMhldsIntoBibRecordsAsMap(bibFilePath, mhldFilePath);
    Set<String> mergedRecIds = mergedRecs.keySet();
    assertEquals(2, mergedRecIds.size());

    // result bibs should match the bib input because there was no merge
    String id = "a4";
    RecordTestingUtils.assertEquals(ALL_UNMERGED_BIBS.get(id), mergedRecs.get(id));
    id = "a6";
    RecordTestingUtils.assertEquals(ALL_UNMERGED_BIBS.get(id), mergedRecs.get(id));
    System.out.println("Test testNoMatches() successful");
  }
  /** code should find a match when non-last bib matches last mhld */
  @Test
  public void testNonLastBibMatchesLastMhld() throws IOException {
    // bib46, mhld34
    String bibFilePath = testDataParentPath + File.separator + "mhldMergeBibs46.mrc";
    String mhldFilePath = testDataParentPath + File.separator + "mhldMergeMhlds34.mrc";
    Map<String, Record> mergedRecs =
        MergeSummaryHoldings.mergeMhldsIntoBibRecordsAsMap(bibFilePath, mhldFilePath);

    // there should be 2 results
    Set<String> mergedRecIds = mergedRecs.keySet();
    assertEquals(2, mergedRecIds.size());

    // result bib 6 only should have the mhld fields
    String id = "a4";
    RecordTestingUtils.assertEqualsIgnoreLeader(ALL_MERGED_BIB_RESULTS.get(id), mergedRecs.get(id));
    id = "a6";
    RecordTestingUtils.assertEqualsIgnoreLeader(ALL_UNMERGED_BIBS.get(id), mergedRecs.get(id));
    System.out.println("Test testLastBibMatchesNonLastMhld() successful");
  }
  /** Test if using Naomi's approach with next() works as well as weird way of duplicating code */
  @Test
  public void testMergeToStdOut2() throws IOException {
    String mhldRecFileName = testDataParentPath + File.separator + "summaryHld_1-1000.mrc";
    String bibRecFileName = testDataParentPath + File.separator + "u335.mrc";

    ByteArrayOutputStream sysBAOS = new ByteArrayOutputStream();
    PrintStream sysMsgs = new PrintStream(sysBAOS);

    MergeSummaryHoldings.mergeMhldRecsIntoBibRecsAsStdOut2(
        bibRecFileName, mhldRecFileName, sysMsgs);

    RecordTestingUtils.assertMarcRecsEqual(mergedSummaryHoldingsOutput, sysBAOS);
    System.out.println("Test testMergeToStdOut2() successful");
  }
  /** test methods that return Map of ids to Records and no sysout stuff */
  @Test
  public void testGettingOutputAsMapOfRecords() throws IOException {
    String mhldRecFileName = testDataParentPath + File.separator + "summaryHld_1-1000.mrc";
    String bibRecFileName = testDataParentPath + File.separator + "u335.mrc";

    Map<String, Record> mergedRecs =
        MergeSummaryHoldings.mergeMhldsIntoBibRecordsAsMap(bibRecFileName, mhldRecFileName);

    junit.framework.Assert.assertEquals("results should have 1 record", 1, mergedRecs.size());
    String expId = "u335";
    assertTrue("Record with id " + expId + " should be in results", mergedRecs.containsKey(expId));

    Record resultRec = mergedRecs.get(expId);
    RecordTestingUtils.assertEqualsIgnoreLeader(mergedSummaryHoldingsOutputNoUmlaut, resultRec);
    System.out.println("Test testGettingOutputAsMapOfRecords() successful");
  }