Skip to content

Commit

Permalink
Test status quo for zero capacity behavior in ConcurrentLruCache
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrannen committed Sep 27, 2023
1 parent 3c59c2a commit d62f178
Showing 1 changed file with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -21,13 +21,39 @@
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);
Expand Down

0 comments on commit d62f178

Please sign in to comment.