Skip to content

Commit 9807fdb

Browse files
committed
Add test for relativize
1 parent 340a39b commit 9807fdb

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* BSD 2-Clause License
3+
*
4+
* Copyright (c) 2023, Swat.engineering
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice, this
10+
* list of conditions and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
package engineering.swat.watch.impl;
28+
29+
import static org.junit.jupiter.api.Assertions.assertEquals;
30+
31+
import java.io.IOException;
32+
import java.nio.file.Path;
33+
34+
import org.junit.jupiter.api.Test;
35+
36+
import engineering.swat.watch.WatchEvent;
37+
38+
class EventHandlingWatchTests {
39+
40+
private static EventHandlingWatch emptyWatch(Path path) {
41+
return new EventHandlingWatch() {
42+
@Override
43+
public void handleEvent(WatchEvent event) {
44+
// Nothing to handle
45+
}
46+
47+
@Override
48+
public void close() throws IOException {
49+
// Nothing to close
50+
}
51+
52+
@Override
53+
public Path getPath() {
54+
return path;
55+
}
56+
};
57+
}
58+
59+
@Test
60+
void relativizeTest() {
61+
var e1 = new WatchEvent(WatchEvent.Kind.OVERFLOW, Path.of("foo"), Path.of("bar", "baz.txt"));
62+
var e2 = new WatchEvent(WatchEvent.Kind.OVERFLOW, Path.of("foo", "bar", "baz.txt"));
63+
var e3 = emptyWatch(Path.of("foo")).relativize(e2);
64+
assertEquals(e1.getRootPath(), e3.getRootPath());
65+
assertEquals(e1.getRelativePath(), e3.getRelativePath());
66+
}
67+
}

0 commit comments

Comments
 (0)