Don't set a custom default InflaterFactory when testing passing in an explicit InflaterFactory #795

Merged
merged 1 commit into from Feb 1, 2017
Jump to file or symbol
Failed to load files and symbols.
+23 −12
Split
@@ -147,30 +147,38 @@ public Inflater makeInflater( boolean gzipCompatible ) {
final List<String> linesWritten = writeTempBlockCompressedFileForInflaterTest(tempFile);
final InflaterFactory countingInflaterFactory = new CountingInflaterFactory();
- BlockGunzipper.setDefaultInflaterFactory(countingInflaterFactory);
return new Object[][]{
- // use default InflaterFactory
- {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new FileInputStream(tempFile), false), linesWritten, 4},
- {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(tempFile), linesWritten, 4},
- {(CheckedExceptionInputStreamSupplier) () -> new AsyncBlockCompressedInputStream(tempFile), linesWritten, 4},
- {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new URL("http://broadinstitute.github.io/picard/testdata/index_test.bam")), null, 21},
- // provide InflaterFactory
- {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new FileInputStream(tempFile), false, countingInflaterFactory), linesWritten, 4},
- {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(tempFile, countingInflaterFactory), linesWritten, 4},
- {(CheckedExceptionInputStreamSupplier) () -> new AsyncBlockCompressedInputStream(tempFile, countingInflaterFactory), linesWritten, 4},
- {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new URL("http://broadinstitute.github.io/picard/testdata/index_test.bam"), countingInflaterFactory), null, 21}
+ // set the default InflaterFactory to a CountingInflaterFactory
+ {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new FileInputStream(tempFile), false), linesWritten, 4, countingInflaterFactory},
+ {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(tempFile), linesWritten, 4, countingInflaterFactory},
+ {(CheckedExceptionInputStreamSupplier) () -> new AsyncBlockCompressedInputStream(tempFile), linesWritten, 4, countingInflaterFactory},
+ {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new URL("http://broadinstitute.github.io/picard/testdata/index_test.bam")), null, 21, countingInflaterFactory},
+ // provide a CountingInflaterFactory explicitly
+ {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new FileInputStream(tempFile), false, countingInflaterFactory), linesWritten, 4, null},
+ {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(tempFile, countingInflaterFactory), linesWritten, 4, null},
+ {(CheckedExceptionInputStreamSupplier) () -> new AsyncBlockCompressedInputStream(tempFile, countingInflaterFactory), linesWritten, 4, null},
+ {(CheckedExceptionInputStreamSupplier) () -> new BlockCompressedInputStream(new URL("http://broadinstitute.github.io/picard/testdata/index_test.bam"), countingInflaterFactory), null, 21, null}
};
}
@Test(dataProvider = "customInflaterInput", singleThreaded = true)
public void testCustomInflater(final CheckedExceptionInputStreamSupplier bcisSupplier,
final List<String> expectedOutput,
- final int expectedInflateCalls) throws Exception
+ final int expectedInflateCalls,
+ final InflaterFactory customDefaultInflaterFactory) throws Exception
{
// clear inflate call counter in CountingInflater
CountingInflater.inflateCalls = 0;
+ // If requested, set the global default InflaterFactory to a custom factory. Otherwise, set it to the default.
+ if ( customDefaultInflaterFactory != null ) {
+ BlockGunzipper.setDefaultInflaterFactory(customDefaultInflaterFactory);
+ }
+ else {
+ BlockGunzipper.setDefaultInflaterFactory(new InflaterFactory());
+ }
+
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(bcisSupplier.get()))) {
String line;
for (int i = 0; (line = reader.readLine()) != null; ++i) {
@@ -183,6 +191,9 @@ public void testCustomInflater(final CheckedExceptionInputStreamSupplier bcisSup
// verify custom inflater was used by checking number of inflate calls
Assert.assertEquals(CountingInflater.inflateCalls, expectedInflateCalls, "inflate calls");
+
+ // Reset the default InflaterFactory back to the default value
+ BlockGunzipper.setDefaultInflaterFactory(new InflaterFactory());
}
@Test(expectedExceptions = IllegalArgumentException.class)