Java tutorial
/* * Copyright 2016 EMBL - European Bioinformatics Institute * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package uk.ac.ebi.eva.pipeline.io.readers; import org.junit.Test; import org.springframework.batch.item.ExecutionContext; import org.springframework.batch.test.MetaDataInstanceFactory; import uk.ac.ebi.eva.pipeline.model.FeatureCoordinates; import uk.ac.ebi.eva.test.data.GtfStaticTestData; import uk.ac.ebi.eva.test.utils.JobTestUtils; import java.io.File; import java.io.FileInputStream; import java.util.zip.GZIPInputStream; import static junit.framework.TestCase.assertEquals; /** * {@link GeneReader} * input: a GTF File * output: a FeatureCoordinates each time `.read()` is called */ public class GeneReaderTest { @Test public void shouldReadAllLinesInGtf() throws Exception { ExecutionContext executionContext = MetaDataInstanceFactory.createStepExecution().getExecutionContext(); //simulate VEP output file File file = JobTestUtils.makeGzipFile(GtfStaticTestData.GTF_CONTENT); GeneReader geneReader = new GeneReader(file); geneReader.setSaveState(false); geneReader.open(executionContext); FeatureCoordinates gene; int chromosomeCount = 0; int count = 0; while ((gene = geneReader.read()) != null) { count++; if (gene.getChromosome() != null && !gene.getChromosome().isEmpty()) { chromosomeCount++; } } // all should have at least the chromosome field assertEquals(count, chromosomeCount); // GeneReader should get all the lines from the file long actualCount = JobTestUtils.getLines(new GZIPInputStream(new FileInputStream(file))); assertEquals(actualCount, count); } }