Skip to content

Commit

Permalink
test: Migration JUNIT4 -> JUNIT5 TemporalFolder and ExpectedException…
Browse files Browse the repository at this point in the history
… Rules #TASK-5174
  • Loading branch information
juanfeSanahuja committed Feb 20, 2024
1 parent 111f46c commit e70dc9c
Show file tree
Hide file tree
Showing 62 changed files with 262 additions and 210 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package org.opencb.biodata.formats;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.formats.gaf.GafParser;
import org.opencb.biodata.models.core.AnnotationEvidence;
import org.opencb.biodata.models.core.FeatureOntologyTermAnnotation;
import org.opencb.commons.utils.FileUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.opencb.biodata.formats;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.formats.obo.OboParser;
import org.opencb.biodata.models.core.OntologyTerm;
import org.opencb.commons.utils.FileUtils;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.opencb.biodata.formats.alignment.samtools.io;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.formats.alignment.samtools.SamtoolsFlagstats;

import java.io.ByteArrayInputStream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@

package org.opencb.biodata.formats.annotation.io;

import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.formats.variant.annotation.io.VepFormatReader;
import org.opencb.biodata.models.variant.avro.VariantAnnotation;
//import org.opencb.biodata.models.variant.annotation.VariantAnnotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.opencb.biodata.formats.feature.gtf.io;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.formats.feature.gtf.Gtf;

import java.io.StringReader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.opencb.biodata.formats.pedigree;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.models.clinical.pedigree.Pedigree;

import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.formats.pubmed.v233jaxb.PubmedArticle;
import org.opencb.biodata.formats.pubmed.v233jaxb.PubmedArticleSet;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.opencb.biodata.formats.variant;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.formats.variant.vcf4.VariantAggregatedVcfFactory;
import org.opencb.biodata.formats.variant.vcf4.VariantVcfFactory;
import org.opencb.biodata.models.variant.StudyEntry;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.opencb.biodata.formats.variant.annotation.io;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.models.variant.Variant;
import org.opencb.biodata.models.variant.avro.VariantAvro;
import org.opencb.commons.utils.FileUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.opencb.biodata.formats.variant.clinvar;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.formats.variant.clinvar.rcv.ClinvarParser;
import org.opencb.biodata.formats.variant.clinvar.rcv.v64jaxb.PublicSetType;
import org.opencb.biodata.formats.variant.clinvar.rcv.v64jaxb.ReleaseType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

package org.opencb.biodata.formats.variant.vcf4.io;

import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.formats.variant.io.VariantReader;
import org.opencb.biodata.models.variant.Variant;
import org.opencb.biodata.formats.variant.vcf4.VariantAggregatedVcfFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.opencb.biodata.models.clinical.interpretation;

import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.models.clinical.ClinicalAcmg;
import org.opencb.biodata.models.clinical.ClinicalProperty;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.opencb.biodata.models.core;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package org.opencb.biodata.models.feature;

import org.junit.Rule;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.rules.ExpectedException;
import org.opencb.biodata.models.variant.Genotype;

Expand Down Expand Up @@ -98,23 +99,38 @@ public void testParse() {

@Test
public void testParseFail1() {
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Unknown allele");
new Genotype("AAA|T", "A", Arrays.asList("G", "C", "T")).getAllelesIdx();
IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Genotype("AAA|T", "A", Arrays.asList("G", "C", "T")).getAllelesIdx();
});
Assertions.assertEquals("Unable to parse genotype 'AAA|T'. Unknown allele \"AAA\". REF=A,ALT=G,C,T", thrown.getMessage());
}

@Test
public void testParseFail2() {
/*
thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Empty allele");
new Genotype("A|T|", "A", Arrays.asList("G", "C", "T")).getAllelesIdx();
*/

IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Genotype("A|T|", "A", Arrays.asList("G", "C", "T")).getAllelesIdx();

});
Assertions.assertEquals("Unable to parse genotype 'A|T|'. Empty allele: REF=A,ALT=G,C,T", thrown.getMessage());
}

@Test
public void testParseFail3() {
thrown.expect(IllegalArgumentException.class);
/* thrown.expect(IllegalArgumentException.class);
thrown.expectMessage("Empty allele");
new Genotype("|C", "A", Arrays.asList("G", "C", "T")).getAllelesIdx();
new Genotype("|C", "A", Arrays.asList("G", "C", "T")).getAllelesIdx();*/

IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> {
new Genotype("|C", "A", Arrays.asList("G", "C", "T")).getAllelesIdx();
});
Assertions.assertEquals("Unable to parse genotype '|C'. Empty allele: REF=A,ALT=G,C,T", thrown.getMessage());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.opencb.biodata.models.variant;

import org.apache.commons.lang3.RandomStringUtils;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.models.variant.avro.*;
import org.opencb.biodata.models.variant.protobuf.VariantProto;

