21
21
22
22
public class PropertiesWatcherUnitTest {
23
23
24
- private static final String PROPERTIES = "target/test-classes/test-files/fileWatcher.properties" ;
25
- private static final String PROPERTIES2 = "target/test-classes/test-files2/fileWatcher2.properties" ;
24
+ private static final int _1_SEC = 1000 ;
25
+ private static final int _2_SEC = 2000 ;
26
26
27
27
private Resource actual ;
28
28
private CountDownLatch lock = new CountDownLatch (0 );
29
29
30
- final File propertiesFile1 = new File (PROPERTIES );
31
- final Resource [] singleResource = new Resource [] { new FileSystemResource (this .propertiesFile1 ) };
30
+ final File propertiesFile1 = new File ("target/test-classes/test-files/fileWatcher.properties" );
31
+ final File propertiesFile2 = new File ("target/test-classes/test-files/different_fileWatcher.properties" );
32
+ final File propertiesFile3 = new File ("target/test-classes/test-files2/fileWatcher2.properties" );
32
33
33
- final File propertiesFile2 = new File (PROPERTIES2 );
34
- final Resource [] multipleResources = new Resource [] { new FileSystemResource (this .propertiesFile1 ), new FileSystemResource (this .propertiesFile2 ) };
34
+ final Resource [] singleResource = new Resource [] { new FileSystemResource (this .propertiesFile1 ) };
35
+ final Resource [] multiResourceSameDir = new Resource [] { new FileSystemResource (this .propertiesFile1 ), new FileSystemResource (this .propertiesFile2 ) };
36
+ final Resource [] multiResourceDifferentDir = new Resource [] { new FileSystemResource (this .propertiesFile1 ), new FileSystemResource (this .propertiesFile3 ) };
35
37
36
38
@ Test
37
39
public final void testWatchingASingle () throws IOException , InterruptedException {
@@ -41,44 +43,64 @@ public final void testWatchingASingle() throws IOException, InterruptedException
41
43
confirmTestDataNotSet ();
42
44
43
45
startPropertiesWatcher (propertiesWatcher );
44
- wait (1000 );
46
+ wait (_1_SEC );
45
47
46
48
modifyPropertiesFile (this .propertiesFile1 );
47
- wait (2000 );
49
+ wait (_2_SEC );
48
50
confirmPropertiesFileModified (this .propertiesFile1 );
49
51
50
52
propertiesWatcher .stop ();
51
- wait (1000 );
53
+ wait (_2_SEC );
52
54
}
53
55
54
56
@ Test
55
57
public final void testWatchingMulitipleResourcesInDifferingDirectories () throws IOException , InterruptedException {
56
- resetCountDownLatch (this .multipleResources .length );
58
+ resetCountDownLatch (this .multiResourceDifferentDir .length );
57
59
58
- final PropertiesWatcher propertiesWatcher = createPropertiesWatcher (this .multipleResources );
60
+ final PropertiesWatcher propertiesWatcher = createPropertiesWatcher (this .multiResourceDifferentDir );
59
61
confirmTestDataNotSet ();
60
62
61
63
startPropertiesWatcher (propertiesWatcher );
62
- wait (1000 );
64
+ wait (_1_SEC );
63
65
64
- modifyPropertiesFile (this .propertiesFile2 );
65
- wait (2000 );
66
- confirmPropertiesFileModified (this .propertiesFile2 );
66
+ modifyPropertiesFile (this .propertiesFile3 );
67
+ wait (_2_SEC );
68
+ confirmPropertiesFileModified (this .propertiesFile3 );
67
69
68
70
resetTestData ();
69
71
confirmTestDataNotSet ();
70
72
71
73
modifyPropertiesFile (this .propertiesFile1 );
72
- wait (2000 );
74
+ wait (_2_SEC );
73
75
confirmPropertiesFileModified (this .propertiesFile1 );
74
76
75
77
propertiesWatcher .stop ();
76
- wait (1000 );
78
+ wait (_1_SEC );
77
79
}
78
80
79
81
@ Test
80
82
public final void testModifyingADifferentResoruceInSameDirectory () throws IOException , InterruptedException {
83
+ resetCountDownLatch (this .multiResourceSameDir .length );
84
+
85
+ final PropertiesWatcher propertiesWatcher = createPropertiesWatcher (this .multiResourceSameDir );
86
+ confirmTestDataNotSet ();
87
+
88
+ startPropertiesWatcher (propertiesWatcher );
89
+ wait (_1_SEC );
90
+
91
+ modifyPropertiesFile (this .propertiesFile1 );
92
+ wait (_2_SEC );
93
+ confirmPropertiesFileModified (this .propertiesFile1 );
94
+
95
+ resetTestData ();
96
+ confirmTestDataNotSet ();
81
97
98
+ modifyPropertiesFile (this .propertiesFile2 );
99
+ wait (_2_SEC );
100
+ confirmPropertiesFileModified (this .propertiesFile2 );
101
+
102
+ propertiesWatcher .stop ();
103
+ wait (_1_SEC );
82
104
}
83
105
84
106
private void resetCountDownLatch (final int count ) {
0 commit comments