public void testHardClippingBeforeMerge() {
final String common = Utils.dupString("A", 10);
final byte[] commonQuals = Utils.dupBytes((byte)30, common.length());
final String adapter = "NNNN";
final GATKSAMRecord read1 = makeOverlappingRead(adapter, 30, common, commonQuals, "", 30, 10);
final GATKSAMRecord read2 = makeOverlappingRead("", 30, common, commonQuals, adapter, 30, 10);
final GATKSAMRecord expectedMerged = makeOverlappingRead("", 30, common, commonQuals, "", 30, 10);
read1.setCigarString("4S" + common.length() + "M");
read1.setProperPairFlag(true);
read1.setReadPairedFlag(true);
read1.setFirstOfPairFlag(true);
read1.setReadNegativeStrandFlag(true);
read1.setMateNegativeStrandFlag(false);
read1.setMateAlignmentStart(read2.getAlignmentStart());
read2.setCigarString(common.length() + "M4S");
read2.setProperPairFlag(true);
read2.setReadPairedFlag(true);
read2.setFirstOfPairFlag(false);
read2.setReadNegativeStrandFlag(false);
read2.setMateNegativeStrandFlag(true);
read2.setMateAlignmentStart(read1.getAlignmentStart());
final int insertSize = common.length() - 1;
read1.setInferredInsertSize(-insertSize);
read2.setInferredInsertSize(insertSize);
final GATKSAMRecord actual = FragmentUtils.mergeOverlappingPairedFragments(read1, read2);
Assert.assertEquals(actual.getCigarString(), expectedMerged.getCigarString());
Assert.assertEquals(actual.getReadBases(), expectedMerged.getReadBases());
Assert.assertEquals(actual.getReadGroup(), expectedMerged.getReadGroup());
Assert.assertEquals(actual.getMappingQuality(), expectedMerged.getMappingQuality());
for ( final EventType type : EventType.values() )
Assert.assertEquals(actual.getBaseQualities(type), expectedMerged.getBaseQualities(type), "Failed base qualities for event type " + type);
}