Skip to content

Commit d62f178

Browse files
committed
Test status quo for zero capacity behavior in ConcurrentLruCache
See gh-31317
1 parent 3c59c2a commit d62f178

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

spring-core/src/test/java/org/springframework/util/ConcurrentLruCacheTests.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,13 +21,39 @@
2121
import static org.assertj.core.api.Assertions.assertThat;
2222

2323
/**
24+
* Tests for {@link ConcurrentLruCache}.
25+
*
2426
* @author Juergen Hoeller
27+
* @author Sam Brannen
2528
*/
2629
class ConcurrentLruCacheTests {
2730

2831
private final ConcurrentLruCache<String, String> cache = new ConcurrentLruCache<>(2, key -> key + "value");
2932

3033

34+
@Test
35+
void zeroCapacity() {
36+
ConcurrentLruCache<String, String> cache = new ConcurrentLruCache<>(0, key -> key + "value");
37+
38+
assertThat(cache.sizeLimit()).isZero();
39+
assertThat(cache.size()).isZero();
40+
41+
assertThat(cache.get("k1")).isEqualTo("k1value");
42+
assertThat(cache.size()).isZero();
43+
assertThat(cache.contains("k1")).isFalse();
44+
45+
assertThat(cache.get("k2")).isEqualTo("k2value");
46+
assertThat(cache.size()).isZero();
47+
assertThat(cache.contains("k1")).isFalse();
48+
assertThat(cache.contains("k2")).isFalse();
49+
50+
assertThat(cache.get("k3")).isEqualTo("k3value");
51+
assertThat(cache.size()).isZero();
52+
assertThat(cache.contains("k1")).isFalse();
53+
assertThat(cache.contains("k2")).isFalse();
54+
assertThat(cache.contains("k3")).isFalse();
55+
}
56+
3157
@Test
3258
void getAndSize() {
3359
assertThat(this.cache.sizeLimit()).isEqualTo(2);

0 commit comments

Comments
 (0)