From c128ccff0c2b2acfcd47860916072799778c9344 Mon Sep 17 00:00:00 2001 From: "MD. Mohiuddin Ahmed" Date: Thu, 7 Jul 2022 04:22:01 +0600 Subject: [PATCH] Checking empty upload location --- .../uploadingfiles/storage/FileSystemStorageService.java | 5 +++++ .../storage/FileSystemStorageServiceTests.java | 9 +++++++++ .../uploadingfiles/storage/FileSystemStorageService.java | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/complete/src/main/java/com/example/uploadingfiles/storage/FileSystemStorageService.java b/complete/src/main/java/com/example/uploadingfiles/storage/FileSystemStorageService.java index a0f4e3c..4142cc9 100755 --- a/complete/src/main/java/com/example/uploadingfiles/storage/FileSystemStorageService.java +++ b/complete/src/main/java/com/example/uploadingfiles/storage/FileSystemStorageService.java @@ -24,6 +24,11 @@ public class FileSystemStorageService implements StorageService { @Autowired public FileSystemStorageService(StorageProperties properties) { + + if(properties.getLocation().trim().length() == 0){ + throw new StorageException("File upload location can not be Empty."); + } + this.rootLocation = Paths.get(properties.getLocation()); } diff --git a/complete/src/test/java/com/example/uploadingfiles/storage/FileSystemStorageServiceTests.java b/complete/src/test/java/com/example/uploadingfiles/storage/FileSystemStorageServiceTests.java index 7bb45fc..73e0b32 100755 --- a/complete/src/test/java/com/example/uploadingfiles/storage/FileSystemStorageServiceTests.java +++ b/complete/src/test/java/com/example/uploadingfiles/storage/FileSystemStorageServiceTests.java @@ -47,6 +47,15 @@ public void init() { service.init(); } + @Test + public void emptyUploadLocation() { + service = null; + properties.setLocation(""); + assertThrows(StorageException.class, () -> { + service = new FileSystemStorageService(properties); + }); + } + @Test public void loadNonExistent() { assertThat(service.load("foo.txt")).doesNotExist(); diff --git a/initial/src/main/java/com/example/uploadingfiles/storage/FileSystemStorageService.java b/initial/src/main/java/com/example/uploadingfiles/storage/FileSystemStorageService.java index d5e2fa3..faf11fc 100644 --- a/initial/src/main/java/com/example/uploadingfiles/storage/FileSystemStorageService.java +++ b/initial/src/main/java/com/example/uploadingfiles/storage/FileSystemStorageService.java @@ -21,6 +21,11 @@ public class FileSystemStorageService implements StorageService { @Autowired public FileSystemStorageService(StorageProperties properties) { + + if(properties.getLocation().trim().length() == 0){ + throw new StorageException("File upload location can not be Empty."); + } + this.rootLocation = Paths.get(properties.getLocation()); }