Skip to content

Commit

Permalink
Apply JUnit best practices
Browse files Browse the repository at this point in the history
  • Loading branch information
JPercival committed Apr 25, 2024
1 parent b6377c2 commit 0a6bea4
Show file tree
Hide file tree
Showing 91 changed files with 731 additions and 747 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"Dischargedon",
"dstu",
"Eithers",
"ersd",
"Fhir",
"fhirpath",
"Gson",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;

public class BenchmarksIT {
class BenchmarksIT {

private static final DecimalFormat df = new DecimalFormat("0.000");

Expand Down Expand Up @@ -44,7 +44,7 @@ public class BenchmarksIT {

@Test
@Disabled("Test fails during package due to test-jar not working as expected ")
public void benchmark() throws Exception {
void benchmark() throws Exception {
Options opt = new OptionsBuilder()
.include(Questionnaires.class.getSimpleName())
.include(Measures.class.getSimpleName())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.opencds.cqf.fhir.cr.measure.MeasureEvaluationOptions;
import org.opencds.cqf.fhir.cr.measure.r4.Measure;
import org.opencds.cqf.fhir.cr.measure.r4.Measure.When;
import org.opencds.cqf.fhir.cr.measure.r4.MeasureProcessorEvaluateTest;
import org.openjdk.jmh.annotations.Benchmark;
import org.openjdk.jmh.annotations.Fork;
import org.openjdk.jmh.annotations.Level;
Expand Down Expand Up @@ -46,7 +45,7 @@ public void setupTrial() throws Exception {
Bundle additionalData = (Bundle) FhirContext.forR4Cached()
.newJsonParser()
.parseResource(
MeasureProcessorEvaluateTest.class.getResourceAsStream("CaseRepresentation101/generated.json"));
this.getClass().getResourceAsStream("CaseRepresentation101/generated.json"));

this.when = Measure.given()
.repositoryFor("CaseRepresentation101")
Expand Down
5 changes: 5 additions & 0 deletions cqf-fhir-cql/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
<artifactId>cqf-fhir-utility</artifactId>
<version>3.5.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>info.cqframework</groupId>
<artifactId>cql-to-elm</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ExtensionResolverTests {
private final Extension expressionExtension = new Extension(Constants.CQF_EXPRESSION, expression);

@Test
void testExtensionResolution() {
void extensionResolution() {
var repository = new InMemoryFhirRepository(FhirContext.forR4Cached());
var libraryEngine = new LibraryEngine(repository, EvaluationSettings.getDefault());
var subjectId = Ids.newId(repository.fhirContext().getVersion().getVersion(), "Patient/Patient1");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
class LibraryEngineTests {

@Test
void testFhirPath() {
void fhirPath() {
var patientId = "Patient/Patient1";
var repository =
new IgRepository(FhirContext.forR4Cached(), Paths.get(getResourcePath(LibraryEngineTests.class)));
Expand All @@ -46,7 +46,7 @@ void testFhirPath() {
}

@Test
void testFhirPathWithResource() {
void fhirPathWithResource() {
var patientId = "Patient/Patient1";
var repository =
new IgRepository(FhirContext.forR4Cached(), Paths.get(getResourcePath(LibraryEngineTests.class)));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class VersionedIdentifiersTests {
@Test
void testExceptions() {
void exceptions() {
assertThrows(
IllegalArgumentException.class,
() -> VersionedIdentifiers.forUrl("http:https://fhir.org/guides/cdc/opioid-cds/Binary/HelloWorld"));
Expand All @@ -20,23 +20,23 @@ void testExceptions() {
}

@Test
void testUrl() {
void url() {
var url = "http:https://fhir.org/guides/cdc/opioid-cds/Library/HelloWorld";
var id = VersionedIdentifiers.forUrl(url);
assertEquals("HelloWorld", id.getId());
assertNull(id.getVersion());
}

@Test
void testCanonical() {
void canonical() {
var url = "http:https://fhir.org/guides/cdc/opioid-cds/Library/HelloWorld|1.0.0";
var id = VersionedIdentifiers.forUrl(url);
assertEquals("HelloWorld", id.getId());
assertEquals("1.0.0", id.getVersion());
}

@Test
void testReference() {
void reference() {
var reference = "Library/HelloWorld";
var id = VersionedIdentifiers.forUrl(reference);
assertEquals("HelloWorld", id.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@
import org.opencds.cqf.cql.engine.runtime.Interval;
import org.opencds.cqf.fhir.utility.adapter.AdapterFactory;

public class CqlFhirParametersConverterTests {
class CqlFhirParametersConverterTests {

protected static CqlFhirParametersConverter cqlFhirParametersConverter;

@BeforeAll
public static void setup() {
static void setup() {
FhirContext fhirContext = FhirContext.forCached(FhirVersionEnum.R4);

AdapterFactory adapterFactory = new org.opencds.cqf.fhir.utility.adapter.r4.AdapterFactory();
Expand All @@ -45,7 +45,7 @@ public static void setup() {
}

@Test
public void TestEvaluationResultToParameters() {
void TestEvaluationResultToParameters() {
Parameters expected = new Parameters();
expected.addParameter().setName("Patient").setResource(new Patient());
expected.addParameter().setName("Numerator").setValue(new BooleanType(true));
Expand All @@ -60,7 +60,7 @@ public void TestEvaluationResultToParameters() {
}

@Test
public void TestFhirParametersToCqlParameters() {
void TestFhirParametersToCqlParameters() {
Map<String, Object> expected = new HashMap<>();
expected.put("Measurement Period", new Interval(new Date("2020-01-01"), true, new Date("2021-01-01"), true));
expected.put("Product Line", "Medicare");
Expand All @@ -85,15 +85,15 @@ public void TestFhirParametersToCqlParameters() {
}

@Test
public void TestFhirParametersListToCqlParameters() {
void TestFhirParametersListToCqlParameters() {

Parameters testData = new Parameters();
testData.addParameter().setName("%encounters").setResource(new Encounter().setId("1"));
testData.addParameter().setName("%encounters").setResource(new Encounter().setId("2"));

Map<String, Object> actual = cqlFhirParametersConverter.toCqlParameters(testData);

assertEquals(actual.size(), 1);
assertEquals(1, actual.size());
assertTrue(actual.containsKey("%encounters"));

Object value = actual.get("%encounters");
Expand All @@ -103,11 +103,11 @@ public void TestFhirParametersListToCqlParameters() {
@SuppressWarnings("unchecked")
List<Encounter> encounters = (List<Encounter>) value;

assertEquals(encounters.size(), 2);
assertEquals(2, encounters.size());
}

@Test
public void TestMaxParameterDefinitionCreatesList() {
void TestMaxParameterDefinitionCreatesList() {

Parameters testData = new Parameters();
ParametersParameterComponent ppc = testData.addParameter();
Expand All @@ -118,7 +118,7 @@ public void TestMaxParameterDefinitionCreatesList() {

Map<String, Object> actual = cqlFhirParametersConverter.toCqlParameters(testData);

assertEquals(actual.size(), 1);
assertEquals(1, actual.size());
assertTrue(actual.containsKey("%encounters"));

Object value = actual.get("%encounters");
Expand All @@ -128,11 +128,11 @@ public void TestMaxParameterDefinitionCreatesList() {
@SuppressWarnings("unchecked")
List<Encounter> encounters = (List<Encounter>) value;

assertEquals(encounters.size(), 1);
assertEquals(1, encounters.size());
}

@Test
public void TestMinParameterDefinitionCreatesList() {
void TestMinParameterDefinitionCreatesList() {
Parameters testData = new Parameters();
ParametersParameterComponent ppc = testData.addParameter();

Expand All @@ -146,7 +146,7 @@ public void TestMinParameterDefinitionCreatesList() {

Map<String, Object> actual = cqlFhirParametersConverter.toCqlParameters(testData);

assertEquals(actual.size(), 1);
assertEquals(1, actual.size());
assertTrue(actual.containsKey("%encounters"));

Object value = actual.get("%encounters");
Expand All @@ -156,11 +156,11 @@ public void TestMinParameterDefinitionCreatesList() {
@SuppressWarnings("unchecked")
List<Encounter> encounters = (List<Encounter>) value;

assertEquals(encounters.size(), 1);
assertEquals(1, encounters.size());
}

@Test
public void TestInvalidParameterDefinitionThrowsException() {
void TestInvalidParameterDefinitionThrowsException() {
assertThrows(IllegalArgumentException.class, () -> {
Parameters testData = new Parameters();
ParametersParameterComponent ppc = testData.addParameter();
Expand All @@ -178,7 +178,7 @@ public void TestInvalidParameterDefinitionThrowsException() {
}

@Test
public void TestParameterDefinitionCreatesList() {
void TestParameterDefinitionCreatesList() {
Parameters testData = new Parameters();
ParametersParameterComponent ppc = testData.addParameter();
ppc.setName("%encounters");
Expand All @@ -188,7 +188,7 @@ public void TestParameterDefinitionCreatesList() {

Map<String, Object> actual = cqlFhirParametersConverter.toCqlParameters(testData);

assertEquals(actual.size(), 1);
assertEquals(1, actual.size());
assertTrue(actual.containsKey("%encounters"));

Object value = actual.get("%encounters");
Expand All @@ -198,6 +198,6 @@ public void TestParameterDefinitionCreatesList() {
@SuppressWarnings("unchecked")
List<Encounter> encounters = (List<Encounter>) value;

assertEquals(encounters.size(), 0);
assertEquals(0, encounters.size());
}
}
Loading

0 comments on commit 0a6bea4

Please sign in to comment.