Test status quo for zero capacity behavior in ConcurrentLruCache

See gh-31317
This commit is contained in:
Sam Brannen
2023-09-27 12:56:30 +02:00
parent 3c59c2a275
commit d62f17864c

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,13 +21,39 @@ import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link ConcurrentLruCache}.
*
* @author Juergen Hoeller
* @author Sam Brannen
*/
class ConcurrentLruCacheTests {
private final ConcurrentLruCache<String, String> cache = new ConcurrentLruCache<>(2, key -> key + "value");
@Test
void zeroCapacity() {
ConcurrentLruCache<String, String> cache = new ConcurrentLruCache<>(0, key -> key + "value");
assertThat(cache.sizeLimit()).isZero();
assertThat(cache.size()).isZero();
assertThat(cache.get("k1")).isEqualTo("k1value");
assertThat(cache.size()).isZero();
assertThat(cache.contains("k1")).isFalse();
assertThat(cache.get("k2")).isEqualTo("k2value");
assertThat(cache.size()).isZero();
assertThat(cache.contains("k1")).isFalse();
assertThat(cache.contains("k2")).isFalse();
assertThat(cache.get("k3")).isEqualTo("k3value");
assertThat(cache.size()).isZero();
assertThat(cache.contains("k1")).isFalse();
assertThat(cache.contains("k2")).isFalse();
assertThat(cache.contains("k3")).isFalse();
}
@Test
void getAndSize() {
assertThat(this.cache.sizeLimit()).isEqualTo(2);