From 01054a7a038fd01ece73a12cdd328c1374652107 Mon Sep 17 00:00:00 2001 From: Russell Howe Date: Sun, 25 Feb 2024 10:05:53 +0000 Subject: [PATCH] Replace hamcrest assertions with jUnit assertions Hamcrest isn't really adding anything here, so we may as well just use the junit assertion APIs --- .../resolver/ClasspathResolverTest.java | 28 +++++------ .../resolver/FileSystemResolverTest.java | 50 +++++++++---------- 2 files changed, 37 insertions(+), 41 deletions(-) diff --git a/compiler/src/test/java/com/github/mustachejava/resolver/ClasspathResolverTest.java b/compiler/src/test/java/com/github/mustachejava/resolver/ClasspathResolverTest.java index 132ee7e1..42b1168b 100644 --- a/compiler/src/test/java/com/github/mustachejava/resolver/ClasspathResolverTest.java +++ b/compiler/src/test/java/com/github/mustachejava/resolver/ClasspathResolverTest.java @@ -4,10 +4,8 @@ import java.io.Reader; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; public class ClasspathResolverTest { @@ -15,7 +13,7 @@ public class ClasspathResolverTest { public void getReaderNullRootAndResourceHasRelativePath() throws Exception { ClasspathResolver underTest = new ClasspathResolver(); try (Reader reader = underTest.getReader("nested_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -23,7 +21,7 @@ public void getReaderNullRootAndResourceHasRelativePath() throws Exception { public void getReaderWithRootAndResourceHasRelativePath() throws Exception { ClasspathResolver underTest = new ClasspathResolver("templates"); try (Reader reader = underTest.getReader("absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -31,7 +29,7 @@ public void getReaderWithRootAndResourceHasRelativePath() throws Exception { public void getReaderWithRootThatHasTrailingForwardSlashAndResourceHasRelativePath() throws Exception { ClasspathResolver underTest = new ClasspathResolver("templates/"); try (Reader reader = underTest.getReader("absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -39,7 +37,7 @@ public void getReaderWithRootThatHasTrailingForwardSlashAndResourceHasRelativePa public void getReaderWithRootAndResourceHasAbsolutePath() throws Exception { ClasspathResolver underTest = new ClasspathResolver("templates"); try (Reader reader = underTest.getReader("/absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -47,7 +45,7 @@ public void getReaderWithRootAndResourceHasAbsolutePath() throws Exception { public void getReaderWithRootThatHasTrailingForwardSlashAndResourceHasAbsolutePath() throws Exception { ClasspathResolver underTest = new ClasspathResolver("templates/"); try (Reader reader = underTest.getReader("/absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -55,7 +53,7 @@ public void getReaderWithRootThatHasTrailingForwardSlashAndResourceHasAbsolutePa public void getReaderNullRootDoesNotFindFileWithAbsolutePath() throws Exception { ClasspathResolver underTest = new ClasspathResolver(); try (Reader reader = underTest.getReader("/nested_partials_template.html")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -75,7 +73,7 @@ public void getReaderNullRootAndNullResourceThrowsNullPointer() throws Exception public void getReaderWithRootAndResourceHasDoubleDotRelativePath() throws Exception { ClasspathResolver underTest = new ClasspathResolver("templates"); try (Reader reader = underTest.getReader("absolute/../absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -83,7 +81,7 @@ public void getReaderWithRootAndResourceHasDoubleDotRelativePath() throws Except public void getReaderWithRootAndResourceHasDotRelativePath() throws Exception { ClasspathResolver underTest = new ClasspathResolver("templates"); try (Reader reader = underTest.getReader("absolute/./nested_partials_sub.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -106,7 +104,7 @@ public void getReaderWithRootAndResourceHasInvalidPathThrows() throws Exception public void getReaderNullRootAndResourceIsDirectory() throws Exception { ClasspathResolver underTest = new ClasspathResolver(); try (Reader reader = underTest.getReader("templates/absolute")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -115,7 +113,7 @@ public void getReaderNullRootAndResourceIsDirectory() throws Exception { public void getReaderWithRootAndResourceIsDirectory() throws Exception { ClasspathResolver underTest = new ClasspathResolver("templates"); try (Reader reader = underTest.getReader("absolute")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -124,7 +122,7 @@ public void getReaderWithRootAndResourceIsDirectory() throws Exception { public void getReaderWithRootAndResourceAboveRoot() throws Exception { ClasspathResolver underTest = new ClasspathResolver("templates/absolute"); try (Reader reader = underTest.getReader("../absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } } diff --git a/compiler/src/test/java/com/github/mustachejava/resolver/FileSystemResolverTest.java b/compiler/src/test/java/com/github/mustachejava/resolver/FileSystemResolverTest.java index 986017a1..efd0c894 100644 --- a/compiler/src/test/java/com/github/mustachejava/resolver/FileSystemResolverTest.java +++ b/compiler/src/test/java/com/github/mustachejava/resolver/FileSystemResolverTest.java @@ -10,10 +10,8 @@ import java.nio.file.Path; import java.nio.file.Paths; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.core.Is.is; -import static org.junit.Assert.assertThat; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; public class FileSystemResolverTest { @@ -23,7 +21,7 @@ public class FileSystemResolverTest { public void getReaderDefaultRootAndResourceHasRelativePath() throws Exception { FileSystemResolver underTest = new FileSystemResolver(); try (Reader reader = underTest.getReader(resources + "/nested_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -32,7 +30,7 @@ public void getReaderFileRootAndResourceHasRelativePath() throws Exception { File fileRoot = new File(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(fileRoot); try (Reader reader = underTest.getReader("absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -41,7 +39,7 @@ public void getReaderPathRootAndResourceHasRelativePath() throws Exception { Path pathRoot = Paths.get(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(pathRoot); try (Reader reader = underTest.getReader("absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -49,7 +47,7 @@ public void getReaderPathRootAndResourceHasRelativePath() throws Exception { public void getReaderDefaultRootDoesNotFindFileWithAbsolutePath() throws Exception { FileSystemResolver underTest = new FileSystemResolver(); try (Reader reader = underTest.getReader("/" + resources + "/nested_partials_template.html")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -58,7 +56,7 @@ public void getReaderFileRootAndResourceHasAbsolutePath() throws Exception { File fileRoot = new File(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(fileRoot); try (Reader reader = underTest.getReader("/absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -67,7 +65,7 @@ public void getReaderPathRootAndResourceHasAbsolutePath() throws Exception { Path pathRoot = Paths.get(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(pathRoot); try (Reader reader = underTest.getReader("/absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -95,7 +93,7 @@ public void getReaderPathRootAndNullResourceThrowsNullPointer() throws Exception public void getReaderDefaultRootAndResourceHasDoubleDotRelativePath() throws Exception { FileSystemResolver underTest = new FileSystemResolver(); try (Reader reader = underTest.getReader(resources + "/templates_filepath/../nested_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -104,7 +102,7 @@ public void getReaderFileRootAndResourceHasDoubleDotRelativePath() throws Except File fileRoot = new File(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(fileRoot); try (Reader reader = underTest.getReader("absolute/../absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -113,7 +111,7 @@ public void getReaderPathRootAndResourceHasDoubleDotRelativePath() throws Except Path pathRoot = Paths.get(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(pathRoot); try (Reader reader = underTest.getReader("absolute/../absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -121,7 +119,7 @@ public void getReaderPathRootAndResourceHasDoubleDotRelativePath() throws Except public void getReaderDefaultRootAndResourceHasDotRelativePath() throws Exception { FileSystemResolver underTest = new FileSystemResolver(); try (Reader reader = underTest.getReader(resources + "/templates_filepath/./absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -130,7 +128,7 @@ public void getReaderFileRootAndResourceHasDotRelativePath() throws Exception { File fileRoot = new File(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(fileRoot); try (Reader reader = underTest.getReader("absolute/./nested_partials_sub.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -139,7 +137,7 @@ public void getReaderPathRootAndResourceHasDotRelativePath() throws Exception { Path pathRoot = Paths.get(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(pathRoot); try (Reader reader = underTest.getReader("absolute/./nested_partials_sub.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } @@ -147,7 +145,7 @@ public void getReaderPathRootAndResourceHasDotRelativePath() throws Exception { public void getReaderDefaultRootAndResourceHasInvalidPath() throws Exception { FileSystemResolver underTest = new FileSystemResolver(); try (Reader reader = underTest.getReader("\0")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -156,7 +154,7 @@ public void getReaderFileRootAndResourceHasInvalidPath() throws Exception { File fileRoot = new File(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(fileRoot); try (Reader reader = underTest.getReader("\0")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -165,7 +163,7 @@ public void getReaderPathRootAndResourceHasInvalidPath() throws Exception { Path pathRoot = Paths.get(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(pathRoot); try (Reader reader = underTest.getReader("\0")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -176,7 +174,7 @@ public void getReaderPathRootAndNonDefaultFileSystem() throws Exception { Path pathRoot = zipFileSystem.getPath("templates"); FileSystemResolver underTest = new FileSystemResolver(pathRoot); try (Reader reader = underTest.getReader("absolute_partials_template.html")) { - assertThat(reader, is(notNullValue())); + assertNotNull(reader); } } } @@ -185,7 +183,7 @@ public void getReaderPathRootAndNonDefaultFileSystem() throws Exception { public void getReaderDefaultRootAndResourceIsDirectory() throws Exception { FileSystemResolver underTest = new FileSystemResolver(); try (Reader reader = underTest.getReader(resources + "/templates_filepath")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -194,7 +192,7 @@ public void getReaderFileRootAndResourceIsDirectory() throws Exception { File fileRoot = new File(resources); FileSystemResolver underTest = new FileSystemResolver(fileRoot); try (Reader reader = underTest.getReader("templates_filepath")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -203,7 +201,7 @@ public void getReaderPathRootAndResourceIsDirectory() throws Exception { Path pathRoot = Paths.get(resources); FileSystemResolver underTest = new FileSystemResolver(pathRoot); try (Reader reader = underTest.getReader("templates_filepath")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -214,7 +212,7 @@ public void getReaderPathRootAndResourceIsDirectory() throws Exception { public void getReaderDefaultRootAndResourceAboveRootNotFound() throws Exception { FileSystemResolver underTest = new FileSystemResolver(); try (Reader reader = underTest.getReader("../this_file_does_not_exist.html")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -230,7 +228,7 @@ public void getReaderFileRootAndResourceAboveRootNotFound() throws Exception { File fileRoot = new File(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(fileRoot); try (Reader reader = underTest.getReader("../this_file_does_not_exist.html")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } @@ -246,7 +244,7 @@ public void getReaderPathRootAndResourceAboveRootNotFound() throws Exception { Path pathRoot = Paths.get(resources + "/templates_filepath"); FileSystemResolver underTest = new FileSystemResolver(pathRoot); try (Reader reader = underTest.getReader("../this_file_does_not_exist.html")) { - assertThat(reader, is(nullValue())); + assertNull(reader); } } }