From f65d39977d20bfc83228458569dea22b555b89c0 Mon Sep 17 00:00:00 2001 From: Nicholas Lativy Date: Sun, 26 Apr 2026 23:05:29 +0100 Subject: [PATCH] Fix two error-prone warnings in tests GuiceberryCompatibilityModuleTest.testWrapperExceptionPropagated swallowed the expected exception in an empty catch block. Replace the try/catch idiom with assertThrows, which both states the intent explicitly and silences the EmptyCatch warning. DependenciesTest.arbitraryOrdering passed `new ServiceA()` twice in an ImmutableSet.of varargs, which DistinctVarargsChecker flags as the kind of thing that's almost always a copy-paste bug. The test just asserts that inOrder() returns every input service for an unrelated set, which two distinct services express equally well. --- .../com/google/acai/DependenciesTest.java | 3 +- .../GuiceberryCompatibilityModuleTest.java | 32 +++++++++---------- 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/src/test/java/com/google/acai/DependenciesTest.java b/src/test/java/com/google/acai/DependenciesTest.java index c26942e..6c44901 100644 --- a/src/test/java/com/google/acai/DependenciesTest.java +++ b/src/test/java/com/google/acai/DependenciesTest.java @@ -38,8 +38,7 @@ private static class ServiceB implements TestingService {} @Test public void arbitraryOrdering() { - Set testingServices = - ImmutableSet.of(new ServiceA(), new ServiceB(), new ServiceA()); + Set testingServices = ImmutableSet.of(new ServiceA(), new ServiceB()); assertThat(Dependencies.inOrder(testingServices)).containsExactlyElementsIn(testingServices); } diff --git a/src/test/java/com/google/acai/GuiceberryCompatibilityModuleTest.java b/src/test/java/com/google/acai/GuiceberryCompatibilityModuleTest.java index 1748ab7..9b99cc4 100644 --- a/src/test/java/com/google/acai/GuiceberryCompatibilityModuleTest.java +++ b/src/test/java/com/google/acai/GuiceberryCompatibilityModuleTest.java @@ -18,6 +18,7 @@ import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertWithMessage; +import static org.junit.Assert.assertThrows; import com.google.guiceberry.GuiceBerryEnvMain; import com.google.guiceberry.GuiceBerryModule; @@ -128,24 +129,23 @@ public void evaluate() { } @Test - public void testWrapperExceptionPropagated() throws Throwable { + public void testWrapperExceptionPropagated() { FakeTestClass test = new FakeTestClass(); - try { - new Acai(ThrowingWrapperModule.class) - .apply( - new Statement() { - @Override - public void evaluate() { - assertWithMessage("Test should not run when TestWrapper throws").fail(); - } - }, - frameworkMethod, - test) - .evaluate(); - assertWithMessage("Exception from TestWrapper should be propagated").fail(); - } catch (TestException expected) { - } + assertThrows( + TestException.class, + () -> + new Acai(ThrowingWrapperModule.class) + .apply( + new Statement() { + @Override + public void evaluate() { + assertWithMessage("Test should not run when TestWrapper throws").fail(); + } + }, + frameworkMethod, + test) + .evaluate()); } private static class FakeTestClass {