Skip to content

Commit

Permalink
Polish PathResourceTests
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Oct 5, 2022
1 parent f0556b6 commit 2e05137
Showing 1 changed file with 8 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,22 +69,19 @@ private static String platformPath(String string) {

@Test
void nullPath() {
assertThatIllegalArgumentException().isThrownBy(() ->
new PathResource((Path) null))
assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((Path) null))
.withMessageContaining("Path must not be null");
}

@Test
void nullPathString() {
assertThatIllegalArgumentException().isThrownBy(() ->
new PathResource((String) null))
assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((String) null))
.withMessageContaining("Path must not be null");
}

@Test
void nullUri() {
assertThatIllegalArgumentException().isThrownBy(() ->
new PathResource((URI) null))
assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((URI) null))
.withMessageContaining("URI must not be null");
}

Expand Down Expand Up @@ -166,15 +163,13 @@ void getInputStream() throws IOException {
@Test
void getInputStreamForDir() throws IOException {
PathResource resource = new PathResource(TEST_DIR);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
resource::getInputStream);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getInputStream);
}

@Test
void getInputStreamDoesNotExist() throws IOException {
PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
resource::getInputStream);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getInputStream);
}

@Test
Expand Down Expand Up @@ -202,8 +197,7 @@ void getFileUnsupported() throws IOException {
given(path.normalize()).willReturn(path);
given(path.toFile()).willThrow(new UnsupportedOperationException());
PathResource resource = new PathResource(path);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
resource::getFile);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getFile);
}

@Test
Expand Down Expand Up @@ -283,8 +277,7 @@ void doesNotExistOutputStream(@TempDir Path temporaryFolder) throws IOException
@Test
void directoryOutputStream() throws IOException {
PathResource resource = new PathResource(TEST_DIR);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
resource::getOutputStream);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getOutputStream);
}

@Test
Expand Down Expand Up @@ -312,8 +305,7 @@ void getReadableByteChannelForDir() throws IOException {
@Test
void getReadableByteChannelDoesNotExist() throws IOException {
PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(
resource::readableChannel);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::readableChannel);
}

@Test
Expand Down

0 comments on commit 2e05137

Please sign in to comment.