From 52d14bd48711fb0f21d7359211f5f142847c165e Mon Sep 17 00:00:00 2001 From: Andrew Aylett Date: Sat, 31 May 2025 13:32:18 +0100 Subject: [PATCH] Don't apply Checker Framework to tests A big chunk of what we want to test is what happens when we break the invariants -- so we were suppressing a lot of warnings. --- lib/build.gradle.kts | 2 ++ lib/src/test/java/eu/aylett/arc/ArcTest.java | 38 +++++++------------- 2 files changed, 14 insertions(+), 26 deletions(-) diff --git a/lib/build.gradle.kts b/lib/build.gradle.kts index 0973775..c3f6a0e 100644 --- a/lib/build.gradle.kts +++ b/lib/build.gradle.kts @@ -59,6 +59,7 @@ java { testing { suites { // Configure the built-in test suite + @Suppress("unused") val test by getting(JvmTestSuite::class) { // Use JUnit Jupiter test framework @@ -81,6 +82,7 @@ configure { "org.checkerframework.common.initializedfields.InitializedFieldsChecker", "org.checkerframework.checker.lock.LockChecker", ) + excludeTests = true } spotless { diff --git a/lib/src/test/java/eu/aylett/arc/ArcTest.java b/lib/src/test/java/eu/aylett/arc/ArcTest.java index ead3dfc..156910c 100644 --- a/lib/src/test/java/eu/aylett/arc/ArcTest.java +++ b/lib/src/test/java/eu/aylett/arc/ArcTest.java @@ -16,13 +16,7 @@ package eu.aylett.arc; -import org.checkerframework.checker.initialization.qual.Initialized; -import org.checkerframework.checker.lock.qual.GuardedBy; -import org.checkerframework.checker.nullness.qual.NonNull; -import org.checkerframework.checker.nullness.qual.PolyNull; -import org.hamcrest.Matcher; -import org.hamcrest.MatcherAssert; -import org.hamcrest.Matchers; +import org.jspecify.annotations.NonNull; import org.junit.jupiter.api.Test; import java.time.Duration; @@ -46,7 +40,9 @@ import java.util.stream.Collectors; import java.util.stream.IntStream; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.is; @@ -56,17 +52,7 @@ import static java.util.Collections.synchronizedList; import static java.util.concurrent.TimeUnit.SECONDS; -@SuppressWarnings({"argument", "type.argument", "method.guarantee.violated", "type.arguments.not.inferred", "argument", - "methodref.receiver", "dereference.of.nullable"}) class ArcTest { - public static org.hamcrest.Matcher<@GuardedBy @PolyNull @Initialized T> equalTo(@GuardedBy @PolyNull T operand) { - return org.hamcrest.core.IsEqual.equalTo(operand); - } - - public static void assertThat(@GuardedBy @PolyNull T actual, Matcher matcher) { - MatcherAssert.assertThat("", actual, matcher); - } - @Test void test() { var arc = new Arc<>(1, i -> "" + i, ForkJoinPool.commonPool()); @@ -92,14 +78,14 @@ void testEviction() { assertThat(arc.get(1), equalTo("1")); // This should reload "1" as it was evicted // Check that the loader function was called with the expected values - assertThat(recordedValues, equalTo(List.<@GuardedBy Integer>of(1, 2, 1))); + assertThat(recordedValues, equalTo(List.of(1, 2, 1))); arc.checkSafety(); } @Test void testMultipleElements() { - var recordedValues = new ArrayList<@NonNull Integer>(); + var recordedValues = new ArrayList(); var arc = new Arc(4, i -> { recordedValues.add(i); return i.toString(); @@ -111,18 +97,18 @@ void testMultipleElements() { assertThat(arc.get(2), equalTo("2")); // Check that the loader function was called with the expected values - assertThat(recordedValues, equalTo(List.<@GuardedBy Integer>of(1, 2))); + assertThat(recordedValues, equalTo(List.of(1, 2))); } @Test void testLFUElements() { - var recordedValues = synchronizedList(new ArrayList<@NonNull Integer>()); + var recordedValues = synchronizedList(new ArrayList()); var arc = new Arc(5, i -> { recordedValues.add(i); return i.toString(); }, ForkJoinPool.commonPool()); - var expectedValues = new ArrayList<@NonNull Integer>(); + var expectedValues = new ArrayList(); arc.get(1); for (var i = 1; i <= 50; i++) { @@ -130,7 +116,7 @@ void testLFUElements() { expectedValues.add(i); } - // Should not have been eviced, so we won't record it again. + // Should not have been evicted, so we won't record it again. arc.get(1); synchronized (recordedValues) { @@ -254,7 +240,7 @@ void repeatedElementsAreRefreshed() { arc.get(-1); } clock.value.addAndGet(1); - if (i % 1000 == 0) { + if (i % 100 == 0) { arc.checkSafety(); } } @@ -371,14 +357,14 @@ void testLoaderRetriesAfterException() { var ex = assertThrowsExactly(CompletionException.class, () -> arc.get(1)); var cause = ex.getCause(); - assertThat(cause.getMessage(), Matchers.equalTo("Loader failed")); + assertThat(cause.getMessage(), equalTo("Loader failed")); assertThat(arc.get(2), equalTo("2")); assertThat(arc.get(1), equalTo("1")); } @Test - void testConcurrentAccessWithSameKey() throws InterruptedException { + void testConcurrentAccessWithSameKey() { var pool = ForkJoinPool.commonPool(); var arc = new Arc(10, i -> { try {