Expand Down Expand Up @@ -240,14 +241,19 @@ public void buildIndelVariantNoEnd_large() {
assertEquals(100 + ref.length() - 1, variant.getEnd().intValue());
}

@Test(expected = IllegalArgumentException.class)
@Test
public void buildIncompleteSV() throws Exception {
new VariantBuilder("1:1000:<DEL>").build();
IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> {
new VariantBuilder("1:1000:<DEL>").build();
});

}

@Test(expected = IllegalArgumentException.class)
@Test
public void buildIncompleteSV_2() throws Exception {
new VariantBuilder("1:1000:A:<DEL>").build();
IllegalArgumentException thrown = Assertions.assertThrows(IllegalArgumentException.class, () -> {
new VariantBuilder("1:1000:A:<DEL>").build();
});
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package org.opencb.biodata.models.variant;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.assertEquals;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.opencb.biodata.models.variant.stats;

import org.junit.Test;
import org.junit.jupiter.api.Test;

import static org.junit.Assert.*;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package org.opencb.biodata.tools.alignment;

import htsjdk.samtools.*;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.models.alignment.RegionCoverage;
import org.opencb.biodata.models.core.Region;
import org.opencb.biodata.tools.alignment.exceptions.AlignmentCoverageException;
Expand Down Expand Up @@ -32,9 +33,9 @@ public class BamManagerTest {
Path bamPath;
Path bwPath;

@Before
@BeforeEach
public void init() throws URISyntaxException, IOException {
Assume.assumeTrue(bamCoverageExists());
Assumptions.assumeTrue(bamCoverageExists());

inputPath = Paths.get(getClass().getResource("/HG00096.chrom20.small.bam").toURI());
bamPath = Paths.get("/tmp/" + inputPath.toFile().getName());
Expand Down Expand Up @@ -80,14 +81,14 @@ public void testQuery() throws Exception {
AlignmentOptions options = new AlignmentOptions().setLimit(5);
Region region = new Region("20", 60000, 65000);
List<SAMRecord> query = bamManager.query(region, options);
assertEquals(5, query.size());
Assertions.assertEquals(5, query.size());

options.setLimit(3);
query = bamManager.query(region, options);
for (SAMRecord sam: query) {
System.out.println(sam.toString());
}
assertEquals(3, query.size());
Assertions.assertEquals(3, query.size());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ga4gh.Reads;
import htsjdk.samtools.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.net.URISyntaxException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.opencb.biodata.tools.alignment.filters;

import htsjdk.samtools.SAMRecord;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.models.core.Region;
import org.opencb.biodata.tools.alignment.AlignmentOptions;
import org.opencb.biodata.tools.alignment.BamManager;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.opencb.biodata.tools.alignment.iterators;

import htsjdk.samtools.SAMRecord;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.models.core.Region;
import org.opencb.biodata.tools.alignment.AlignmentOptions;
import org.opencb.biodata.tools.alignment.BamManager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import htsjdk.samtools.SAMRecord;
import org.ga4gh.models.ReadAlignment;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.tools.alignment.BamManager;
import org.opencb.biodata.tools.alignment.AlignmentOptions;
import org.opencb.biodata.tools.alignment.iterators.BamIterator;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.opencb.biodata.tools.commons;

import org.junit.Before;
import org.junit.jupiter.api.BeforeEach;
import org.opencb.biodata.models.core.Region;
import org.opencb.biodata.tools.alignment.BamUtils;
import org.opencb.biodata.tools.feature.WigUtils;
Expand All @@ -19,7 +19,7 @@ public class ChunkFrequencyManagerTest {
int chunkSize = 1000;
int windowSize = 100;

@Before
@BeforeEach
public void init() throws Exception {
bamPath = Paths.get(getClass().getResource("/HG00096.chrom20.small.bam").toURI());
coverageWigPath = Paths.get("/tmp/" + bamPath.toFile().getName() + ".bam.coverage.wig");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package org.opencb.biodata.tools.feature;

import org.broad.igv.bbfile.*;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.models.core.Region;
import org.opencb.biodata.tools.commons.ChunkFrequencyManager;

import java.nio.file.Path;
import java.nio.file.Paths;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.opencb.biodata.tools.pedigree;

import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.opencb.biodata.models.clinical.Disorder;
import org.opencb.biodata.models.clinical.pedigree.Member;
import org.opencb.biodata.models.clinical.pedigree.Pedigree;
Expand Down Expand Up @@ -36,7 +36,7 @@ public class ModeOfInheritanceTest {
Disorder disorder3;
Disorder disorder4;

@Before
@BeforeEach
public void before() {
disorder1 = new Disorder("disease1", "disease1", "", "", Collections.emptyList(), Collections.emptyMap());
disorder2 = new Disorder("disease2", "disease2", "", "", Collections.emptyList(), Collections.emptyMap());
Expand Down
Loading

0 comments on commit e70dc9c

Please sign in to comment.