-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix CRAMIterator when next() is called without hasNext() #1193
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1193 +/- ##
===============================================
+ Coverage 68.405% 68.423% +0.018%
- Complexity 8017 8020 +3
===============================================
Files 542 542
Lines 32701 32701
Branches 5530 5530
===============================================
+ Hits 22369 22375 +6
+ Misses 8127 8123 -4
+ Partials 2205 2203 -2
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some minor things
@@ -271,7 +266,11 @@ public boolean hasNext() { | |||
|
|||
@Override | |||
public SAMRecord next() { | |||
return iterator.next(); | |||
if(hasNext()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space after if
|
||
public final class CRAMTestUtils { | ||
|
||
private CRAMTestUtils(){}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that there's no point in instantiating this class, but why bother enforcing it with a private constructor?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does make it clear that there is no point in instantiating the class, which I like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unlike a singleton, there's no harm if a user decides to instantiate it. They can't break anything or change behavior that we'd like to control. So I'd still say there is no need to bother enforcing it for this class. But I guess it comes down to a matter of taste..
|
||
private static CRAMFileReader writeAndReadFromInMemoryCram(Collection<SAMRecord> records, CRAMReferenceSource source, SAMFileHeader header) throws IOException { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
CRAMFileWriter cramFileWriter = new CRAMFileWriter(baos, source, header, "whatever"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use try-with-resources to avoid close()
below. Since baos
is closable too you could put that in the try
as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I stuck it in a try with resources so that it will always close on exit, but I left the close to force a flush before reading from the buffer, the alternative was a gross nested try statement.
/** | ||
* return a CRAMReferenceSource that returns all A's for any sequence queried | ||
*/ | ||
public static CRAMReferenceSource getFakeReferenceSource(){ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing space between ){
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of minor comments. Thx for adding the utilities.
final CRAMFileReader reader = CRAMTestUtils.writeAndReadFromInMemoryCram(builder); | ||
final SAMRecordIterator iterator = reader.getIterator(); | ||
Assert.assertNotNull(iterator.next()); | ||
Assert.assertThrows(NoSuchElementException.class, iterator::next); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That two tests, but, ok...
|
||
public final class CRAMTestUtils { | ||
|
||
private CRAMTestUtils(){}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does make it clear that there is no point in instantiating the class, which I like.
* fixing a bug in CRAMIterator which previously threw if next() was called without first calling hasNext() * adding CRAMTestUtils and extracting a method to it from CramEdgeCasesTest
39c0997
to
3fb463d
Compare
Checklist