Polish PathResourceTests

This commit is contained in:
Sam Brannen 2022-10-05 15:49:47 +02:00
parent f0556b6004
commit 2e05137ff9
1 changed files with 8 additions and 16 deletions

View File

@ -69,22 +69,19 @@ class PathResourceTests {
@Test @Test
void nullPath() { void nullPath() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((Path) null))
new PathResource((Path) null))
.withMessageContaining("Path must not be null"); .withMessageContaining("Path must not be null");
} }
@Test @Test
void nullPathString() { void nullPathString() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((String) null))
new PathResource((String) null))
.withMessageContaining("Path must not be null"); .withMessageContaining("Path must not be null");
} }
@Test @Test
void nullUri() { void nullUri() {
assertThatIllegalArgumentException().isThrownBy(() -> assertThatIllegalArgumentException().isThrownBy(() -> new PathResource((URI) null))
new PathResource((URI) null))
.withMessageContaining("URI must not be null"); .withMessageContaining("URI must not be null");
} }
@ -166,15 +163,13 @@ class PathResourceTests {
@Test @Test
void getInputStreamForDir() throws IOException { void getInputStreamForDir() throws IOException {
PathResource resource = new PathResource(TEST_DIR); PathResource resource = new PathResource(TEST_DIR);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy( assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getInputStream);
resource::getInputStream);
} }
@Test @Test
void getInputStreamDoesNotExist() throws IOException { void getInputStreamDoesNotExist() throws IOException {
PathResource resource = new PathResource(NON_EXISTING_FILE); PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy( assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getInputStream);
resource::getInputStream);
} }
@Test @Test
@ -202,8 +197,7 @@ class PathResourceTests {
given(path.normalize()).willReturn(path); given(path.normalize()).willReturn(path);
given(path.toFile()).willThrow(new UnsupportedOperationException()); given(path.toFile()).willThrow(new UnsupportedOperationException());
PathResource resource = new PathResource(path); PathResource resource = new PathResource(path);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy( assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getFile);
resource::getFile);
} }
@Test @Test
@ -283,8 +277,7 @@ class PathResourceTests {
@Test @Test
void directoryOutputStream() throws IOException { void directoryOutputStream() throws IOException {
PathResource resource = new PathResource(TEST_DIR); PathResource resource = new PathResource(TEST_DIR);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy( assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::getOutputStream);
resource::getOutputStream);
} }
@Test @Test
@ -312,8 +305,7 @@ class PathResourceTests {
@Test @Test
void getReadableByteChannelDoesNotExist() throws IOException { void getReadableByteChannelDoesNotExist() throws IOException {
PathResource resource = new PathResource(NON_EXISTING_FILE); PathResource resource = new PathResource(NON_EXISTING_FILE);
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy( assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(resource::readableChannel);
resource::readableChannel);
} }
@Test @Test