From 15e6a4e8ff90aa358317f53044b9ff1f384355c3 Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Mon, 5 May 2025 15:43:02 -0700 Subject: [PATCH 1/2] Remove loops in InputValidationTest by using @ParameterizedTest --- .../lib2813/util/InputValidationTest.java | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/core/src/test/java/com/team2813/lib2813/util/InputValidationTest.java b/core/src/test/java/com/team2813/lib2813/util/InputValidationTest.java index 536410b8..d853eb4d 100644 --- a/core/src/test/java/com/team2813/lib2813/util/InputValidationTest.java +++ b/core/src/test/java/com/team2813/lib2813/util/InputValidationTest.java @@ -19,35 +19,40 @@ import static com.google.common.truth.Truth.assertWithMessage; import static org.junit.Assert.assertThrows; +import java.util.stream.IntStream; import org.junit.jupiter.api.Nested; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.ValueSource; +/** Tests for {@link InputValidation}. */ public class InputValidationTest { - // Tests for the `InputValidation.checkCanId(...)` method. + /** Tests for the `InputValidation.checkCanId(...)` method. */ @Nested public class CheckCanIdTest { - @Test - public void invalidCanId() { - // Can IDs can only valid in the range [0, 62]. - int[] invalidCanIds = {-50, -1, 63, 100}; - for (int invalidCanId : invalidCanIds) { - InvalidCanIdException exception = - assertThrows( - InvalidCanIdException.class, () -> InputValidation.checkCanId(invalidCanId)); - assertThat(exception.getCanId()).isEqualTo(invalidCanId); - assertThat(exception).hasMessageThat().contains("is not a valid can id"); - } + @ParameterizedTest + @ValueSource(ints = {-50, -1, 63, 100}) // Can IDs can only valid in the range [0, 62] + public void invalidCanId(int invalidCanId) { + InvalidCanIdException exception = + assertThrows(InvalidCanIdException.class, () -> InputValidation.checkCanId(invalidCanId)); + + assertThat(exception.getCanId()).isEqualTo(invalidCanId); + assertThat(exception).hasMessageThat().contains("is not a valid can id"); } - @Test - public void validCanID() { - // Can IDs can only valid in the range [0, 62]. - int[] validCanIds = {0, 1, 10, 62}; - for (int validCanId : validCanIds) { - int returnValue = InputValidation.checkCanId(validCanId); - assertWithMessage("Expected a valid CAN ID").that(returnValue).isEqualTo(validCanId); - } + @ParameterizedTest + @MethodSource("validCanIds") + public void checkCanId_returnsInputForValidCanId(int validCanId) { + int returnValue = InputValidation.checkCanId(validCanId); + + assertWithMessage("Expected to return the passed-in value") + .that(returnValue) + .isEqualTo(validCanId); + } + + private static IntStream validCanIds() { + return IntStream.range(0, 63); } } } From 187880612ba9103db65d347a7fb6e0fc75141688 Mon Sep 17 00:00:00 2001 From: Kevin Cooney Date: Sat, 7 Mar 2026 18:49:41 -0800 Subject: [PATCH 2/2] Fix warning with use of indentWithSpaces() in spotless.format --- buildSrc/src/main/groovy/java-common-conventions.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/buildSrc/src/main/groovy/java-common-conventions.gradle b/buildSrc/src/main/groovy/java-common-conventions.gradle index 56a308b8..09cf0629 100644 --- a/buildSrc/src/main/groovy/java-common-conventions.gradle +++ b/buildSrc/src/main/groovy/java-common-conventions.gradle @@ -91,7 +91,7 @@ spotless { // define the steps to apply to those files trimTrailingWhitespace() - indentWithSpaces() + leadingTabsToSpaces() endWithNewline() } groovyGradle {