Skip to content

Commit

Permalink
Replace hamcrest assertions with jUnit assertions
Browse files Browse the repository at this point in the history
Hamcrest isn't really adding anything here, so we may as well just use
the junit assertion APIs
  • Loading branch information
rhowe authored and spullara committed Feb 26, 2024
1 parent 5c3735e commit 01054a7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,56 @@

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 {

@Test
public void getReaderNullRootAndResourceHasRelativePath() throws Exception {
ClasspathResolver underTest = new ClasspathResolver();
try (Reader reader = underTest.getReader("nested_partials_template.html")) {
assertThat(reader, is(notNullValue()));
assertNotNull(reader);
}
}

@Test
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);
}
}

@Test
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);
}
}

@Test
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);
}
}

@Test
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);
}
}

@Test
public void getReaderNullRootDoesNotFindFileWithAbsolutePath() throws Exception {
ClasspathResolver underTest = new ClasspathResolver();
try (Reader reader = underTest.getReader("/nested_partials_template.html")) {
assertThat(reader, is(nullValue()));
assertNull(reader);
}
}

Expand All @@ -75,15 +73,15 @@ 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);
}
}

@Test
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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -41,15 +39,15 @@ 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);
}
}

@Test
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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -113,15 +111,15 @@ 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);
}
}

@Test
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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -139,15 +137,15 @@ 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);
}
}

@Test
public void getReaderDefaultRootAndResourceHasInvalidPath() throws Exception {
FileSystemResolver underTest = new FileSystemResolver();
try (Reader reader = underTest.getReader("\0")) {
assertThat(reader, is(nullValue()));
assertNull(reader);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand All @@ -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);
}
}
}

0 comments on commit 01054a7

Please sign in to comment.