Replace "folder" with "directory"

Consistently use the term "directory" instead of "folder"

Closes gh-21218
This commit is contained in:
Phillip Webb
2020-04-28 18:27:41 -07:00
parent ec871d6752
commit ad1248e4ec
98 changed files with 853 additions and 835 deletions

View File

@@ -213,8 +213,8 @@ class LocalDevToolsAutoConfigurationTests {
ClassPathFileSystemWatcher classPathWatcher = this.context.getBean(ClassPathFileSystemWatcher.class);
Object watcher = ReflectionTestUtils.getField(classPathWatcher, "fileSystemWatcher");
@SuppressWarnings("unchecked")
Map<File, Object> folders = (Map<File, Object>) ReflectionTestUtils.getField(watcher, "folders");
assertThat(folders).hasSize(2).containsKey(new File("src/main/java").getAbsoluteFile())
Map<File, Object> directories = (Map<File, Object>) ReflectionTestUtils.getField(watcher, "directories");
assertThat(directories).hasSize(2).containsKey(new File("src/main/java").getAbsoluteFile())
.containsKey(new File("src/test/java").getAbsoluteFile());
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -32,7 +32,7 @@ import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfi
import org.springframework.boot.devtools.remote.server.DispatcherFilter;
import org.springframework.boot.devtools.restart.MockRestarter;
import org.springframework.boot.devtools.restart.server.HttpRestartServer;
import org.springframework.boot.devtools.restart.server.SourceFolderUrlFilter;
import org.springframework.boot.devtools.restart.server.SourceDirectoryUrlFilter;
import org.springframework.boot.test.util.TestPropertyValues;
import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebApplicationContext;
import org.springframework.context.annotation.Bean;
@@ -244,8 +244,8 @@ class RemoteDevToolsAutoConfigurationTests {
@Bean
HttpRestartServer remoteRestartHttpRestartServer() {
SourceFolderUrlFilter sourceFolderUrlFilter = mock(SourceFolderUrlFilter.class);
return new MockHttpRestartServer(sourceFolderUrlFilter);
SourceDirectoryUrlFilter sourceDirectoryUrlFilter = mock(SourceDirectoryUrlFilter.class);
return new MockHttpRestartServer(sourceDirectoryUrlFilter);
}
}
@@ -257,8 +257,8 @@ class RemoteDevToolsAutoConfigurationTests {
private boolean invoked;
MockHttpRestartServer(SourceFolderUrlFilter sourceFolderUrlFilter) {
super(sourceFolderUrlFilter);
MockHttpRestartServer(SourceDirectoryUrlFilter sourceDirectoryUrlFilter) {
super(sourceDirectoryUrlFilter);
}
@Override

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -93,10 +93,10 @@ class ClassPathFileChangeListenerTests {
private void testSendsEvent(boolean restart) {
ClassPathFileChangeListener listener = new ClassPathFileChangeListener(this.eventPublisher,
this.restartStrategy, this.fileSystemWatcher);
File folder = new File("s1");
File directory = new File("s1");
File file = new File("f1");
ChangedFile file1 = new ChangedFile(folder, file, ChangedFile.Type.ADD);
ChangedFile file2 = new ChangedFile(folder, file, ChangedFile.Type.ADD);
ChangedFile file1 = new ChangedFile(directory, file, ChangedFile.Type.ADD);
ChangedFile file2 = new ChangedFile(directory, file, ChangedFile.Type.ADD);
Set<ChangedFile> files = new LinkedHashSet<>();
files.add(file1);
files.add(file2);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -57,19 +57,19 @@ class ClassPathFileSystemWatcherTests {
}
@Test
void configuredWithRestartStrategy(@TempDir File folder) throws Exception {
void configuredWithRestartStrategy(@TempDir File directory) throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
Map<String, Object> properties = new HashMap<>();
List<URL> urls = new ArrayList<>();
urls.add(new URL("https://spring.io"));
urls.add(folder.toURI().toURL());
urls.add(directory.toURI().toURL());
properties.put("urls", urls);
MapPropertySource propertySource = new MapPropertySource("test", properties);
context.getEnvironment().getPropertySources().addLast(propertySource);
context.register(Config.class);
context.refresh();
Thread.sleep(200);
File classFile = new File(folder, "Example.class");
File classFile = new File(directory, "Example.class");
FileCopyUtils.copy("file".getBytes(), classFile);
Thread.sleep(1000);
List<ClassPathChangedEvent> events = context.getBean(Listener.class).getEvents();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -49,29 +49,29 @@ class PatternClassPathRestartStrategyTests {
void singlePattern() {
ClassPathRestartStrategy strategy = createStrategy("static/**");
assertRestartRequired(strategy, "static/file.txt", false);
assertRestartRequired(strategy, "static/folder/file.txt", false);
assertRestartRequired(strategy, "static/directory/file.txt", false);
assertRestartRequired(strategy, "public/file.txt", true);
assertRestartRequired(strategy, "public/folder/file.txt", true);
assertRestartRequired(strategy, "public/directory/file.txt", true);
}
@Test
void multiplePatterns() {
ClassPathRestartStrategy strategy = createStrategy("static/**,public/**");
assertRestartRequired(strategy, "static/file.txt", false);
assertRestartRequired(strategy, "static/folder/file.txt", false);
assertRestartRequired(strategy, "static/directory/file.txt", false);
assertRestartRequired(strategy, "public/file.txt", false);
assertRestartRequired(strategy, "public/folder/file.txt", false);
assertRestartRequired(strategy, "public/directory/file.txt", false);
assertRestartRequired(strategy, "src/file.txt", true);
assertRestartRequired(strategy, "src/folder/file.txt", true);
assertRestartRequired(strategy, "src/directory/file.txt", true);
}
@Test
void pomChange() {
ClassPathRestartStrategy strategy = createStrategy("META-INF/maven/**");
assertRestartRequired(strategy, "pom.xml", true);
String mavenFolder = "META-INF/maven/org.springframework.boot/spring-boot-devtools";
assertRestartRequired(strategy, mavenFolder + "/pom.xml", false);
assertRestartRequired(strategy, mavenFolder + "/pom.properties", false);
String mavenDirectory = "META-INF/maven/org.springframework.boot/spring-boot-devtools";
assertRestartRequired(strategy, mavenDirectory + "/pom.xml", false);
assertRestartRequired(strategy, mavenDirectory + "/pom.properties", false);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -55,7 +55,7 @@ class DevToolsHomePropertiesPostProcessorTests {
}
@Test
void loadsPropertiesFromHomeFolderUsingProperties() throws Exception {
void loadsPropertiesFromHomeDirectoryUsingProperties() throws Exception {
Properties properties = new Properties();
properties.put("abc", "def");
writeFile(properties, ".spring-boot-devtools.properties");
@@ -64,7 +64,7 @@ class DevToolsHomePropertiesPostProcessorTests {
}
@Test
void loadsPropertiesFromConfigFolderUsingProperties() throws Exception {
void loadsPropertiesFromConfigDirectoryUsingProperties() throws Exception {
Properties properties = new Properties();
properties.put("abc", "def");
OutputStream out = new FileOutputStream(new File(this.configDir, "spring-boot-devtools.properties"));
@@ -75,7 +75,7 @@ class DevToolsHomePropertiesPostProcessorTests {
}
@Test
void loadsPropertiesFromConfigFolderUsingYml() throws Exception {
void loadsPropertiesFromConfigDirectoryUsingYml() throws Exception {
OutputStream out = new FileOutputStream(new File(this.configDir, "spring-boot-devtools.yml"));
File file = new ClassPathResource("spring-devtools.yaml", getClass()).getFile();
byte[] content = Files.readAllBytes(file.toPath());
@@ -86,7 +86,7 @@ class DevToolsHomePropertiesPostProcessorTests {
}
@Test
void loadsPropertiesFromConfigFolderUsingYaml() throws Exception {
void loadsPropertiesFromConfigDirectoryUsingYaml() throws Exception {
OutputStream out = new FileOutputStream(new File(this.configDir, "spring-boot-devtools.yaml"));
File file = new ClassPathResource("spring-devtools.yaml", getClass()).getFile();
byte[] content = Files.readAllBytes(file.toPath());
@@ -97,7 +97,7 @@ class DevToolsHomePropertiesPostProcessorTests {
}
@Test
void loadFromConfigFolderWithPropertiesTakingPrecedence() throws Exception {
void loadFromConfigDirectoryWithPropertiesTakingPrecedence() throws Exception {
OutputStream out = new FileOutputStream(new File(this.configDir, "spring-boot-devtools.yaml"));
File file = new ClassPathResource("spring-devtools.yaml", getClass()).getFile();
byte[] content = Files.readAllBytes(file.toPath());
@@ -114,7 +114,7 @@ class DevToolsHomePropertiesPostProcessorTests {
}
@Test
void loadFromConfigFolderTakesPrecedenceOverHomeFolder() throws Exception {
void loadFromConfigDirectoryTakesPrecedenceOverHomeDirectory() throws Exception {
Properties properties = new Properties();
properties.put("abc", "def");
properties.put("bar", "baz");
@@ -130,7 +130,7 @@ class DevToolsHomePropertiesPostProcessorTests {
}
@Test
void loadFromConfigFolderWithYamlTakesPrecedenceOverHomeFolder() throws Exception {
void loadFromConfigDirectoryWithYamlTakesPrecedenceOverHomeDirectory() throws Exception {
Properties properties = new Properties();
properties.put("abc.xyz", "jkl");
properties.put("bar", "baz");
@@ -173,7 +173,7 @@ class DevToolsHomePropertiesPostProcessorTests {
private class MockDevToolHomePropertiesPostProcessor extends DevToolsHomePropertiesPostProcessor {
@Override
protected File getHomeFolder() {
protected File getHomeDirectory() {
return DevToolsHomePropertiesPostProcessorTests.this.home;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,45 +37,44 @@ class ChangedFileTests {
File tempDir;
@Test
void sourceFolderMustNotBeNull() throws Exception {
void sourceDirectoryMustNotBeNull() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(() -> new ChangedFile(null, new File(this.tempDir, "file"), Type.ADD))
.withMessageContaining("SourceFolder must not be null");
.withMessageContaining("SourceDirectory must not be null");
}
@Test
void fileMustNotBeNull() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(() -> new ChangedFile(new File(this.tempDir, "folder"), null, Type.ADD))
.isThrownBy(() -> new ChangedFile(new File(this.tempDir, "directory"), null, Type.ADD))
.withMessageContaining("File must not be null");
}
@Test
void typeMustNotBeNull() throws Exception {
assertThatIllegalArgumentException()
.isThrownBy(
() -> new ChangedFile(new File(this.tempDir, "file"), new File(this.tempDir, "folder"), null))
assertThatIllegalArgumentException().isThrownBy(
() -> new ChangedFile(new File(this.tempDir, "file"), new File(this.tempDir, "directory"), null))
.withMessageContaining("Type must not be null");
}
@Test
void getFile() throws Exception {
File file = new File(this.tempDir, "file");
ChangedFile changedFile = new ChangedFile(new File(this.tempDir, "folder"), file, Type.ADD);
ChangedFile changedFile = new ChangedFile(new File(this.tempDir, "directory"), file, Type.ADD);
assertThat(changedFile.getFile()).isEqualTo(file);
}
@Test
void getType() throws Exception {
ChangedFile changedFile = new ChangedFile(new File(this.tempDir, "folder"), new File(this.tempDir, "file"),
ChangedFile changedFile = new ChangedFile(new File(this.tempDir, "directory"), new File(this.tempDir, "file"),
Type.DELETE);
assertThat(changedFile.getType()).isEqualTo(Type.DELETE);
}
@Test
void getRelativeName() throws Exception {
File subFolder = new File(this.tempDir, "A");
File file = new File(subFolder, "B.txt");
File subDirectory = new File(this.tempDir, "A");
File file = new File(subDirectory, "B.txt");
ChangedFile changedFile = new ChangedFile(this.tempDir, file, Type.ADD);
assertThat(changedFile.getRelativeName()).isEqualTo("A/B.txt");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,72 +31,72 @@ import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
/**
* Tests for {@link FolderSnapshot}.
* Tests for {@link DirectorySnapshot}.
*
* @author Phillip Webb
*/
class FolderSnapshotTests {
class DirectorySnapshotTests {
@TempDir
File tempDir;
private File folder;
private File directory;
private FolderSnapshot initialSnapshot;
private DirectorySnapshot initialSnapshot;
@BeforeEach
void setup() throws Exception {
this.folder = createTestFolderStructure();
this.initialSnapshot = new FolderSnapshot(this.folder);
this.directory = createTestDirectoryStructure();
this.initialSnapshot = new DirectorySnapshot(this.directory);
}
@Test
void folderMustNotBeNull() {
assertThatIllegalArgumentException().isThrownBy(() -> new FolderSnapshot(null))
.withMessageContaining("Folder must not be null");
void directoryMustNotBeNull() {
assertThatIllegalArgumentException().isThrownBy(() -> new DirectorySnapshot(null))
.withMessageContaining("Directory must not be null");
}
@Test
void folderMustNotBeFile() throws Exception {
void directoryMustNotBeFile() throws Exception {
File file = new File(this.tempDir, "file");
file.createNewFile();
assertThatIllegalArgumentException().isThrownBy(() -> new FolderSnapshot(file))
.withMessageContaining("Folder '" + file + "' must not be a file");
assertThatIllegalArgumentException().isThrownBy(() -> new DirectorySnapshot(file))
.withMessageContaining("Directory '" + file + "' must not be a file");
}
@Test
void folderDoesNotHaveToExist() throws Exception {
void directoryDoesNotHaveToExist() throws Exception {
File file = new File(this.tempDir, "does/not/exist");
FolderSnapshot snapshot = new FolderSnapshot(file);
assertThat(snapshot).isEqualTo(new FolderSnapshot(file));
DirectorySnapshot snapshot = new DirectorySnapshot(file);
assertThat(snapshot).isEqualTo(new DirectorySnapshot(file));
}
@Test
void equalsWhenNothingHasChanged() {
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
DirectorySnapshot updatedSnapshot = new DirectorySnapshot(this.directory);
assertThat(this.initialSnapshot).isEqualTo(updatedSnapshot);
assertThat(this.initialSnapshot.hashCode()).isEqualTo(updatedSnapshot.hashCode());
}
@Test
void notEqualsWhenAFileIsAdded() throws Exception {
new File(new File(this.folder, "folder1"), "newfile").createNewFile();
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
new File(new File(this.directory, "directory1"), "newfile").createNewFile();
DirectorySnapshot updatedSnapshot = new DirectorySnapshot(this.directory);
assertThat(this.initialSnapshot).isNotEqualTo(updatedSnapshot);
}
@Test
void notEqualsWhenAFileIsDeleted() {
new File(new File(this.folder, "folder1"), "file1").delete();
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
new File(new File(this.directory, "directory1"), "file1").delete();
DirectorySnapshot updatedSnapshot = new DirectorySnapshot(this.directory);
assertThat(this.initialSnapshot).isNotEqualTo(updatedSnapshot);
}
@Test
void notEqualsWhenAFileIsModified() throws Exception {
File file1 = new File(new File(this.folder, "folder1"), "file1");
File file1 = new File(new File(this.directory, "directory1"), "file1");
FileCopyUtils.copy("updatedcontent".getBytes(), file1);
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
DirectorySnapshot updatedSnapshot = new DirectorySnapshot(this.directory);
assertThat(this.initialSnapshot).isNotEqualTo(updatedSnapshot);
}
@@ -107,30 +107,30 @@ class FolderSnapshotTests {
}
@Test
void getChangedFilesSnapshotMustBeTheSameSourceFolder() throws Exception {
void getChangedFilesSnapshotMustBeTheSameSourceDirectory() throws Exception {
assertThatIllegalArgumentException().isThrownBy(
() -> this.initialSnapshot.getChangedFiles(new FolderSnapshot(createTestFolderStructure()), null))
.withMessageContaining("Snapshot source folder must be '" + this.folder + "'");
() -> this.initialSnapshot.getChangedFiles(new DirectorySnapshot(createTestDirectoryStructure()), null))
.withMessageContaining("Snapshot source directory must be '" + this.directory + "'");
}
@Test
void getChangedFilesWhenNothingHasChanged() {
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
DirectorySnapshot updatedSnapshot = new DirectorySnapshot(this.directory);
this.initialSnapshot.getChangedFiles(updatedSnapshot, null);
}
@Test
void getChangedFilesWhenAFileIsAddedAndDeletedAndChanged() throws Exception {
File folder1 = new File(this.folder, "folder1");
File file1 = new File(folder1, "file1");
File file2 = new File(folder1, "file2");
File newFile = new File(folder1, "newfile");
File directory1 = new File(this.directory, "directory1");
File file1 = new File(directory1, "file1");
File file2 = new File(directory1, "file2");
File newFile = new File(directory1, "newfile");
FileCopyUtils.copy("updatedcontent".getBytes(), file1);
file2.delete();
newFile.createNewFile();
FolderSnapshot updatedSnapshot = new FolderSnapshot(this.folder);
DirectorySnapshot updatedSnapshot = new DirectorySnapshot(this.directory);
ChangedFiles changedFiles = this.initialSnapshot.getChangedFiles(updatedSnapshot, null);
assertThat(changedFiles.getSourceFolder()).isEqualTo(this.folder);
assertThat(changedFiles.getSourceDirectory()).isEqualTo(this.directory);
assertThat(getChangedFile(changedFiles, file1).getType()).isEqualTo(Type.MODIFY);
assertThat(getChangedFile(changedFiles, file2).getType()).isEqualTo(Type.DELETE);
assertThat(getChangedFile(changedFiles, newFile).getType()).isEqualTo(Type.ADD);
@@ -145,12 +145,12 @@ class FolderSnapshotTests {
return null;
}
private File createTestFolderStructure() throws IOException {
private File createTestDirectoryStructure() throws IOException {
File root = new File(this.tempDir, UUID.randomUUID().toString());
File folder1 = new File(root, "folder1");
folder1.mkdirs();
FileCopyUtils.copy("abc".getBytes(), new File(folder1, "file1"));
FileCopyUtils.copy("abc".getBytes(), new File(folder1, "file2"));
File directory1 = new File(root, "directory1");
directory1.mkdirs();
FileCopyUtils.copy("abc".getBytes(), new File(directory1, "file1"));
FileCopyUtils.copy("abc".getBytes(), new File(directory1, "file2"));
return root;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,11 +51,11 @@ class FileSnapshotTests {
}
@Test
void fileMustNotBeAFolder() throws Exception {
void fileMustNotBeADirectory() throws Exception {
File file = new File(this.tempDir, "file");
file.mkdir();
assertThatIllegalArgumentException().isThrownBy(() -> new FileSnapshot(file))
.withMessageContaining("File must not be a folder");
.withMessageContaining("File must not be a directory");
}
@Test

View File

@@ -94,70 +94,70 @@ class FileSystemWatcherTests {
}
@Test
void sourceFolderMustNotBeNull() {
assertThatIllegalArgumentException().isThrownBy(() -> this.watcher.addSourceFolder(null))
.withMessageContaining("Folder must not be null");
void sourceDirectoryMustNotBeNull() {
assertThatIllegalArgumentException().isThrownBy(() -> this.watcher.addSourceDirectory(null))
.withMessageContaining("Directory must not be null");
}
@Test
void sourceFolderMustNotBeAFile() throws IOException {
void sourceDirectoryMustNotBeAFile() throws IOException {
File file = new File(this.tempDir, "file");
assertThat(file.createNewFile()).isTrue();
assertThat(file.isFile()).isTrue();
assertThatIllegalArgumentException().isThrownBy(() -> this.watcher.addSourceFolder(file))
.withMessageContaining("Folder '" + file + "' must not be a file");
assertThatIllegalArgumentException().isThrownBy(() -> this.watcher.addSourceDirectory(file))
.withMessageContaining("Directory '" + file + "' must not be a file");
}
@Test
void cannotAddSourceFolderToStartedListener() throws Exception {
void cannotAddSourceDirectoryToStartedListener() throws Exception {
this.watcher.start();
assertThatIllegalStateException().isThrownBy(() -> this.watcher.addSourceFolder(this.tempDir))
assertThatIllegalStateException().isThrownBy(() -> this.watcher.addSourceDirectory(this.tempDir))
.withMessageContaining("FileSystemWatcher already started");
}
@Test
void addFile() throws Exception {
File folder = startWithNewFolder();
File file = touch(new File(folder, "test.txt"));
File directory = startWithNewDirectory();
File file = touch(new File(directory, "test.txt"));
this.watcher.stopAfter(1);
ChangedFiles changedFiles = getSingleChangedFiles();
ChangedFile expected = new ChangedFile(folder, file, Type.ADD);
ChangedFile expected = new ChangedFile(directory, file, Type.ADD);
assertThat(changedFiles.getFiles()).contains(expected);
}
@Test
void addNestedFile() throws Exception {
File folder = startWithNewFolder();
File file = touch(new File(new File(folder, "sub"), "text.txt"));
File directory = startWithNewDirectory();
File file = touch(new File(new File(directory, "sub"), "text.txt"));
this.watcher.stopAfter(1);
ChangedFiles changedFiles = getSingleChangedFiles();
ChangedFile expected = new ChangedFile(folder, file, Type.ADD);
ChangedFile expected = new ChangedFile(directory, file, Type.ADD);
assertThat(changedFiles.getFiles()).contains(expected);
}
@Test
void createSourceFolderAndAddFile() throws IOException {
File folder = new File(this.tempDir, "does/not/exist");
assertThat(folder.exists()).isFalse();
this.watcher.addSourceFolder(folder);
void createSourceDirectoryAndAddFile() throws IOException {
File directory = new File(this.tempDir, "does/not/exist");
assertThat(directory.exists()).isFalse();
this.watcher.addSourceDirectory(directory);
this.watcher.start();
folder.mkdirs();
File file = touch(new File(folder, "text.txt"));
directory.mkdirs();
File file = touch(new File(directory, "text.txt"));
this.watcher.stopAfter(1);
ChangedFiles changedFiles = getSingleChangedFiles();
ChangedFile expected = new ChangedFile(folder, file, Type.ADD);
ChangedFile expected = new ChangedFile(directory, file, Type.ADD);
assertThat(changedFiles.getFiles()).contains(expected);
}
@Test
void waitsForPollingInterval() throws Exception {
setupWatcher(10, 1);
File folder = startWithNewFolder();
touch(new File(folder, "test1.txt"));
File directory = startWithNewDirectory();
touch(new File(directory, "test1.txt"));
while (this.changes.size() != 1) {
Thread.sleep(10);
}
touch(new File(folder, "test2.txt"));
touch(new File(directory, "test2.txt"));
this.watcher.stopAfter(1);
assertThat(this.changes.size()).isEqualTo(2);
}
@@ -165,9 +165,9 @@ class FileSystemWatcherTests {
@Test
void waitsForQuietPeriod() throws Exception {
setupWatcher(300, 200);
File folder = startWithNewFolder();
File directory = startWithNewDirectory();
for (int i = 0; i < 10; i++) {
touch(new File(folder, i + "test.txt"));
touch(new File(directory, i + "test.txt"));
Thread.sleep(100);
}
this.watcher.stopAfter(1);
@@ -177,39 +177,39 @@ class FileSystemWatcherTests {
@Test
void withExistingFiles() throws Exception {
File folder = new File(this.tempDir, UUID.randomUUID().toString());
folder.mkdir();
touch(new File(folder, "test.txt"));
this.watcher.addSourceFolder(folder);
File directory = new File(this.tempDir, UUID.randomUUID().toString());
directory.mkdir();
touch(new File(directory, "test.txt"));
this.watcher.addSourceDirectory(directory);
this.watcher.start();
File file = touch(new File(folder, "test2.txt"));
File file = touch(new File(directory, "test2.txt"));
this.watcher.stopAfter(1);
ChangedFiles changedFiles = getSingleChangedFiles();
ChangedFile expected = new ChangedFile(folder, file, Type.ADD);
ChangedFile expected = new ChangedFile(directory, file, Type.ADD);
assertThat(changedFiles.getFiles()).contains(expected);
}
@Test
void multipleSources() throws Exception {
File folder1 = new File(this.tempDir, UUID.randomUUID().toString());
folder1.mkdir();
File folder2 = new File(this.tempDir, UUID.randomUUID().toString());
folder2.mkdir();
this.watcher.addSourceFolder(folder1);
this.watcher.addSourceFolder(folder2);
File directory1 = new File(this.tempDir, UUID.randomUUID().toString());
directory1.mkdir();
File directory2 = new File(this.tempDir, UUID.randomUUID().toString());
directory2.mkdir();
this.watcher.addSourceDirectory(directory1);
this.watcher.addSourceDirectory(directory2);
this.watcher.start();
File file1 = touch(new File(folder1, "test.txt"));
File file2 = touch(new File(folder2, "test.txt"));
File file1 = touch(new File(directory1, "test.txt"));
File file2 = touch(new File(directory2, "test.txt"));
this.watcher.stopAfter(1);
Set<ChangedFiles> change = getSingleOnChange();
assertThat(change.size()).isEqualTo(2);
for (ChangedFiles changedFiles : change) {
if (changedFiles.getSourceFolder().equals(folder1)) {
ChangedFile file = new ChangedFile(folder1, file1, Type.ADD);
if (changedFiles.getSourceDirectory().equals(directory1)) {
ChangedFile file = new ChangedFile(directory1, file1, Type.ADD);
assertThat(changedFiles.getFiles()).containsOnly(file);
}
else {
ChangedFile file = new ChangedFile(folder2, file2, Type.ADD);
ChangedFile file = new ChangedFile(directory2, file2, Type.ADD);
assertThat(changedFiles.getFiles()).containsOnly(file);
}
}
@@ -217,48 +217,48 @@ class FileSystemWatcherTests {
@Test
void multipleListeners() throws Exception {
File folder = new File(this.tempDir, UUID.randomUUID().toString());
folder.mkdir();
File directory = new File(this.tempDir, UUID.randomUUID().toString());
directory.mkdir();
final Set<ChangedFiles> listener2Changes = new LinkedHashSet<>();
this.watcher.addSourceFolder(folder);
this.watcher.addSourceDirectory(directory);
this.watcher.addListener(listener2Changes::addAll);
this.watcher.start();
File file = touch(new File(folder, "test.txt"));
File file = touch(new File(directory, "test.txt"));
this.watcher.stopAfter(1);
ChangedFiles changedFiles = getSingleChangedFiles();
ChangedFile expected = new ChangedFile(folder, file, Type.ADD);
ChangedFile expected = new ChangedFile(directory, file, Type.ADD);
assertThat(changedFiles.getFiles()).contains(expected);
assertThat(listener2Changes).isEqualTo(this.changes.get(0));
}
@Test
void modifyDeleteAndAdd() throws Exception {
File folder = new File(this.tempDir, UUID.randomUUID().toString());
folder.mkdir();
File modify = touch(new File(folder, "modify.txt"));
File delete = touch(new File(folder, "delete.txt"));
this.watcher.addSourceFolder(folder);
File directory = new File(this.tempDir, UUID.randomUUID().toString());
directory.mkdir();
File modify = touch(new File(directory, "modify.txt"));
File delete = touch(new File(directory, "delete.txt"));
this.watcher.addSourceDirectory(directory);
this.watcher.start();
FileCopyUtils.copy("abc".getBytes(), modify);
delete.delete();
File add = touch(new File(folder, "add.txt"));
File add = touch(new File(directory, "add.txt"));
this.watcher.stopAfter(1);
ChangedFiles changedFiles = getSingleChangedFiles();
Set<ChangedFile> actual = changedFiles.getFiles();
Set<ChangedFile> expected = new HashSet<>();
expected.add(new ChangedFile(folder, modify, Type.MODIFY));
expected.add(new ChangedFile(folder, delete, Type.DELETE));
expected.add(new ChangedFile(folder, add, Type.ADD));
expected.add(new ChangedFile(directory, modify, Type.MODIFY));
expected.add(new ChangedFile(directory, delete, Type.DELETE));
expected.add(new ChangedFile(directory, add, Type.ADD));
assertThat(actual).isEqualTo(expected);
}
@Test
void withTriggerFilter() throws Exception {
File folder = new File(this.tempDir, UUID.randomUUID().toString());
folder.mkdir();
File file = touch(new File(folder, "file.txt"));
File trigger = touch(new File(folder, "trigger.txt"));
this.watcher.addSourceFolder(folder);
File directory = new File(this.tempDir, UUID.randomUUID().toString());
directory.mkdir();
File file = touch(new File(directory, "file.txt"));
File trigger = touch(new File(directory, "trigger.txt"));
this.watcher.addSourceDirectory(directory);
this.watcher.setTriggerFilter((candidate) -> candidate.getName().equals("trigger.txt"));
this.watcher.start();
FileCopyUtils.copy("abc".getBytes(), file);
@@ -269,7 +269,7 @@ class FileSystemWatcherTests {
ChangedFiles changedFiles = getSingleChangedFiles();
Set<ChangedFile> actual = changedFiles.getFiles();
Set<ChangedFile> expected = new HashSet<>();
expected.add(new ChangedFile(folder, file, Type.MODIFY));
expected.add(new ChangedFile(directory, file, Type.MODIFY));
assertThat(actual).isEqualTo(expected);
}
@@ -278,12 +278,12 @@ class FileSystemWatcherTests {
this.watcher.addListener((changeSet) -> FileSystemWatcherTests.this.changes.add(changeSet));
}
private File startWithNewFolder() throws IOException {
File folder = new File(this.tempDir, UUID.randomUUID().toString());
folder.mkdir();
this.watcher.addSourceFolder(folder);
private File startWithNewDirectory() throws IOException {
File directory = new File(this.tempDir, UUID.randomUUID().toString());
directory.mkdir();
this.watcher.addSourceDirectory(directory);
this.watcher.start();
return folder;
return directory;
}
private ChangedFiles getSingleChangedFiles() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -37,7 +37,7 @@ import org.springframework.boot.devtools.filewatch.ChangedFiles;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceDirectory;
import org.springframework.boot.devtools.test.MockClientHttpRequestFactory;
import org.springframework.http.HttpStatus;
import org.springframework.mock.http.client.MockClientHttpRequest;
@@ -91,33 +91,33 @@ class ClassPathChangeUploaderTests {
}
@Test
void sendsClassLoaderFiles(@TempDir File sourceFolder) throws Exception {
ClassPathChangedEvent event = createClassPathChangedEvent(sourceFolder);
void sendsClassLoaderFiles(@TempDir File sourceDirectory) throws Exception {
ClassPathChangedEvent event = createClassPathChangedEvent(sourceDirectory);
this.requestFactory.willRespond(HttpStatus.OK);
this.uploader.onApplicationEvent(event);
assertThat(this.requestFactory.getExecutedRequests()).hasSize(1);
MockClientHttpRequest request = this.requestFactory.getExecutedRequests().get(0);
verifyUploadRequest(sourceFolder, request);
verifyUploadRequest(sourceDirectory, request);
}
@Test
void retriesOnSocketException(@TempDir File sourceFolder) throws Exception {
ClassPathChangedEvent event = createClassPathChangedEvent(sourceFolder);
void retriesOnSocketException(@TempDir File sourceDirectory) throws Exception {
ClassPathChangedEvent event = createClassPathChangedEvent(sourceDirectory);
this.requestFactory.willRespond(new SocketException());
this.requestFactory.willRespond(HttpStatus.OK);
this.uploader.onApplicationEvent(event);
assertThat(this.requestFactory.getExecutedRequests()).hasSize(2);
verifyUploadRequest(sourceFolder, this.requestFactory.getExecutedRequests().get(1));
verifyUploadRequest(sourceDirectory, this.requestFactory.getExecutedRequests().get(1));
}
private void verifyUploadRequest(File sourceFolder, MockClientHttpRequest request)
private void verifyUploadRequest(File sourceDirectory, MockClientHttpRequest request)
throws IOException, ClassNotFoundException {
ClassLoaderFiles classLoaderFiles = deserialize(request.getBodyAsBytes());
Collection<SourceFolder> sourceFolders = classLoaderFiles.getSourceFolders();
assertThat(sourceFolders.size()).isEqualTo(1);
SourceFolder classSourceFolder = sourceFolders.iterator().next();
assertThat(classSourceFolder.getName()).isEqualTo(sourceFolder.getAbsolutePath());
Iterator<ClassLoaderFile> classFiles = classSourceFolder.getFiles().iterator();
Collection<SourceDirectory> sourceDirectories = classLoaderFiles.getSourceDirectories();
assertThat(sourceDirectories.size()).isEqualTo(1);
SourceDirectory classSourceDirectory = sourceDirectories.iterator().next();
assertThat(classSourceDirectory.getName()).isEqualTo(sourceDirectory.getAbsolutePath());
Iterator<ClassLoaderFile> classFiles = classSourceDirectory.getFiles().iterator();
assertClassFile(classFiles.next(), "File1", ClassLoaderFile.Kind.ADDED);
assertClassFile(classFiles.next(), "File2", ClassLoaderFile.Kind.MODIFIED);
assertClassFile(classFiles.next(), null, ClassLoaderFile.Kind.DELETED);
@@ -129,21 +129,21 @@ class ClassPathChangeUploaderTests {
assertThat(file.getKind()).isEqualTo(kind);
}
private ClassPathChangedEvent createClassPathChangedEvent(File sourceFolder) throws IOException {
private ClassPathChangedEvent createClassPathChangedEvent(File sourceDirectory) throws IOException {
Set<ChangedFile> files = new LinkedHashSet<>();
File file1 = createFile(sourceFolder, "File1");
File file2 = createFile(sourceFolder, "File2");
File file3 = createFile(sourceFolder, "File3");
files.add(new ChangedFile(sourceFolder, file1, Type.ADD));
files.add(new ChangedFile(sourceFolder, file2, Type.MODIFY));
files.add(new ChangedFile(sourceFolder, file3, Type.DELETE));
File file1 = createFile(sourceDirectory, "File1");
File file2 = createFile(sourceDirectory, "File2");
File file3 = createFile(sourceDirectory, "File3");
files.add(new ChangedFile(sourceDirectory, file1, Type.ADD));
files.add(new ChangedFile(sourceDirectory, file2, Type.MODIFY));
files.add(new ChangedFile(sourceDirectory, file3, Type.DELETE));
Set<ChangedFiles> changeSet = new LinkedHashSet<>();
changeSet.add(new ChangedFiles(sourceFolder, files));
changeSet.add(new ChangedFiles(sourceDirectory, files));
return new ClassPathChangedEvent(this, changeSet, false);
}
private File createFile(File sourceFolder, String name) throws IOException {
File file = new File(sourceFolder, name);
private File createFile(File sourceDirectory, String name) throws IOException {
File file = new File(sourceDirectory, name);
FileCopyUtils.copy(name.getBytes(), file);
return file;
}

View File

@@ -46,7 +46,7 @@ class ChangeableUrlsTests {
File tempDir;
@Test
void folderUrl() throws Exception {
void directoryUrl() throws Exception {
URL url = makeUrl("myproject");
assertThat(ChangeableUrls.fromUrls(url).size()).isEqualTo(1);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -83,25 +83,25 @@ class ClassLoaderFilesResourcePatternResolverTests {
}
@Test
void getResourceWhenDeletedShouldReturnDeletedResource(@TempDir File folder) throws Exception {
File file = createFile(folder, "name.class");
this.files.addFile(folder.getName(), "name.class", new ClassLoaderFile(Kind.DELETED, null));
void getResourceWhenDeletedShouldReturnDeletedResource(@TempDir File directory) throws Exception {
File file = createFile(directory, "name.class");
this.files.addFile(directory.getName(), "name.class", new ClassLoaderFile(Kind.DELETED, null));
Resource resource = this.resolver.getResource("file:" + file.getAbsolutePath());
assertThat(resource).isNotNull().isInstanceOf(DeletedClassLoaderFileResource.class);
}
@Test
void getResourcesShouldReturnResources(@TempDir File folder) throws Exception {
createFile(folder, "name.class");
Resource[] resources = this.resolver.getResources("file:" + folder.getAbsolutePath() + "/**");
void getResourcesShouldReturnResources(@TempDir File directory) throws Exception {
createFile(directory, "name.class");
Resource[] resources = this.resolver.getResources("file:" + directory.getAbsolutePath() + "/**");
assertThat(resources).isNotEmpty();
}
@Test
void getResourcesWhenDeletedShouldFilterDeleted(@TempDir File folder) throws Exception {
createFile(folder, "name.class");
this.files.addFile(folder.getName(), "name.class", new ClassLoaderFile(Kind.DELETED, null));
Resource[] resources = this.resolver.getResources("file:" + folder.getAbsolutePath() + "/**");
void getResourcesWhenDeletedShouldFilterDeleted(@TempDir File directory) throws Exception {
createFile(directory, "name.class");
this.files.addFile(directory.getName(), "name.class", new ClassLoaderFile(Kind.DELETED, null));
Resource[] resources = this.resolver.getResources("file:" + directory.getAbsolutePath() + "/**");
assertThat(resources).isEmpty();
}
@@ -179,8 +179,8 @@ class ClassLoaderFilesResourcePatternResolverTests {
return resolver;
}
private File createFile(File folder, String name) throws IOException {
File file = new File(folder, name);
private File createFile(File directory, String name) throws IOException {
File file = new File(directory, name);
FileCopyUtils.copy("test".getBytes(), file);
return file;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,7 +25,7 @@ import java.util.Iterator;
import org.junit.jupiter.api.Test;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFile.Kind;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceFolder;
import org.springframework.boot.devtools.restart.classloader.ClassLoaderFiles.SourceDirectory;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@@ -79,18 +79,18 @@ class ClassLoaderFilesTests {
}
@Test
void addTwiceInDifferentSourceFolders() {
void addTwiceInDifferentSourceDirectories() {
ClassLoaderFile file1 = new ClassLoaderFile(Kind.ADDED, new byte[10]);
ClassLoaderFile file2 = new ClassLoaderFile(Kind.MODIFIED, new byte[10]);
this.files.addFile("a", "myfile", file1);
this.files.addFile("b", "myfile", file2);
assertThat(this.files.getFile("myfile")).isEqualTo(file2);
assertThat(this.files.getOrCreateSourceFolder("a").getFiles().size()).isEqualTo(0);
assertThat(this.files.getOrCreateSourceFolder("b").getFiles().size()).isEqualTo(1);
assertThat(this.files.getOrCreateSourceDirectory("a").getFiles().size()).isEqualTo(0);
assertThat(this.files.getOrCreateSourceDirectory("b").getFiles().size()).isEqualTo(1);
}
@Test
void getSourceFolders() {
void getSourceDirectories() {
ClassLoaderFile file1 = new ClassLoaderFile(Kind.ADDED, new byte[10]);
ClassLoaderFile file2 = new ClassLoaderFile(Kind.MODIFIED, new byte[10]);
ClassLoaderFile file3 = new ClassLoaderFile(Kind.MODIFIED, new byte[10]);
@@ -99,14 +99,14 @@ class ClassLoaderFilesTests {
this.files.addFile("a", "myfile2", file2);
this.files.addFile("b", "myfile3", file3);
this.files.addFile("b", "myfile4", file4);
Iterator<SourceFolder> sourceFolders = this.files.getSourceFolders().iterator();
SourceFolder sourceFolder1 = sourceFolders.next();
SourceFolder sourceFolder2 = sourceFolders.next();
assertThat(sourceFolders.hasNext()).isFalse();
assertThat(sourceFolder1.getName()).isEqualTo("a");
assertThat(sourceFolder2.getName()).isEqualTo("b");
assertThat(sourceFolder1.getFiles()).containsOnly(file1, file2);
assertThat(sourceFolder2.getFiles()).containsOnly(file3, file4);
Iterator<SourceDirectory> sourceDirectories = this.files.getSourceDirectories().iterator();
SourceDirectory sourceDirectory1 = sourceDirectories.next();
SourceDirectory sourceDirectory2 = sourceDirectories.next();
assertThat(sourceDirectories.hasNext()).isFalse();
assertThat(sourceDirectory1.getName()).isEqualTo("a");
assertThat(sourceDirectory2.getName()).isEqualTo("b");
assertThat(sourceDirectory1.getFiles()).containsOnly(file1, file2);
assertThat(sourceDirectory2.getFiles()).containsOnly(file3, file4);
}
@Test
@@ -132,13 +132,13 @@ class ClassLoaderFilesTests {
toAdd.addFile("a", "myfile2", file2);
toAdd.addFile("b", "myfile3", file3);
this.files.addAll(toAdd);
Iterator<SourceFolder> sourceFolders = this.files.getSourceFolders().iterator();
SourceFolder sourceFolder1 = sourceFolders.next();
SourceFolder sourceFolder2 = sourceFolders.next();
assertThat(sourceFolders.hasNext()).isFalse();
assertThat(sourceFolder1.getName()).isEqualTo("a");
assertThat(sourceFolder2.getName()).isEqualTo("b");
assertThat(sourceFolder1.getFiles()).containsOnly(file1, file2);
Iterator<SourceDirectory> sourceDirectoryies = this.files.getSourceDirectories().iterator();
SourceDirectory sourceDirectory1 = sourceDirectoryies.next();
SourceDirectory sourceDirectory2 = sourceDirectoryies.next();
assertThat(sourceDirectoryies.hasNext()).isFalse();
assertThat(sourceDirectory1.getName()).isEqualTo("a");
assertThat(sourceDirectory2.getName()).isEqualTo("b");
assertThat(sourceDirectory1.getFiles()).containsOnly(file1, file2);
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -27,11 +27,11 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link DefaultSourceFolderUrlFilter}.
* Tests for {@link DefaultSourceDirectoryUrlFilter}.
*
* @author Phillip Webb
*/
class DefaultSourceFolderUrlFilterTests {
class DefaultSourceDirectoryUrlFilterTests {
private static final String SOURCE_ROOT = "/Users/me/code/some-root/";
@@ -52,33 +52,33 @@ class DefaultSourceFolderUrlFilterTests {
COMMON_POSTFIXES = Collections.unmodifiableList(postfixes);
}
private DefaultSourceFolderUrlFilter filter = new DefaultSourceFolderUrlFilter();
private DefaultSourceDirectoryUrlFilter filter = new DefaultSourceDirectoryUrlFilter();
@Test
void mavenSourceFolder() throws Exception {
void mavenSourceDirectory() throws Exception {
doTest("my-module/target/classes/");
}
@Test
void gradleEclipseSourceFolder() throws Exception {
void gradleEclipseSourceDirectory() throws Exception {
doTest("my-module/bin/");
}
@Test
void unusualSourceFolder() throws Exception {
void unusualSourceDirectory() throws Exception {
doTest("my-module/something/quite/quite/mad/");
}
@Test
void skippedProjects() throws Exception {
String sourceFolder = "/Users/me/code/spring-boot-samples/spring-boot-sample-devtools";
String sourceDirectory = "/Users/me/code/spring-boot-samples/spring-boot-sample-devtools";
URL jarUrl = new URL("jar:file:/Users/me/tmp/spring-boot-sample-devtools-1.3.0.BUILD-SNAPSHOT.jar!/");
assertThat(this.filter.isMatch(sourceFolder, jarUrl)).isTrue();
assertThat(this.filter.isMatch(sourceDirectory, jarUrl)).isTrue();
URL nestedJarUrl = new URL("jar:file:/Users/me/tmp/spring-boot-sample-devtools-1.3.0.BUILD-SNAPSHOT.jar!/"
+ "lib/spring-boot-1.3.0.BUILD-SNAPSHOT.jar!/");
assertThat(this.filter.isMatch(sourceFolder, nestedJarUrl)).isFalse();
assertThat(this.filter.isMatch(sourceDirectory, nestedJarUrl)).isFalse();
URL fileUrl = new URL("file:/Users/me/tmp/spring-boot-sample-devtools-1.3.0.BUILD-SNAPSHOT.jar");
assertThat(this.filter.isMatch(sourceFolder, fileUrl)).isTrue();
assertThat(this.filter.isMatch(sourceDirectory, fileUrl)).isTrue();
}
private void doTest(String sourcePostfix) throws MalformedURLException {
@@ -89,11 +89,11 @@ class DefaultSourceFolderUrlFilterTests {
}
private void doTest(String sourcePostfix, String moduleRoot, boolean expected) throws MalformedURLException {
String sourceFolder = SOURCE_ROOT + sourcePostfix;
String sourceDirectory = SOURCE_ROOT + sourcePostfix;
for (String postfix : COMMON_POSTFIXES) {
for (URL url : getUrls(moduleRoot + postfix)) {
boolean match = this.filter.isMatch(sourceFolder, url);
assertThat(match).as(url + " against " + sourceFolder).isEqualTo(expected);
boolean match = this.filter.isMatch(sourceDirectory, url);
assertThat(match).as(url + " against " + sourceDirectory).isEqualTo(expected);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -62,9 +62,9 @@ class HttpRestartServerTests {
}
@Test
void sourceFolderUrlFilterMustNotBeNull() {
assertThatIllegalArgumentException().isThrownBy(() -> new HttpRestartServer((SourceFolderUrlFilter) null))
.withMessageContaining("SourceFolderUrlFilter must not be null");
void sourceDirectoryUrlFilterMustNotBeNull() {
assertThatIllegalArgumentException().isThrownBy(() -> new HttpRestartServer((SourceDirectoryUrlFilter) null))
.withMessageContaining("SourceDirectoryUrlFilter must not be null");
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2019 the original author or authors.
* Copyright 2012-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -43,9 +43,9 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
class RestartServerTests {
@Test
void sourceFolderUrlFilterMustNotBeNull() {
assertThatIllegalArgumentException().isThrownBy(() -> new RestartServer((SourceFolderUrlFilter) null))
.withMessageContaining("SourceFolderUrlFilter must not be null");
void sourceDirectoryUrlFilterMustNotBeNull() {
assertThatIllegalArgumentException().isThrownBy(() -> new RestartServer((SourceDirectoryUrlFilter) null))
.withMessageContaining("SourceDirectoryUrlFilter must not be null");
}
@Test
@@ -56,7 +56,7 @@ class RestartServerTests {
URL url4 = new URL("file:/proj/module-d.jar!/");
URLClassLoader classLoaderA = new URLClassLoader(new URL[] { url1, url2 });
URLClassLoader classLoaderB = new URLClassLoader(new URL[] { url3, url4 }, classLoaderA);
SourceFolderUrlFilter filter = new DefaultSourceFolderUrlFilter();
SourceDirectoryUrlFilter filter = new DefaultSourceDirectoryUrlFilter();
MockRestartServer server = new MockRestartServer(filter, classLoaderB);
ClassLoaderFiles files = new ClassLoaderFiles();
ClassLoaderFile fileA = new ClassLoaderFile(Kind.ADDED, new byte[0]);
@@ -70,14 +70,14 @@ class RestartServerTests {
}
@Test
void updateSetsJarLastModified(@TempDir File folder) throws Exception {
void updateSetsJarLastModified(@TempDir File directory) throws Exception {
long startTime = System.currentTimeMillis();
File jarFile = new File(folder, "module-a.jar");
File jarFile = new File(directory, "module-a.jar");
new FileOutputStream(jarFile).close();
jarFile.setLastModified(0);
URL url = jarFile.toURI().toURL();
URLClassLoader classLoader = new URLClassLoader(new URL[] { url });
SourceFolderUrlFilter filter = new DefaultSourceFolderUrlFilter();
SourceDirectoryUrlFilter filter = new DefaultSourceDirectoryUrlFilter();
MockRestartServer server = new MockRestartServer(filter, classLoader);
ClassLoaderFiles files = new ClassLoaderFiles();
ClassLoaderFile fileA = new ClassLoaderFile(Kind.ADDED, new byte[0]);
@@ -87,15 +87,15 @@ class RestartServerTests {
}
@Test
void updateReplacesLocalFilesWhenPossible(@TempDir File folder) throws Exception {
void updateReplacesLocalFilesWhenPossible(@TempDir File directory) throws Exception {
// This is critical for Cloud Foundry support where the application is
// run exploded and resources can be found from the servlet root (outside of the
// classloader)
File classFile = new File(folder, "ClassA.class");
File classFile = new File(directory, "ClassA.class");
FileCopyUtils.copy("abc".getBytes(), classFile);
URL url = folder.toURI().toURL();
URL url = directory.toURI().toURL();
URLClassLoader classLoader = new URLClassLoader(new URL[] { url });
SourceFolderUrlFilter filter = new DefaultSourceFolderUrlFilter();
SourceDirectoryUrlFilter filter = new DefaultSourceDirectoryUrlFilter();
MockRestartServer server = new MockRestartServer(filter, classLoader);
ClassLoaderFiles files = new ClassLoaderFiles();
ClassLoaderFile fileA = new ClassLoaderFile(Kind.ADDED, "def".getBytes());
@@ -106,8 +106,8 @@ class RestartServerTests {
static class MockRestartServer extends RestartServer {
MockRestartServer(SourceFolderUrlFilter sourceFolderUrlFilter, ClassLoader classLoader) {
super(sourceFolderUrlFilter, classLoader);
MockRestartServer(SourceDirectoryUrlFilter sourceDirectoryUrlFilter, ClassLoader classLoader) {
super(sourceDirectoryUrlFilter, classLoader);
}
private Set<URL> restartUrls;