Skip to content

Commit

Permalink
Merge pull request #895 from hazendaz/tests
Browse files Browse the repository at this point in the history
[tests] Rewrite hamcrest to assertj and remove hamcrest from the build
  • Loading branch information
mathieucarbou authored Jan 21, 2025
2 parents 33f2c49 + d3e1d64 commit 97f2d32
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 39 deletions.
7 changes: 0 additions & 7 deletions license-maven-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -297,13 +297,6 @@
</exclusions>
</dependency>

<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<version>3.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.soebes.itf.jupiter.extension</groupId>
<artifactId>itf-assertj</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@
import static java.util.EnumSet.complementOf;
import static java.util.EnumSet.copyOf;
import static java.util.stream.Collectors.toList;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

import static org.assertj.core.api.Assertions.assertThat;

class CompleteMojoTest {

Expand Down Expand Up @@ -144,7 +143,7 @@ void test_add(HeaderType headerType, String extension) throws Exception {

String processed = FileUtils.read(new File(tmp, "file." + extension), Charset.defaultCharset());
String expected = FileUtils.read(new File("src/test/resources/complete/" + headerType + "/expected1." + extension), Charset.defaultCharset());
assertThat(processed, is(equalTo(expected)));
assertThat(processed).isEqualTo(expected);
}

@ParameterizedTest
Expand Down Expand Up @@ -173,7 +172,7 @@ void test_update(HeaderType headerType, String extension) throws Exception {

String processed = FileUtils.read(new File(tmp, "file." + extension), Charset.defaultCharset());
String expected = FileUtils.read(new File("src/test/resources/complete/" + headerType + "/expected2." + extension), Charset.defaultCharset());
assertThat(processed, is(equalTo(expected)));
assertThat(processed).isEqualTo(expected);
}

@ParameterizedTest
Expand Down Expand Up @@ -203,7 +202,7 @@ void test_remove(HeaderType headerType, String extension) throws Exception {

String processed = FileUtils.read(new File(tmp, "file." + extension), Charset.defaultCharset());
String expected = FileUtils.read(new File("src/test/resources/complete/" + headerType + "/file." + extension), Charset.defaultCharset());
assertThat(processed, is(equalTo(expected)));
assertThat(processed).isEqualTo(expected);
}

@ParameterizedTest
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
package com.mycila.maven.plugin.license;

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

import java.util.Arrays;

import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

class DefaultTest {
@Test
void test_Jenkinsfile_is_not_a_default_exclude() {
assertThat(Arrays.asList(Default.EXCLUDES), not(CoreMatchers.<String>hasItems(containsString("Jenkinsfile"))));
assertThat(Arrays.asList(Default.EXCLUDES)).doesNotContain("Jenkinsfile");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@
import java.time.Instant;
import java.time.ZoneId;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

class ReportTest {

Expand Down Expand Up @@ -68,7 +66,7 @@ void test_check_xml() throws Exception {

String processed = unixify(FileUtils.read(plugin.reportLocation, Charset.defaultCharset()));
String expected = FileUtils.read(new File("src/test/resources/issues/issue-122/check.xml"), Charset.defaultCharset());
assertThat(processed, is(equalTo(expected)));
assertThat(processed).isEqualTo(expected);
}

@Test
Expand All @@ -92,7 +90,7 @@ void test_check_json() throws Exception {

String processed = unixify(FileUtils.read(plugin.reportLocation, Charset.defaultCharset()));
String expected = FileUtils.read(new File("src/test/resources/issues/issue-122/check.json"), Charset.defaultCharset());
assertThat(processed, is(equalTo(expected)));
assertThat(processed).isEqualTo(expected);
}

@Test
Expand All @@ -112,7 +110,7 @@ void test_format_xml() throws Exception {

String processed = unixify(FileUtils.read(plugin.reportLocation, Charset.defaultCharset()));
String expected = FileUtils.read(new File("src/test/resources/issues/issue-122/format.xml"), Charset.defaultCharset());
assertThat(processed, is(equalTo(expected)));
assertThat(processed).isEqualTo(expected);
}

@Test
Expand All @@ -132,7 +130,7 @@ void test_format_json() throws Exception {

String processed = unixify(FileUtils.read(plugin.reportLocation, Charset.defaultCharset()));
String expected = FileUtils.read(new File("src/test/resources/issues/issue-122/format.json"), Charset.defaultCharset());
assertThat(processed, is(equalTo(expected)));
assertThat(processed).isEqualTo(expected);
}

@Test
Expand All @@ -152,7 +150,7 @@ void test_remove_xml() throws Exception {

String processed = unixify(FileUtils.read(plugin.reportLocation, Charset.defaultCharset()));
String expected = FileUtils.read(new File("src/test/resources/issues/issue-122/remove.xml"), Charset.defaultCharset());
assertThat(processed, is(equalTo(expected)));
assertThat(processed).isEqualTo(expected);
}

@Test
Expand All @@ -172,7 +170,7 @@ void test_remove_json() throws Exception {

String processed = unixify(FileUtils.read(plugin.reportLocation, Charset.defaultCharset()));
String expected = FileUtils.read(new File("src/test/resources/issues/issue-122/remove.json"), Charset.defaultCharset());
assertThat(processed, is(equalTo(expected)));
assertThat(processed).isEqualTo(expected);
}

private static String unixify(String s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@
import java.util.LinkedHashMap;
import java.util.List;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.assertj.core.api.Assertions.assertThat;

class UpdateMojoTest {

Expand Down Expand Up @@ -125,7 +123,7 @@ void test_issue50() throws Exception {
updater.defaultBasedir = tmp;
updater.legacyConfigHeader = "src/test/resources/update/header.txt";
updater.defaultProperties = ImmutableMap.of("year", "2008");
updater.mapping = new LinkedHashMap<String, String>() {{
updater.mapping = new LinkedHashMap<>() {{
put("properties", "SCRIPT_STYLE");
}};
updater.project = new MavenProjectStub();
Expand All @@ -150,7 +148,7 @@ void test_issue48() throws Exception {
updater.defaultBasedir = tmp;
updater.legacyConfigHeader = "src/test/resources/update/header.txt";
updater.defaultProperties = ImmutableMap.of("year", "2008");
updater.mapping = new LinkedHashMap<String, String>() {{
updater.mapping = new LinkedHashMap<>() {{
put("properties", "SCRIPT_STYLE");
}};
updater.project = new MavenProjectStub();
Expand Down Expand Up @@ -254,7 +252,7 @@ void test_issue71_canSkipSeveralLines() throws Exception {
updater.defaultBasedir = tmp;
updater.legacyConfigHeader = "src/test/resources/issues/issue-71/issue-71-header.txt";
updater.project = new MavenProjectStub();
updater.mapping = new LinkedHashMap<String, String>() {{
updater.mapping = new LinkedHashMap<>() {{
put("txt.extended", "EXTENDED_STYLE");
}};
updater.defaultHeaderDefinitions = new String[]{"/issues/issue-71/issue-71-additionalHeaderDefinitions.xml"};
Expand All @@ -263,8 +261,8 @@ void test_issue71_canSkipSeveralLines() throws Exception {

// Check that all the skipable header has been correctly skipped
List<String> linesOfModifiedFile = Files.readLines(new File(tmp, "issue-71.txt.extended"), Charset.defaultCharset());
assertThat(linesOfModifiedFile.get(0 /* line 1 */), is("|||"));
assertThat(linesOfModifiedFile.get(8) /* line 9 */, is("|||"));
assertThat(linesOfModifiedFile.get(0) /* line 1 */).isEqualTo("|||");
assertThat(linesOfModifiedFile.get(8) /* line 9 */).isEqualTo("|||");
}

@Test
Expand All @@ -289,7 +287,7 @@ void test_issue37_RunningUpdaterTwiceMustNotChangeTheFile() throws Exception {

String execution2FileContent = FileUtils.read(new File(tmp, "xwiki.xml"), Charset.defaultCharset());

assertThat(execution1FileContent, is(execution2FileContent));
assertThat(execution1FileContent).isEqualTo(execution2FileContent);
}

@Test
Expand All @@ -308,7 +306,7 @@ void test_UpdateWorksHasExpectedOnAOneLineCommentFile_relatesTo_issue30() throws
List<String> linesOfUpdatedFile = Files.readLines(new File(tmp, "one-line-comment.ftl"), Charset.defaultCharset());

// check that the original line is kept as the latest one even when introducing a license header
assertThat(linesOfOriginFile.get(0), is(linesOfUpdatedFile.get(linesOfUpdatedFile.size() - 1)));
assertThat(linesOfOriginFile.get(0)).isEqualTo(linesOfUpdatedFile.get(linesOfUpdatedFile.size() - 1));
}


Expand Down Expand Up @@ -358,7 +356,7 @@ void test_issue71_underscore_in_package_name() throws Exception {
updater.defaultBasedir = tmp;
updater.legacyConfigHeader = "src/test/resources/update/issue-187/header.txt";
updater.project = new MavenProjectStub();
updater.mapping = new LinkedHashMap<String, String>() {{
updater.mapping = new LinkedHashMap<>() {{
put("java", "JAVAPKG_STYLE");
}};

Expand All @@ -367,6 +365,6 @@ void test_issue71_underscore_in_package_name() throws Exception {
String processed = FileUtils.read(new File(tmp, "Main.java"), Charset.defaultCharset());
String expected = FileUtils.read(new File("src/test/resources/update/issue-187/expected.txt"), Charset.defaultCharset());

assertThat(processed, is(equalTo(expected)));
assertThat(processed).isEqualTo(expected);
}
}

0 comments on commit 97f2d32

Please sign in to comment.