|
28 | 28 | @ExtendWith(MktmpResolver.class) |
29 | 29 | final class FpDefaultTest { |
30 | 30 |
|
31 | | - @Test |
32 | | - void failsIfSourcePathNotExists() { |
33 | | - Assertions.assertThrows( |
34 | | - IllegalStateException.class, |
35 | | - () -> new FpDefault( |
36 | | - src -> FpDefaultTest.footprintContent(), |
37 | | - Paths.get("/file-doesnt-exist"), |
38 | | - "", |
39 | | - "", |
40 | | - Paths.get("/also-doesnt-exist") |
41 | | - ).apply(Paths.get("/is-absent"), Paths.get("/not-found")), |
42 | | - "FpDefault should fail if source path does not exist" |
43 | | - ); |
44 | | - } |
45 | | - |
46 | | - @Test |
47 | | - void doesNothingWhenTargetIsOlderThanSource(@Mktmp final Path temp) throws Exception { |
48 | | - final Path source = FpDefaultTest.existedSource(temp); |
49 | | - final Path target = FpDefaultTest.existedTarget(temp); |
50 | | - FpDefaultTest.makeOlder(target); |
51 | | - final Path result = new FpDefault( |
52 | | - src -> FpDefaultTest.footprintContent(), |
53 | | - temp, |
54 | | - "1.2.3", |
55 | | - "abcdef", |
56 | | - Paths.get("") |
57 | | - ).apply(source, target); |
58 | | - MatcherAssert.assertThat( |
59 | | - "Footprint has to return target path, but it didn't", |
60 | | - result, |
61 | | - Matchers.equalTo(target) |
62 | | - ); |
63 | | - MatcherAssert.assertThat( |
64 | | - "The content of target file has not to be changed", |
65 | | - new TextOf(target).asString(), |
66 | | - Matchers.equalTo("Target content") |
67 | | - ); |
68 | | - } |
69 | | - |
70 | | - @Test |
71 | | - void updatesOnlyTargetFromSourceIfNoTargetAndCacheIsNotCacheable( |
72 | | - @Mktmp final Path temp |
73 | | - ) throws Exception { |
74 | | - final Path source = FpDefaultTest.existedSource(temp); |
75 | | - final Path target = FpDefaultTest.notExistedTarget(temp); |
76 | | - new FpDefault( |
77 | | - src -> FpDefaultTest.footprintContent(), |
78 | | - temp, |
79 | | - "SNAPSHOT", |
80 | | - "", |
81 | | - Paths.get("cache1.txt") |
82 | | - ).apply(source, target); |
83 | | - MatcherAssert.assertThat( |
84 | | - "Target file must be updated from content function, but it didn't", |
85 | | - new TextOf(target).asString(), |
86 | | - Matchers.equalTo(FpDefaultTest.footprintContent()) |
87 | | - ); |
88 | | - MatcherAssert.assertThat( |
89 | | - "Cache file has not to be updated", |
90 | | - temp.resolve("SNAPSHOT").resolve("cache.txt").toFile().exists(), |
91 | | - Matchers.equalTo(false) |
92 | | - ); |
93 | | - } |
94 | | - |
95 | | - @Test |
96 | | - void updatesOnlyTargetFromSourceIfYoungerTargetAndCacheIsNotCacheable( |
97 | | - @Mktmp final Path temp |
98 | | - ) throws Exception { |
99 | | - final Path source = FpDefaultTest.existedSource(temp); |
100 | | - final Path target = FpDefaultTest.existedTarget(temp); |
101 | | - FpDefaultTest.makeOlder(source); |
102 | | - new FpDefault( |
103 | | - src -> FpDefaultTest.footprintContent(), |
104 | | - temp, |
105 | | - "SNAPSHOT", |
106 | | - "", |
107 | | - Paths.get("cache2.txt") |
108 | | - ).apply(source, target); |
109 | | - MatcherAssert.assertThat( |
110 | | - "Target file must be updated from content function, but it didn't", |
111 | | - new TextOf(target).asString(), |
112 | | - Matchers.equalTo(FpDefaultTest.footprintContent()) |
113 | | - ); |
114 | | - MatcherAssert.assertThat( |
115 | | - "Cache file has not to be updated", |
116 | | - temp.resolve("SNAPSHOT").resolve("cache.txt").toFile().exists(), |
117 | | - Matchers.equalTo(false) |
118 | | - ); |
119 | | - } |
120 | | - |
121 | | - @Test |
122 | | - void updatesBothIfTargetYoungerAndNotExistedCacheableCache( |
123 | | - @Mktmp final Path temp |
124 | | - ) throws Exception { |
125 | | - final Path source = FpDefaultTest.existedSource(temp); |
126 | | - final Path target = FpDefaultTest.existedTarget(temp); |
127 | | - FpDefaultTest.makeOlder(source); |
128 | | - final Cache cache = FpDefaultTest.notExistedCache(temp); |
129 | | - FpDefaultTest.defaultFootprint(cache, source, target); |
130 | | - MatcherAssert.assertThat( |
131 | | - "Target content must be updated from lambda, but it didn't", |
132 | | - new TextOf(target).asString(), |
133 | | - Matchers.equalTo(FpDefaultTest.footprintContent()) |
134 | | - ); |
135 | | - MatcherAssert.assertThat( |
136 | | - "Cache content must be updated from lambda, but it didn't", |
137 | | - new TextOf(cache.path()).asString(), |
138 | | - Matchers.equalTo(FpDefaultTest.footprintContent()) |
139 | | - ); |
140 | | - } |
141 | | - |
142 | | - @Test |
143 | | - void updatesBothNoTargetAndNotExistedCacheableCache(@Mktmp final Path temp) throws Exception { |
144 | | - final Path source = FpDefaultTest.existedSource(temp); |
145 | | - final Path target = FpDefaultTest.notExistedTarget(temp); |
146 | | - final Cache cache = FpDefaultTest.notExistedCache(temp); |
147 | | - FpDefaultTest.defaultFootprint(cache, source, target); |
148 | | - MatcherAssert.assertThat( |
149 | | - "Target content must be updated from lambda, but it didn't", |
150 | | - new TextOf(target).asString(), |
151 | | - Matchers.equalTo(FpDefaultTest.footprintContent()) |
152 | | - ); |
153 | | - MatcherAssert.assertThat( |
154 | | - "Cache content must be updated from lambda, but it didn't", |
155 | | - new TextOf(cache.path()).asString(), |
156 | | - Matchers.equalTo(FpDefaultTest.footprintContent()) |
157 | | - ); |
158 | | - } |
159 | | - |
160 | | - @Test |
161 | | - void updatesBothIfTargetYoungerAndExistedCacheableCacheIsYounger( |
162 | | - @Mktmp final Path temp |
163 | | - ) throws Exception { |
164 | | - final Path source = FpDefaultTest.existedSource(temp); |
165 | | - final Path target = FpDefaultTest.existedTarget(temp); |
166 | | - final Cache cache = FpDefaultTest.existedCache(temp); |
167 | | - FpDefaultTest.makeOlder(source); |
168 | | - FpDefaultTest.defaultFootprint(cache, source, target); |
169 | | - MatcherAssert.assertThat( |
170 | | - "Target content must be updated from lambda, but it didn't", |
171 | | - new TextOf(target).asString(), |
172 | | - Matchers.equalTo(FpDefaultTest.footprintContent()) |
173 | | - ); |
174 | | - MatcherAssert.assertThat( |
175 | | - "Cache content must be updated from lambda, but it didn't", |
176 | | - new TextOf(cache.path()).asString(), |
177 | | - Matchers.equalTo(FpDefaultTest.footprintContent()) |
178 | | - ); |
179 | | - } |
180 | | - |
181 | | - @Test |
182 | | - void updatesBothIfNoTargetAndExistedCacheableCacheIsYounger( |
183 | | - @Mktmp final Path temp |
184 | | - ) throws Exception { |
185 | | - final Path source = FpDefaultTest.existedSource(temp); |
186 | | - final Path target = FpDefaultTest.notExistedTarget(temp); |
187 | | - final Cache cache = FpDefaultTest.existedCache(temp); |
188 | | - FpDefaultTest.makeOlder(source); |
189 | | - FpDefaultTest.defaultFootprint(cache, source, target); |
190 | | - MatcherAssert.assertThat( |
191 | | - "Target content must be updated from lambda, but it didn't", |
192 | | - new TextOf(target).asString(), |
193 | | - Matchers.equalTo(FpDefaultTest.footprintContent()) |
194 | | - ); |
195 | | - MatcherAssert.assertThat( |
196 | | - "Cache content must be updated from lambda, but it didn't", |
197 | | - new TextOf(cache.path()).asString(), |
198 | | - Matchers.equalTo(FpDefaultTest.footprintContent()) |
199 | | - ); |
200 | | - } |
201 | | - |
202 | | - @Test |
203 | | - void copiesFromCacheIfTargetYoungerAndExistedCacheableCacheOlder( |
204 | | - @Mktmp final Path temp |
205 | | - ) throws Exception { |
206 | | - final Path source = FpDefaultTest.existedSource(temp); |
207 | | - final Path target = FpDefaultTest.existedTarget(temp); |
208 | | - final Cache cache = FpDefaultTest.existedCache(temp); |
209 | | - FpDefaultTest.makeOlder(source); |
210 | | - FpDefaultTest.makeOlder(cache.path(), 80_000); |
211 | | - FpDefaultTest.defaultFootprint(cache, source, target); |
212 | | - MatcherAssert.assertThat( |
213 | | - "Target content must be updated from cache, but it didn't", |
214 | | - new TextOf(target).asString(), |
215 | | - Matchers.equalTo(FpDefaultTest.cacheContent()) |
216 | | - ); |
217 | | - MatcherAssert.assertThat( |
218 | | - "Cache content must not be changed, but it did", |
219 | | - new TextOf(cache.path()).asString(), |
220 | | - Matchers.equalTo(FpDefaultTest.cacheContent()) |
221 | | - ); |
222 | | - } |
223 | | - |
224 | 31 | @Test |
225 | 32 | void copiesFromCacheIfNoTaretAndExistedCacheableCacheOlder( |
226 | 33 | @Mktmp final Path temp |
|
0 commit comments