Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
638aa87d
Commit
638aa87d
authored
Apr 09, 2021
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch '2.3.x' into 2.4.x
Closes gh-25982
parents
d7dc3c4c
02e6b7c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
21 additions
and
29 deletions
+21
-29
FileSystemWatcherTests.java
...ework/boot/devtools/filewatch/FileSystemWatcherTests.java
+21
-29
No files found.
spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/filewatch/FileSystemWatcherTests.java
View file @
638aa87d
/*
* Copyright 2012-202
0
the original author or authors.
* Copyright 2012-202
1
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.
...
...
@@ -23,10 +23,10 @@ import java.time.Duration;
import
java.util.ArrayList
;
import
java.util.Collections
;
import
java.util.HashSet
;
import
java.util.LinkedHashSet
;
import
java.util.List
;
import
java.util.Set
;
import
java.util.UUID
;
import
java.util.stream.Collectors
;
import
org.junit.jupiter.api.BeforeEach
;
import
org.junit.jupiter.api.Test
;
...
...
@@ -44,6 +44,7 @@ import static org.mockito.Mockito.mock;
* Tests for {@link FileSystemWatcher}.
*
* @author Phillip Webb
* @author Andy Wilkinson
*/
class
FileSystemWatcherTests
{
...
...
@@ -120,9 +121,8 @@ class FileSystemWatcherTests {
File
directory
=
startWithNewDirectory
();
File
file
=
touch
(
new
File
(
directory
,
"test.txt"
));
this
.
watcher
.
stopAfter
(
1
);
ChangedFiles
changedFiles
=
getSingleChangedFiles
();
ChangedFile
expected
=
new
ChangedFile
(
directory
,
file
,
Type
.
ADD
);
assertThat
(
changedFiles
.
getFiles
()).
contains
(
expected
);
assertThat
(
getAllFileChanges
()).
containsExactly
(
expected
);
}
@Test
...
...
@@ -130,9 +130,8 @@ class FileSystemWatcherTests {
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
(
directory
,
file
,
Type
.
ADD
);
assertThat
(
changedFiles
.
getFiles
()).
contains
(
expected
);
assertThat
(
getAllFileChanges
()).
containsExactly
(
expected
);
}
@Test
...
...
@@ -144,9 +143,8 @@ class FileSystemWatcherTests {
directory
.
mkdirs
();
File
file
=
touch
(
new
File
(
directory
,
"text.txt"
));
this
.
watcher
.
stopAfter
(
1
);
ChangedFiles
changedFiles
=
getSingleChangedFiles
();
ChangedFile
expected
=
new
ChangedFile
(
directory
,
file
,
Type
.
ADD
);
assertThat
(
changedFiles
.
getFiles
()).
contains
(
expected
);
assertThat
(
getAllFileChanges
()).
containsExactly
(
expected
);
}
@Test
...
...
@@ -171,8 +169,7 @@ class FileSystemWatcherTests {
Thread
.
sleep
(
10
);
}
this
.
watcher
.
stopAfter
(
1
);
ChangedFiles
changedFiles
=
getSingleChangedFiles
();
assertThat
(
changedFiles
.
getFiles
()).
hasSize
(
100
);
assertThat
(
getAllFileChanges
()).
hasSize
(
100
);
}
@Test
...
...
@@ -184,9 +181,8 @@ class FileSystemWatcherTests {
this
.
watcher
.
start
();
File
file
=
touch
(
new
File
(
directory
,
"test2.txt"
));
this
.
watcher
.
stopAfter
(
1
);
ChangedFiles
changedFiles
=
getSingleChangedFiles
();
ChangedFile
expected
=
new
ChangedFile
(
directory
,
file
,
Type
.
ADD
);
assertThat
(
changedFiles
.
getFil
es
()).
contains
(
expected
);
assertThat
(
getAllFileChang
es
()).
contains
(
expected
);
}
@Test
...
...
@@ -201,7 +197,7 @@ class FileSystemWatcherTests {
File
file1
=
touch
(
new
File
(
directory1
,
"test.txt"
));
File
file2
=
touch
(
new
File
(
directory2
,
"test.txt"
));
this
.
watcher
.
stopAfter
(
1
);
Set
<
ChangedFiles
>
change
=
getSingleOnChange
(
);
Set
<
ChangedFiles
>
change
=
this
.
changes
.
stream
().
flatMap
(
Set
<
ChangedFiles
>::
stream
).
collect
(
Collectors
.
toSet
()
);
assertThat
(
change
.
size
()).
isEqualTo
(
2
);
for
(
ChangedFiles
changedFiles
:
change
)
{
if
(
changedFiles
.
getSourceDirectory
().
equals
(
directory1
))
{
...
...
@@ -219,16 +215,16 @@ class FileSystemWatcherTests {
void
multipleListeners
()
throws
Exception
{
File
directory
=
new
File
(
this
.
tempDir
,
UUID
.
randomUUID
().
toString
());
directory
.
mkdir
();
final
Set
<
ChangedFiles
>
listener2Changes
=
new
LinkedHashSe
t
<>();
final
List
<
Set
<
ChangedFiles
>>
listener2Changes
=
new
ArrayLis
t
<>();
this
.
watcher
.
addSourceDirectory
(
directory
);
this
.
watcher
.
addListener
(
listener2Changes:
:
add
All
);
this
.
watcher
.
addListener
(
listener2Changes:
:
add
);
this
.
watcher
.
start
();
File
file
=
touch
(
new
File
(
directory
,
"test.txt"
));
this
.
watcher
.
stopAfter
(
1
);
ChangedFiles
changedFiles
=
getSingleChangedFiles
();
ChangedFile
expected
=
new
ChangedFile
(
directory
,
file
,
Type
.
ADD
);
assertThat
(
changedFiles
.
getFiles
()).
contains
(
expected
);
assertThat
(
listener2Changes
).
isEqualTo
(
this
.
changes
.
get
(
0
));
Set
<
ChangedFile
>
changeSet
=
getAllFileChanges
();
assertThat
(
changeSet
).
contains
(
expected
);
assertThat
(
getAllFileChanges
(
listener2Changes
)).
isEqualTo
(
changeSet
);
}
@Test
...
...
@@ -243,8 +239,7 @@ class FileSystemWatcherTests {
delete
.
delete
();
File
add
=
touch
(
new
File
(
directory
,
"add.txt"
));
this
.
watcher
.
stopAfter
(
1
);
ChangedFiles
changedFiles
=
getSingleChangedFiles
();
Set
<
ChangedFile
>
actual
=
changedFiles
.
getFiles
();
Set
<
ChangedFile
>
actual
=
getAllFileChanges
();
Set
<
ChangedFile
>
expected
=
new
HashSet
<>();
expected
.
add
(
new
ChangedFile
(
directory
,
modify
,
Type
.
MODIFY
));
expected
.
add
(
new
ChangedFile
(
directory
,
delete
,
Type
.
DELETE
));
...
...
@@ -266,8 +261,7 @@ class FileSystemWatcherTests {
assertThat
(
this
.
changes
).
isEmpty
();
FileCopyUtils
.
copy
(
"abc"
.
getBytes
(),
trigger
);
this
.
watcher
.
stopAfter
(
1
);
ChangedFiles
changedFiles
=
getSingleChangedFiles
();
Set
<
ChangedFile
>
actual
=
changedFiles
.
getFiles
();
Set
<
ChangedFile
>
actual
=
getAllFileChanges
();
Set
<
ChangedFile
>
expected
=
new
HashSet
<>();
expected
.
add
(
new
ChangedFile
(
directory
,
file
,
Type
.
MODIFY
));
assertThat
(
actual
).
isEqualTo
(
expected
);
...
...
@@ -315,15 +309,13 @@ class FileSystemWatcherTests {
return
directory
;
}
private
ChangedFiles
getSingleChangedFiles
()
{
Set
<
ChangedFiles
>
singleChange
=
getSingleOnChange
();
assertThat
(
singleChange
).
hasSize
(
1
);
return
singleChange
.
iterator
().
next
();
private
Set
<
ChangedFile
>
getAllFileChanges
()
{
return
getAllFileChanges
(
this
.
changes
);
}
private
Set
<
ChangedFile
s
>
getSingleOnChange
(
)
{
assertThat
(
this
.
changes
).
hasSize
(
1
);
return
this
.
changes
.
get
(
0
);
private
Set
<
ChangedFile
>
getAllFileChanges
(
List
<
Set
<
ChangedFiles
>>
changes
)
{
return
changes
.
stream
().
flatMap
(
Set
<
ChangedFiles
>::
stream
)
.
flatMap
((
changedFiles
)
->
changedFiles
.
getFiles
().
stream
()).
collect
(
Collectors
.
toSet
()
);
}
private
File
touch
(
File
file
)
throws
IOException
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment