Skip to content

Commit

Permalink
Use assertj instead of hamcrest (#1662)
Browse files Browse the repository at this point in the history
* Use assertj instead of hamcrest

* Trim README
  • Loading branch information
dotasek authored Jun 20, 2024
1 parent c631f6c commit 9b43743
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 42 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -282,4 +282,3 @@ This project is maintained by [Grahame Grieve][Link-grahameGithub], [James Agnew
[Badge-cliSonatypeSnapshot]: https://img.shields.io/nexus/s/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.validation.cli.svg "Sonatype Snapshots"
[Badge-validationSonatypeRelease]: https://img.shields.io/nexus/r/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.validation.svg "Sonatype Releases"
[Badge-validationSonatypeSnapshot]: https://img.shields.io/nexus/s/https/oss.sonatype.org/ca.uhn.hapi.fhir/org.hl7.fhir.validation.svg "Sonatype Snapshots"

7 changes: 7 additions & 0 deletions org.hl7.fhir.utilities/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@
<optional>true</optional>
</dependency>


<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.mockftpserver</groupId>
<artifactId>MockFtpServer</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hl7.fhir.utilities;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -29,7 +28,7 @@ private static void assertAWarningIsGivenWhenNotUTF8(String allWrittenLines) {
if (Charset.defaultCharset().equals(StandardCharsets.UTF_8)) {
assertEquals(0, allWrittenLines.length());
} else {
assertThat(allWrittenLines, containsString("WARNING"));
assertThat(allWrittenLines).contains("WARNING");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hl7.fhir.utilities.i18n;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -67,11 +66,11 @@ void testFormatMessagePluralWithoutInitLocale() {

//Answer value must be of the type {1}
String resultOne = testClass.formatMessagePlural(1, I18nConstants.QUESTIONNAIRE_QR_ITEM_WRONGTYPE);
assertThat(resultOne, containsString("be of the type"));
assertThat(resultOne).contains("be of the type");

//Answer value must be one of the {0} types {1}
String resultMany = testClass.formatMessagePlural(3, I18nConstants.QUESTIONNAIRE_QR_ITEM_WRONGTYPE);
assertThat(resultMany, containsString("one of the 3 types "));
assertThat(resultMany).contains("one of the 3 types ");

}

Expand All @@ -83,11 +82,11 @@ void testFormatMessagePluralWithInitLocale() {
testClass.setLocale(Locale.GERMAN);
//Answer value muss vom Typ {0} sein.
String resultOne = testClass.formatMessagePlural(1, I18nConstants.QUESTIONNAIRE_QR_ITEM_WRONGTYPE);
assertThat(resultOne, containsString("muss vom Typ"));
assertThat(resultOne).contains("muss vom Typ");

//Answer value muss einer der Typen {1} sein
String resultMany = testClass.formatMessagePlural(3, I18nConstants.QUESTIONNAIRE_QR_ITEM_WRONGTYPE);
assertThat(resultMany, containsString("einer der Typen "));
assertThat(resultMany).contains("einer der Typen ");

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hl7.fhir.utilities.npm;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.StringStartsWith.startsWith;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

Expand Down Expand Up @@ -149,7 +148,7 @@ public void testPackageFhirServer() throws IOException, InterruptedException {
private static void assertBasicAuthorization(RecordedRequest packageRequest) {
String authorizationHeader = packageRequest.getHeader("Authorization");

assertThat(authorizationHeader, startsWith("Basic"));
assertThat(authorizationHeader).startsWith("Basic");
byte[] data = Base64.getDecoder().decode(authorizationHeader.substring(6));
String authorizationValue = new String(data, StandardCharsets.UTF_8);
String[] authorizationColumns = authorizationValue.split(":");
Expand All @@ -161,7 +160,7 @@ private static void assertBasicAuthorization(RecordedRequest packageRequest) {
private static void assertTokenAuthorization(RecordedRequest packageRequest) {
String authorizationHeader = packageRequest.getHeader("Authorization");

assertThat(authorizationHeader, startsWith("Bearer"));
assertThat(authorizationHeader).startsWith("Bearer");
String token = authorizationHeader.substring(7);

assertEquals(MockPackageServer.DUMMY_TOKEN, token);
Expand Down
13 changes: 0 additions & 13 deletions org.hl7.fhir.validation.cli/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -248,19 +248,6 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
<version>${hamcrest_version}</version>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>${hamcrest_version}</version>
<scope>compile</scope>
</dependency>

<!-- /org.hl7.fhir.core test-jar dependencies -->

Expand Down
6 changes: 6 additions & 0 deletions org.hl7.fhir.validation/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
package org.hl7.fhir.validation;

import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.MatcherAssert.assertThat;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.hl7.fhir.validation.cli.utils;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.assertEquals;

import java.io.File;
Expand Down Expand Up @@ -33,6 +32,6 @@ void testFhirSettingsFileDoesntExist() {
java.lang.Error error = Assertions.assertThrows(java.lang.Error.class, () -> {
CliContext cliContext = Params.loadCliContext(new String[]{"-fhir-settings", "this-does-not-exist.json"});
});
assertThat(error.getMessage(), containsString("this-does-not-exist.json"));
assertThat(error.getMessage()).contains("this-does-not-exist.json");
}
}
22 changes: 14 additions & 8 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,12 @@
<artifactId>logback-core</artifactId>
<version>1.2.13</version>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.22.0</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down Expand Up @@ -398,14 +404,14 @@
<goals>
<goal>checkstyle</goal>
</goals>
<configuration>
<failsOnError>true</failsOnError>
<suppressionsLocation>${project.basedir}/checkstyle_suppressions.xml</suppressionsLocation>
<enableRulesSummary>true</enableRulesSummary>
<enableSeveritySummary>true</enableSeveritySummary>
<consoleOutput>true</consoleOutput>
<configLocation>${checkstyle_config_location}/checkstyle.xml</configLocation>
</configuration>
<configuration>
<failsOnError>true</failsOnError>
<suppressionsLocation>${project.basedir}/checkstyle_suppressions.xml</suppressionsLocation>
<enableRulesSummary>true</enableRulesSummary>
<enableSeveritySummary>true</enableSeveritySummary>
<consoleOutput>true</consoleOutput>
<configLocation>${checkstyle_config_location}/checkstyle.xml</configLocation>
</configuration>
</execution>
</executions>
</plugin>
Expand Down

0 comments on commit 9b43743

Please sign in to comment.