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()); }