Source:
public void testCoordinateByMateMethodWorksProperly () throws IOException { final HitsForInsert hitsForInsert = new HitsForInsert(); final SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(SAMFileHeader.SortOrder.queryname); { final SAMRecord first = new SAMRecord(header); final SAMRecord second = new SAMRecord(header); first.setReferenceName("chrm1"); first.setAlignmentStart(20); first.setMateReferenceName("chrm2"); first.setMateAlignmentStart(1); second.setReferenceName("chrm2"); second.setAlignmentStart(1); second.setMateReferenceName("chrm1"); second.setMateAlignmentStart(20); hitsForInsert.addFirstOfPairOrFragment(first); hitsForInsert.addSecondOfPair(second); } { final SAMRecord first = new SAMRecord(header); first.setReferenceName("chrm1"); first.setAlignmentStart(8); first.setMateReferenceName(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME); first.setAlignmentStart(SAMRecord.NO_ALIGNMENT_START); hitsForInsert.addFirstOfPairOrFragment(first); } { final SAMRecord second = new SAMRecord(header); second.setReferenceName("chrm2"); second.setAlignmentStart(15); second.setMateReferenceName(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME); second.setAlignmentStart(SAMRecord.NO_ALIGNMENT_START); hitsForInsert.addFirstOfPairOrFragment(second); } for (int i = 0; i < 3; i++) { final SAMRecord first = hitsForInsert.getFirstOfPair(i); final SAMRecord second = hitsForInsert.getSecondOfPair(i); if (first != null && second != null) { Assert.assertEquals(first.getMateAlignmentStart(), second.getAlignmentStart()); Assert.assertEquals(second.getMateAlignmentStart(), first.getAlignmentStart()); } else if (first != null) { Assert.assertEquals(first.getMateAlignmentStart(), SAMRecord.NO_ALIGNMENT_START); } else { Assert.assertEquals(second.getMateAlignmentStart(), SAMRecord.NO_ALIGNMENT_START); } } }

Target:
public void testCoordinateByMateMethodWorksProperly () { final HitsForInsert hitsForInsert = new HitsForInsert(); final SAMFileHeader header = new SAMFileHeader(); header.setSortOrder(SAMFileHeader.SortOrder.queryname); { final SAMRecord first = new SAMRecord(header); final SAMRecord second = new SAMRecord(header); first.setReferenceName("chrm1"); first.setAlignmentStart(20); first.setMateReferenceName("chrm2"); first.setMateAlignmentStart(1); second.setReferenceName("chrm2"); second.setAlignmentStart(1); second.setMateReferenceName("chrm1"); second.setMateAlignmentStart(20); hitsForInsert.addFirstOfPairOrFragment(first); hitsForInsert.addSecondOfPair(second); } { final SAMRecord first = new SAMRecord(header); first.setReferenceName("chrm1"); first.setAlignmentStart(8); first.setMateReferenceName(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME); first.setAlignmentStart(SAMRecord.NO_ALIGNMENT_START); hitsForInsert.addFirstOfPairOrFragment(first); } { final SAMRecord second = new SAMRecord(header); second.setReferenceName("chrm2"); second.setAlignmentStart(15); second.setMateReferenceName(SAMRecord.NO_ALIGNMENT_REFERENCE_NAME); second.setAlignmentStart(SAMRecord.NO_ALIGNMENT_START); hitsForInsert.addFirstOfPairOrFragment(second); } for (int i = 0; i < hitsForInsert.numHits(); i++) { final SAMRecord first = hitsForInsert.getFirstOfPair(i); final SAMRecord second = hitsForInsert.getSecondOfPair(i); if (first != null && second != null) { Assert.assertEquals(first.getMateAlignmentStart(), second.getAlignmentStart()); Assert.assertEquals(second.getMateAlignmentStart(), first.getAlignmentStart()); } else if (first != null) { Assert.assertEquals(first.getMateAlignmentStart(), SAMRecord.NO_ALIGNMENT_START); } else { Assert.assertEquals(second.getMateAlignmentStart(), SAMRecord.NO_ALIGNMENT_START); } } }