Skip to content
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

Migrate to JUnit 5, apply JUnit best practices #1360

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 38 additions & 3 deletions Src/java/.vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,71 @@
"java.configuration.updateBuildConfiguration": "automatic",
"java.debug.settings.onBuildFailureProceed": true,
"java.compile.nullAnalysis.mode": "automatic",
"java.jdt.ls.vmargs": "-noverify -Xmx8G -XX:+UseG1GC -XX:+UseStringDeduplication",
"java.jdt.ls.vmargs": "-noverify -Xmx64G -XX:+UseG1GC -XX:+UseStringDeduplication",
"cSpell.words": [
"abstractclassname",
"Anded",
"antlr",
"archunit",
"BACKBONEELEMENT",
"BACKBONETYPE",
"bools",
"Bryn",
"CANONICALRESOURCE",
"checkstyle",
"Codeable",
"Codesystem",
"codesystems",
"cqframework",
"datumedge",
"DEPENDSON",
"DOMAINRESOURCE",
"DSTU",
"ecqi",
"ecqms",
"fhir",
"fhirpath",
"Gentest",
"GREATERTHAN",
"Greator",
"hamcrest",
"healthit",
"Inferencing",
"Instancio",
"javac",
"JAXB",
"Kolkata",
"LESSTHAN",
"loinc",
"MAXYEAR",
"Messageheader",
"METADATARESOURCE",
"modelinfo",
"Multisource",
"mycontentig",
"myig",
"Nullological",
"Objenesis",
"opdef",
"opencds",
"PRIMITIVETYPE",
"qicore",
"QUOTEDIDENTIFIER",
"Randomizer",
"redeclaration",
"testng",
"searchparam",
"SEARCHSET",
"SNOMED",
"tngtech",
"tomakehurst",
"trackback",
"Ucum",
"unescaping",
"Unmarshaller"
"Unmarshaller",
"valueset",
"VALUESETS",
"wiremock",
"Zulip"
],
"cSpell.enabledLanguageIds": [
"java",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
api platform("ca.uhn.hapi.fhir:hapi-fhir-bom:${hapiVersion}") {
exclude group: 'org.eclipse.jetty'
exclude group: 'xpp3'
exclude group: 'org.junit'
}

implementation "ca.uhn.hapi.fhir:hapi-fhir-base"
Expand All @@ -24,7 +25,7 @@ dependencies {
// Note that this dependency hasn't been updated since 2013
// we probably need to standardize on a fork up the dependency chain
implementation ('org.ogce:xpp3:1.1.6') {
exclude group: 'junit'
exclude group: 'org.junit'
exclude group: 'org.hamcrest'
}
}
14 changes: 7 additions & 7 deletions Src/java/buildSrc/src/main/groovy/cql.java-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@ repositories {

dependencies {
implementation 'org.slf4j:slf4j-api:1.7.36'
testImplementation 'org.testng:testng:7.4.0'
testImplementation 'org.hamcrest:hamcrest-all:1.3'
testImplementation 'uk.co.datumedge:hamcrest-json:0.2'
testImplementation 'junit:junit:4.13.2'
testImplementation(platform('org.junit:junit-bom:5.10.2'))
testImplementation('org.junit.jupiter:junit-jupiter')
testImplementation 'org.slf4j:slf4j-simple:1.7.36'

// These are JAXB dependencies excluded because the libraries need to work
// on Android. But for test purposes we use them pretty much everywhere.
testRuntimeOnly 'org.eclipse.persistence:org.eclipse.persistence.moxy:4.0.2'
testRuntimeOnly 'org.eclipse.parsson:parsson:1.1.5'
testRuntimeOnly('org.junit.platform:junit-platform-launcher')
}

jar {
Expand All @@ -52,6 +53,10 @@ jacoco {
}

test {
useJUnitPlatform()
testLogging {
events "skipped", "failed"
}
finalizedBy jacocoTestReport // report is always generated after tests run
}

Expand All @@ -71,11 +76,6 @@ tasks.withType(JavaCompile) {
options.deprecation = true
}


tasks.named('test', Test) {
useTestNG()
}

spotless {
java {
targetExclude '**/generated/**'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.cqframework.fhir.npm;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.testng.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import ca.uhn.fhir.context.FhirContext;
import java.io.InputStream;
Expand All @@ -15,28 +15,28 @@
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.model.ImplementationGuide;
import org.hl7.fhir.utilities.npm.NpmPackage;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Ignore;
import org.testng.annotations.Test;

public class NpmPackageManagerTests implements IWorkerContext.ILoggingService {

private final Logger logger = LoggerFactory.getLogger(NpmPackageManagerTests.class);
private final VersionConvertor_40_50 convertor = new VersionConvertor_40_50(new BaseAdvisor_40_50());

@Test
public void testSampleIGLocalNoDependencies() {
void sampleIGLocalNoDependencies() {
Resource igResource = (Resource) FhirContext.forR4Cached()
.newXmlParser()
.parseResource(NpmPackageManagerTests.class.getResourceAsStream("myig.xml"));
ImplementationGuide ig = (ImplementationGuide) convertor.convertResource(igResource);
NpmPackageManager pm = new NpmPackageManager(ig);
assertEquals(pm.getNpmList().size(), 1);
assertEquals(1, pm.getNpmList().size());
}

@Test
public void testSampleContentIGLocalWithRecursiveDependencies() {
void sampleContentIGLocalWithRecursiveDependencies() {
Resource igResource = (Resource) FhirContext.forR4Cached()
.newXmlParser()
.parseResource(NpmPackageManagerTests.class.getResourceAsStream("mycontentig.xml"));
Expand Down Expand Up @@ -65,7 +65,7 @@ public void testSampleContentIGLocalWithRecursiveDependencies() {
}

@Test
public void testOpioidMMEIGLocalWithSingleFileDependency() {
void opioidMmeIGLocalWithSingleFileDependency() {
Resource igResource = (Resource) FhirContext.forR4Cached()
.newXmlParser()
.parseResource(NpmPackageManagerTests.class.getResourceAsStream("opioid-mme-r4.xml"));
Expand All @@ -89,8 +89,8 @@ public void testOpioidMMEIGLocalWithSingleFileDependency() {
}

@Test
@Ignore("This test depends on the example.fhir.uv.myig package, which is not currently published")
public void testLibrarySourceProviderLocal() {
@Disabled("This test depends on the example.fhir.uv.myig package, which is not currently published")
void librarySourceProviderLocal() {
Resource igResource = (Resource) FhirContext.forR4Cached()
.newXmlParser()
.parseResource(NpmPackageManagerTests.class.getResourceAsStream("mycontentig.xml"));
Expand All @@ -111,7 +111,7 @@ public void testLibrarySourceProviderLocal() {
}

@Test
public void testModelInfoProviderLocal() {
void modelInfoProviderLocal() {
Resource igResource = (Resource) FhirContext.forR4Cached()
.newXmlParser()
.parseResource(NpmPackageManagerTests.class.getResourceAsStream("testig.xml"));
Expand All @@ -125,7 +125,7 @@ public void testModelInfoProviderLocal() {
.withSystem("http://hl7.org/fhir/us/qicore")
.withId("QICore"));
assertNotNull(mi);
assertEquals(mi.getName(), "QICore");
assertEquals("QICore", mi.getName());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@

public class IGUtils {

private IGUtils() {
// intentionally empty
}

public static String getImplementationGuideCanonicalBase(String url) {
String canonicalBase = null;

Expand All @@ -19,12 +23,11 @@ public static String getImplementationGuideCanonicalBase(String url) {
return canonicalBase;
}

public static ArrayList<String> extractResourcePaths(String rootDir, ImplementationGuide sourceIg)
throws IOException {
public static List<String> extractResourcePaths(String rootDir, ImplementationGuide sourceIg) throws IOException {
ArrayList<String> result = new ArrayList<>();
for (ImplementationGuide.ImplementationGuideDefinitionParameterComponent p :
sourceIg.getDefinition().getParameter()) {
if (p.getCode().equals("path-resource")) {
if ("path-resource".equals(p.getCode().getCode())) {
result.add(Utilities.path(rootDir, p.getValue()));
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
package org.cqframework.fhir.utilities;

import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

public class TestIGContext implements IWorkerContext.ILoggingService {

@Test
public void testTypesAndValuesIG() throws URISyntaxException {
void typesAndValuesIG() throws URISyntaxException {
URL url = TestIGContext.class.getResource("types-and-values/ig.ini");
assertNotNull(url);
URI uri = Uris.parseOrNull(url.toURI().toString());
assertNotNull(uri);
String path = uri.getSchemeSpecificPart();
IGContext igContext = new IGContext(this);
igContext.initializeFromIni(path);
assertEquals(igContext.getPackageId(), "fhir.cqf.typesandvalues");
assertEquals(igContext.getCanonicalBase(), "http://fhir.org/guides/cqf/typesandvalues");
assertEquals("fhir.cqf.typesandvalues", igContext.getPackageId());
assertEquals("http://fhir.org/guides/cqf/typesandvalues", igContext.getCanonicalBase());
}

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

import java.util.ArrayList;
import java.util.List;
import org.antlr.v4.runtime.Recognizer;
import org.antlr.v4.runtime.TokenStream;
import org.antlr.v4.runtime.misc.Interval;
import org.antlr.v4.runtime.tree.ParseTree;
Expand Down Expand Up @@ -58,7 +59,7 @@ public Object visitLibrary(cqlParser.LibraryContext ctx) {
for (int i = 0; i < ctx.getChildCount(); i++) {
ParseTree tree = ctx.getChild(i);
TerminalNode terminalNode = tree instanceof TerminalNode ? (TerminalNode) tree : null;
if (terminalNode != null && terminalNode.getSymbol().getType() == cqlLexer.EOF) {
if (terminalNode != null && terminalNode.getSymbol().getType() == Recognizer.EOF) {
continue;
}

Expand Down Expand Up @@ -168,7 +169,6 @@ public Object visitUsingDefinition(cqlParser.UsingDefinitionContext ctx) {
}

@Override
@SuppressWarnings("unchecked")
public Object visitCodesystemDefinition(cqlParser.CodesystemDefinitionContext ctx) {
CodesystemDefinitionInfo codesystemDefinition = new CodesystemDefinitionInfo();
codesystemDefinition.setName(parseString(ctx.identifier()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
import org.cqframework.cql.cql2elm.model.LibraryRef;
import org.cqframework.cql.elm.IdObjectFactory;
import org.hl7.elm.r1.Element;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Test;

public class ArchitectureTest {
class ArchitectureTest {

@Test
public void ensureNoDirectElmConstruction() {
void ensureNoDirectElmConstruction() {

JavaClasses importedClasses = new ClassFileImporter().importPackages("org.cqframework.cql");

Expand Down
Loading
Loading