diff --git a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/filewatch/FileSystemWatcher.java b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/filewatch/FileSystemWatcher.java index 7531e4ee04..0f46a0c0e9 100644 --- a/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/filewatch/FileSystemWatcher.java +++ b/spring-boot-devtools/src/main/java/org/springframework/boot/devtools/filewatch/FileSystemWatcher.java @@ -114,7 +114,8 @@ public class FileSystemWatcher { */ public synchronized void addSourceFolder(File folder) { Assert.notNull(folder, "Folder must not be null"); - Assert.isTrue(folder.isDirectory(), "Folder must not be a file"); + Assert.isTrue(folder.isDirectory(), "Folder '" + folder + "' must exist and must" + + " be a directory"); checkNotStarted(); this.folders.put(folder, null); } diff --git a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/filewatch/FileSystemWatcherTests.java b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/filewatch/FileSystemWatcherTests.java index 1af417ffad..37e799e59f 100644 --- a/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/filewatch/FileSystemWatcherTests.java +++ b/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/filewatch/FileSystemWatcherTests.java @@ -38,6 +38,7 @@ import org.springframework.util.FileCopyUtils; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; import static org.mockito.Mockito.mock; @@ -107,6 +108,25 @@ public class FileSystemWatcherTests { this.watcher.addSourceFolder(null); } + @Test + public void sourceFolderMustExist() throws Exception { + File folder = new File("does/not/exist"); + assertThat(folder.exists(), is(false)); + this.thrown.expect(IllegalArgumentException.class); + this.thrown + .expectMessage("Folder 'does/not/exist' must exist and must be a directory"); + this.watcher.addSourceFolder(folder); + } + + @Test + public void sourceFolderMustBeADirectory() throws Exception { + File folder = new File("pom.xml"); + assertThat(folder.isFile(), is(true)); + this.thrown.expect(IllegalArgumentException.class); + this.thrown.expectMessage("Folder 'pom.xml' must exist and must be a directory"); + this.watcher.addSourceFolder(new File("pom.xml")); + } + @Test public void cannotAddSourceFolderToStartedListener() throws Exception { this.thrown.expect(IllegalStateException.class);