Skip to content

Commit

Permalink
upgrade truth assertion library
Browse files Browse the repository at this point in the history
The transition to support Java 8 types directly leads to ambiguous
static imports. These are qualified until the extension can be dropped
when all types are supported (currently only a few were moved).
  • Loading branch information
ben-manes committed Jan 20, 2024
1 parent 8d46e20 commit 30eb66a
Show file tree
Hide file tree
Showing 28 changed files with 63 additions and 57 deletions.
1 change: 1 addition & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
java 11
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package com.github.benmanes.caffeine.cache;

import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static com.google.common.util.concurrent.MoreExecutors.directExecutor;
import static org.junit.Assert.assertThrows;
import static org.mockito.Mockito.verify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import static com.google.common.base.Functions.identity;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static com.google.common.truth.Truth.assertThat;
import static com.google.common.truth.Truth8.assertThat;
import static java.util.Map.entry;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.github.benmanes.caffeine.testing.Int;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.google.common.truth.Truth8;

/**
* The test cases for caches that support the expire-after-read (time-to-idle) policy.
Expand Down Expand Up @@ -358,18 +359,18 @@ public void ageOf(CacheContext context,
expireAfterAccess = Expire.ONE_MINUTE)
public void ageOf_duration(CacheContext context,
@ExpireAfterAccess FixedExpiration<Int, Int> expireAfterAccess) {
assertThat(expireAfterAccess.ageOf(context.firstKey())).hasValue(Duration.ZERO);
Truth8.assertThat(expireAfterAccess.ageOf(context.firstKey())).hasValue(Duration.ZERO);
context.ticker().advance(Duration.ofSeconds(30));
assertThat(expireAfterAccess.ageOf(context.firstKey())).hasValue(Duration.ofSeconds(30));
Truth8.assertThat(expireAfterAccess.ageOf(context.firstKey())).hasValue(Duration.ofSeconds(30));
context.ticker().advance(Duration.ofSeconds(45));
assertThat(expireAfterAccess.ageOf(context.firstKey())).isEmpty();
Truth8.assertThat(expireAfterAccess.ageOf(context.firstKey())).isEmpty();
}

@Test(dataProvider = "caches")
@CacheSpec(expireAfterAccess = Expire.ONE_MINUTE)
public void ageOf_absent(CacheContext context,
@ExpireAfterAccess FixedExpiration<Int, Int> expireAfterAccess) {
assertThat(expireAfterAccess.ageOf(context.absentKey())).isEmpty();
Truth8.assertThat(expireAfterAccess.ageOf(context.absentKey())).isEmpty();
assertThat(expireAfterAccess.ageOf(context.absentKey(), TimeUnit.SECONDS)).isEmpty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
import com.github.benmanes.caffeine.testing.ConcurrentTestHarness;
import com.github.benmanes.caffeine.testing.Int;
import com.google.common.collect.ImmutableList;
import com.google.common.truth.Truth8;

/**
* The test cases for caches that support the variable expiration policy.
Expand Down Expand Up @@ -584,7 +585,7 @@ public void getIfPresentQuietly(Cache<Int, Int> cache, CacheContext context) {
@Test(dataProvider = "caches")
@CacheSpec(population = Population.EMPTY, expiry = CacheExpiry.DISABLED)
public void expireVariably_notEnabled(Cache<Int, Int> cache) {
assertThat(cache.policy().expireVariably()).isEmpty();
Truth8.assertThat(cache.policy().expireVariably()).isEmpty();
}

@Test(dataProvider = "caches")
Expand All @@ -607,14 +608,17 @@ public void getExpiresAfter(Cache<Int, Int> cache,
expiry = CacheExpiry.MOCKITO, expiryTime = Expire.ONE_MINUTE)
public void getExpiresAfter_duration(Cache<Int, Int> cache,
CacheContext context, VarExpiration<Int, Int> expireAfterVar) {
assertThat(expireAfterVar.getExpiresAfter(context.absentKey())).isEmpty();
assertThat(expireAfterVar.getExpiresAfter(context.firstKey())).hasValue(Duration.ofMinutes(1));
Truth8.assertThat(expireAfterVar.getExpiresAfter(context.absentKey())).isEmpty();
Truth8.assertThat(expireAfterVar.getExpiresAfter(
context.firstKey())).hasValue(Duration.ofMinutes(1));

when(context.expiry().expireAfterUpdate(any(), any(), anyLong(), anyLong()))
.thenReturn(TimeUnit.HOURS.toNanos(1));
cache.put(context.firstKey(), context.absentValue());
assertThat(expireAfterVar.getExpiresAfter(context.firstKey())).hasValue(Duration.ofHours(1));
assertThat(expireAfterVar.getExpiresAfter(context.lastKey())).hasValue(Duration.ofMinutes(1));
Truth8.assertThat(expireAfterVar.getExpiresAfter(
context.firstKey())).hasValue(Duration.ofHours(1));
Truth8.assertThat(expireAfterVar.getExpiresAfter(
context.lastKey())).hasValue(Duration.ofMinutes(1));
}

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -679,10 +683,11 @@ public void setExpiresAfter(Cache<Int, Int> cache,
public void setExpiresAfter_duration(Cache<Int, Int> cache,
CacheContext context, VarExpiration<Int, Int> expireAfterVar) {
expireAfterVar.setExpiresAfter(context.firstKey(), Duration.ofMinutes(2));
assertThat(expireAfterVar.getExpiresAfter(context.firstKey())).hasValue(Duration.ofMinutes(2));
Truth8.assertThat(expireAfterVar.getExpiresAfter(context.firstKey()))
.hasValue(Duration.ofMinutes(2));

expireAfterVar.setExpiresAfter(context.absentKey(), Duration.ofMinutes(4));
assertThat(expireAfterVar.getExpiresAfter(context.absentKey())).isEmpty();
Truth8.assertThat(expireAfterVar.getExpiresAfter(context.absentKey())).isEmpty();

context.ticker().advance(Duration.ofSeconds(90));
cache.cleanUp();
Expand Down Expand Up @@ -790,7 +795,7 @@ public void putIfAbsent_insert(Cache<Int, Int> cache,
assertThat(result).isNull();

assertThat(cache).containsEntry(key, value);
assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(Duration.ofMinutes(2));
Truth8.assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(Duration.ofMinutes(2));

context.ticker().advance(Duration.ofSeconds(90));
cache.cleanUp();
Expand All @@ -808,7 +813,7 @@ public void putIfAbsent_present(Cache<Int, Int> cache,
assertThat(result).isEqualTo(context.original().get(key));

assertThat(cache).containsEntry(key, context.original().get(key));
assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(Duration.ofMinutes(1));
Truth8.assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(Duration.ofMinutes(1));

context.ticker().advance(Duration.ofSeconds(90));
cache.cleanUp();
Expand Down Expand Up @@ -891,7 +896,7 @@ public void put_insert(Cache<Int, Int> cache,
assertThat(oldValue).isNull();

assertThat(cache).containsEntry(key, value);
assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(Duration.ofMinutes(2));
Truth8.assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(Duration.ofMinutes(2));

context.ticker().advance(Duration.ofSeconds(90));
cache.cleanUp();
Expand All @@ -909,7 +914,7 @@ public void put_replace(Cache<Int, Int> cache,
assertThat(oldValue).isEqualTo(context.original().get(key));

assertThat(cache).containsEntry(key, value);
assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(Duration.ofMinutes(2));
Truth8.assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(Duration.ofMinutes(2));

context.ticker().advance(Duration.ofSeconds(90));
cache.cleanUp();
Expand Down Expand Up @@ -1054,7 +1059,7 @@ public void compute_absent(Cache<Int, Int> cache,
Int result = expireAfterVar.compute(context.absentKey(),
(key, value) -> context.absentValue(), duration);
verifyNoInteractions(context.expiry());
assertThat(expireAfterVar.getExpiresAfter(context.absentKey())).hasValue(duration);
Truth8.assertThat(expireAfterVar.getExpiresAfter(context.absentKey())).hasValue(duration);

assertThat(result).isEqualTo(context.absentValue());
assertThat(cache).hasSize(1 + context.initialSize());
Expand Down Expand Up @@ -1127,7 +1132,7 @@ public void compute_sameValue(Cache<Int, Int> cache,

replaced.put(key, value);
assertThat(result).isSameInstanceAs(value);
assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(duration);
Truth8.assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(duration);
}
int count = context.firstMiddleLastKeys().size();
assertThat(context).stats().hits(0).misses(0).success(count).failures(0);
Expand All @@ -1151,7 +1156,7 @@ public void compute_sameInstance(Cache<Int, Int> cache,
Int result = expireAfterVar.compute(key, (k, v) -> value, duration);

assertThat(result).isSameInstanceAs(value);
assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(duration);
Truth8.assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(duration);
}
verifyNoInteractions(context.expiry());
int count = context.firstMiddleLastKeys().size();
Expand Down Expand Up @@ -1179,7 +1184,7 @@ public void compute_differentValue(Cache<Int, Int> cache,

replaced.put(key, value);
assertThat(result).isEqualTo(key);
assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(duration);
Truth8.assertThat(expireAfterVar.getExpiresAfter(key)).hasValue(duration);
}
verifyNoInteractions(context.expiry());
int count = context.firstMiddleLastKeys().size();
Expand Down Expand Up @@ -1323,7 +1328,7 @@ public void compute_absent_error(CacheContext context, VarExpiration<Int, Int> e
expireAfterVar.compute(context.firstKey(),
(key, value) -> { throw new IllegalStateException(); }, Duration.ofDays(1));
});
assertThat(expireAfterVar.getExpiresAfter(context.firstKey())).isEmpty();
Truth8.assertThat(expireAfterVar.getExpiresAfter(context.firstKey())).isEmpty();
}

@Test(dataProvider = "caches")
Expand All @@ -1336,7 +1341,7 @@ public void compute_present_error(CacheContext context, VarExpiration<Int, Int>
expireAfterVar.compute(context.firstKey(),
(key, value) -> { throw new IllegalStateException(); }, Duration.ofDays(1));
});
assertThat(variable).isEqualTo(expireAfterVar.getExpiresAfter(context.firstKey()));
Truth8.assertThat(variable).isEqualTo(expireAfterVar.getExpiresAfter(context.firstKey()));
}

@Test(dataProvider = "caches")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import com.github.benmanes.caffeine.testing.Int;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Maps;
import com.google.common.truth.Truth8;

/**
* The test cases for caches that support the expire-after-write (time-to-live) policy.
Expand Down Expand Up @@ -324,14 +325,14 @@ public void ageOf_duration(CacheContext context,
context.ticker().advance(Duration.ofSeconds(30));
assertThat(expireAfterWrite.ageOf(context.firstKey()).orElseThrow().toSeconds()).isEqualTo(30);
context.ticker().advance(Duration.ofSeconds(45));
assertThat(expireAfterWrite.ageOf(context.firstKey())).isEmpty();
Truth8.assertThat(expireAfterWrite.ageOf(context.firstKey())).isEmpty();
}

@Test(dataProvider = "caches")
@CacheSpec(expireAfterWrite = Expire.ONE_MINUTE)
public void ageOf_absent(CacheContext context,
@ExpireAfterWrite FixedExpiration<Int, Int> expireAfterWrite) {
assertThat(expireAfterWrite.ageOf(context.absentKey())).isEmpty();
Truth8.assertThat(expireAfterWrite.ageOf(context.absentKey())).isEmpty();
assertThat(expireAfterWrite.ageOf(context.absentKey(), TimeUnit.SECONDS)).isEmpty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
import com.github.valfirst.slf4jtest.TestLoggerFactory;
import com.google.common.collect.Iterables;
import com.google.common.collect.Maps;
import com.google.common.truth.Truth8;
import com.google.errorprone.annotations.CanIgnoreReturnValue;

/**
Expand Down Expand Up @@ -1005,7 +1006,7 @@ public void ageOf_duration(CacheContext context, FixedRefresh<Int, Int> refreshA
@Test(dataProvider = "caches")
@CacheSpec(refreshAfterWrite = Expire.ONE_MINUTE)
public void ageOf_absent(CacheContext context, FixedRefresh<Int, Int> refreshAfterWrite) {
assertThat(refreshAfterWrite.ageOf(context.absentKey())).isEmpty();
Truth8.assertThat(refreshAfterWrite.ageOf(context.absentKey())).isEmpty();
assertThat(refreshAfterWrite.ageOf(context.absentKey(), TimeUnit.SECONDS)).isEmpty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.github.benmanes.caffeine.cache;

import static com.google.common.truth.Truth8.assertThat;
import static com.google.common.truth.Truth.assertThat;
import static org.slf4j.event.Level.TRACE;

import org.testng.annotations.Listeners;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
caffeine = "3.1.8"
junit = "5.10.1"
reactor = "3.6.2"
truth = "1.2.0"
truth = "1.3.0"
versions = "0.50.0"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-2-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion examples/coalescing-bulkloader-reactor/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("com.gradle.enterprise") version "3.16.1"
id("com.gradle.common-custom-user-data-gradle-plugin") version "1.12.1"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

dependencyResolutionManagement {
Expand Down
2 changes: 1 addition & 1 deletion examples/graal-native/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
caffeine = "3.1.8"
graal = "0.9.28"
junit = "5.10.1"
truth = "1.2.0"
truth = "1.3.0"
versions = "0.50.0"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-2-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion examples/graal-native/settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ pluginManagement {
plugins {
id("com.gradle.enterprise") version "3.16.1"
id("com.gradle.common-custom-user-data-gradle-plugin") version "1.12.1"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

dependencyResolutionManagement {
Expand Down
4 changes: 2 additions & 2 deletions examples/hibernate/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[versions]
caffeine = "3.1.8"
h2 = "2.2.224"
hibernate = "6.4.1.Final"
hibernate = "6.4.2.Final"
junit = "5.10.1"
log4j2 = "3.0.0-beta1"
slf4j = "2.0.7"
truth = "1.2.0"
truth = "1.3.0"
versions = "0.50.0"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-2-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion examples/hibernate/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("com.gradle.enterprise") version "3.16.1"
id("com.gradle.common-custom-user-data-gradle-plugin") version "1.12.1"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

dependencyResolutionManagement {
Expand Down
2 changes: 1 addition & 1 deletion examples/resilience-failsafe/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
caffeine = "3.1.8"
failsafe = "3.3.2"
junit = "5.10.1"
truth = "1.2.0"
truth = "1.3.0"
versions = "0.50.0"

[libraries]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-2-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion examples/resilience-failsafe/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("com.gradle.enterprise") version "3.16.1"
id("com.gradle.common-custom-user-data-gradle-plugin") version "1.12.1"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

dependencyResolutionManagement {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-rc-2-bin.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down
2 changes: 1 addition & 1 deletion examples/write-behind-rxjava/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("com.gradle.enterprise") version "3.16.1"
id("com.gradle.common-custom-user-data-gradle-plugin") version "1.12.1"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

dependencyResolutionManagement {
Expand Down
8 changes: 4 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ commons-text = "1.11.0"
concurrentlinkedhashmap = "1.4.2"
config = "1.4.3"
coveralls = "2.12.2"
dependency-check = "9.0.8"
dependency-check = "9.0.9"
eclipse-collections = "12.0.0.M3"
ehcache3 = "3.10.8"
errorprone-core = "2.24.1"
Expand Down Expand Up @@ -63,9 +63,9 @@ junit4 = "4.13.2"
junit5 = "5.10.1"
kotlin = "1.9.22"
lincheck = "2.18.1"
mockito = "5.8.0"
mockito = "5.9.0"
nexus-publish = "2.0.0-rc-1"
nullaway-core = "0.10.19"
nullaway-core = "0.10.21"
nullaway-plugin = "1.6.0"
okhttp = "4.12.0"
osgi-annotations = "1.5.1"
Expand All @@ -86,7 +86,7 @@ spotbugs-plugin = "6.0.6"
stream = "2.9.8"
tcache = "2.0.1"
testng = "7.9.0"
truth = "1.2.0"
truth = "1.3.0"
univocity-parsers = "2.9.1"
versions = "0.50.0"
xz = "1.9"
Expand Down
2 changes: 1 addition & 1 deletion gradle/plugins/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("com.gradle.enterprise") version "3.16.1"
id("com.gradle.common-custom-user-data-gradle-plugin") version "1.12.1"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0"
}

dependencyResolutionManagement {
Expand Down
Loading

0 comments on commit 30eb66a

Please sign in to comment.