Skip to content

Commit

Permalink
Add AsyncFeatureWriterTest
Browse files Browse the repository at this point in the history
  • Loading branch information
magicDGS committed Aug 28, 2017
1 parent 7b940f4 commit 7b106b9
Showing 1 changed file with 76 additions and 0 deletions.
76 changes: 76 additions & 0 deletions src/test/java/htsjdk/tribble/writer/AsyncFeatureWriterTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2017 Daniel Gomez-Sanchez
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package htsjdk.tribble.writer;

import htsjdk.tribble.Feature;
import htsjdk.tribble.FeatureCodec;
import htsjdk.tribble.SimpleFeature;
import htsjdk.tribble.bed.BEDCodec;
import htsjdk.tribble.bed.BEDSimpleEncoder;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

/**
* @author Daniel Gomez-Sanchez (magicDGS)
*/
public class AsyncFeatureWriterTest extends FeatureWriterTester {

@Test(dataProvider = "bedFiles")
public void readWriteSimpleBed(final File bedFile) throws Exception {
testReadWrite(bedFile, (FeatureCodec) new BEDCodec(), (f) -> {
try {
return new AsyncFeatureWriter<>(new FeatureWriterImpl<>(new BEDSimpleEncoder(), new FileOutputStream(f)));
} catch (final FileNotFoundException e) {
throw new AssertionError(e.getMessage());
}
});
}

@DataProvider
public Object[][] featuresAndHeaders() {
return new Object[][] {
{Collections.singletonList(new SimpleFeature("chr1", 1, 100)),
Collections.singletonList("header1")},
{Arrays.asList(new SimpleFeature("chr1", 10, 100),
new SimpleFeature("chr2", 1, 100)), Arrays.asList("header1", "header2")}
};
}

@Test(dataProvider = "featuresAndHeaders")
public void testWriteHeaderAndFeatures(final List<Feature> featuresToWrite,
final List<Object> headersToWrite) throws Exception {
testWriteHeaderAndFeatures((encoder, file) ->
new AsyncFeatureWriter<>(new FeatureWriterImpl(encoder, file)),
featuresToWrite, headersToWrite);
}

}

0 comments on commit 7b106b9

Please sign in to comment.