8
8
9
9
import java .util .Optional ;
10
10
import java .util .concurrent .ConcurrentHashMap ;
11
+ import java .util .concurrent .atomic .AtomicBoolean ;
11
12
import java .util .concurrent .atomic .AtomicInteger ;
12
13
import java .util .function .Function ;
13
14
@@ -60,6 +61,7 @@ void full_path_exists_version_supplied() {
60
61
61
62
@ Test
62
63
void cache_is_populated_on_lookup () {
64
+ AtomicBoolean shouldInspect = new AtomicBoolean (false );
63
65
AtomicInteger numLookups = new AtomicInteger (0 );
64
66
65
67
@ NullMarked
@@ -69,14 +71,18 @@ class InspectableCache implements WebJarCache {
69
71
@ Override
70
72
public Optional <String > computeIfAbsent (String key , Function <String , Optional <String >> function ) {
71
73
Function <String , Optional <String >> inspectableFunction = function .andThen ((value ) -> {
72
- numLookups .incrementAndGet ();
74
+ if (shouldInspect .get ()) {
75
+ numLookups .incrementAndGet ();
76
+ }
73
77
return value ;
74
78
});
75
79
return cache .computeIfAbsent (key , inspectableFunction );
76
80
}
77
81
}
78
82
79
83
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 );
80
86
81
87
assertEquals ("3.1.1" , webJarVersionLocator .version ("bootstrap" ));
82
88
assertEquals (1 , numLookups .get ());
0 commit comments