Skip to content

Commit

Permalink
Update cache_is_populated_on_lookup test to ignore webjars cached by …
Browse files Browse the repository at this point in the history
…loading webjars-locator.properties
  • Loading branch information
dodgex committed Oct 19, 2024
1 parent b59602d commit 5335fea
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/test/java/org/webjars/WebJarVersionLocatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.util.Optional;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;

Expand Down Expand Up @@ -60,6 +61,7 @@ void full_path_exists_version_supplied() {

@Test
void cache_is_populated_on_lookup() {
AtomicBoolean shouldInspect = new AtomicBoolean(false);
AtomicInteger numLookups = new AtomicInteger(0);

@NullMarked
Expand All @@ -69,14 +71,18 @@ class InspectableCache implements WebJarCache {
@Override
public Optional<String> computeIfAbsent(String key, Function<String, Optional<String>> function) {
Function<String, Optional<String>> inspectableFunction = function.andThen((value) -> {
numLookups.incrementAndGet();
if(shouldInspect.get()) {
numLookups.incrementAndGet();
}
return value;
});
return cache.computeIfAbsent(key, inspectableFunction);
}
}

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

assertEquals("3.1.1", webJarVersionLocator.version("bootstrap"));
assertEquals(1, numLookups.get());
Expand Down

0 comments on commit 5335fea

Please sign in to comment.