Skip to content

Commit 5335fea

Browse files
committed
Update cache_is_populated_on_lookup test to ignore webjars cached by loading webjars-locator.properties
1 parent b59602d commit 5335fea

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/test/java/org/webjars/WebJarVersionLocatorTest.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.util.Optional;
1010
import java.util.concurrent.ConcurrentHashMap;
11+
import java.util.concurrent.atomic.AtomicBoolean;
1112
import java.util.concurrent.atomic.AtomicInteger;
1213
import java.util.function.Function;
1314

@@ -60,6 +61,7 @@ void full_path_exists_version_supplied() {
6061

6162
@Test
6263
void cache_is_populated_on_lookup() {
64+
AtomicBoolean shouldInspect = new AtomicBoolean(false);
6365
AtomicInteger numLookups = new AtomicInteger(0);
6466

6567
@NullMarked
@@ -69,14 +71,18 @@ class InspectableCache implements WebJarCache {
6971
@Override
7072
public Optional<String> computeIfAbsent(String key, Function<String, Optional<String>> function) {
7173
Function<String, Optional<String>> inspectableFunction = function.andThen((value) -> {
72-
numLookups.incrementAndGet();
74+
if(shouldInspect.get()) {
75+
numLookups.incrementAndGet();
76+
}
7377
return value;
7478
});
7579
return cache.computeIfAbsent(key, inspectableFunction);
7680
}
7781
}
7882

7983
final WebJarVersionLocator webJarVersionLocator = new WebJarVersionLocator(new InspectableCache());
84+
// enable inspection after webJarVersionLocator has been constructed, to ignore lookups caused by loading webjars-locator.properties
85+
shouldInspect.set(true);
8086

8187
assertEquals("3.1.1", webJarVersionLocator.version("bootstrap"));
8288
assertEquals(1, numLookups.get());

0 commit comments

Comments
 (0)