|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2023 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
21 | 21 | import static org.assertj.core.api.Assertions.assertThat;
|
22 | 22 |
|
23 | 23 | /**
|
| 24 | + * Tests for {@link ConcurrentLruCache}. |
| 25 | + * |
24 | 26 | * @author Juergen Hoeller
|
| 27 | + * @author Sam Brannen |
25 | 28 | */
|
26 | 29 | class ConcurrentLruCacheTests {
|
27 | 30 |
|
28 | 31 | private final ConcurrentLruCache<String, String> cache = new ConcurrentLruCache<>(2, key -> key + "value");
|
29 | 32 |
|
30 | 33 |
|
| 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 | + |
31 | 57 | @Test
|
32 | 58 | void getAndSize() {
|
33 | 59 | assertThat(this.cache.sizeLimit()).isEqualTo(2);
|
|
0 commit comments