Download data/plugin/src/test/java/copilotj/awt/ParameterSchemaValidateTest.java from introvoyz045/CopilotJ: direct link, hf CLI and curl.
- Browser
- Download file 5.4 kB
-
https://huggingface.co/datasets/introvoyz045/CopilotJ/resolve/main/data/plugin/src/test/java/copilotj/awt/ParameterSchemaValidateTest.java
- Command line
-
hf download hf://datasets/introvoyz045/CopilotJ/data/plugin/src/test/java/copilotj/awt/ParameterSchemaValidateTest.java
-
curl -L -o ParameterSchemaValidateTest.java https://huggingface.co/datasets/introvoyz045/CopilotJ/resolve/main/data/plugin/src/test/java/copilotj/awt/ParameterSchemaValidateTest.java
5.4 kB
| /** | |
| * SPDX-FileCopyrightText: Copyright contributors to the CopilotJ project. | |
| * | |
| * SPDX-License-Identifier: Apache-2.0 | |
| */ | |
| package copilotj.awt; | |
| import static org.junit.jupiter.api.Assertions.assertEquals; | |
| import static org.junit.jupiter.api.Assertions.assertFalse; | |
| import static org.junit.jupiter.api.Assertions.assertNotNull; | |
| import static org.junit.jupiter.api.Assertions.assertNull; | |
| import static org.junit.jupiter.api.Assertions.assertTrue; | |
| import java.util.Arrays; | |
| import java.util.List; | |
| import org.junit.jupiter.api.Test; | |
| /** | |
| * Tests for {@link Action.ParameterSchema#validate(Object)} across all four | |
| * subclasses. Contract: a valid value returns {@code null}; an invalid value | |
| * returns a non-empty error list (never an empty list). | |
| */ | |
| public class ParameterSchemaValidateTest { | |
| private static void assertInvalid(final List<String> errors, final String containsFragment) { | |
| assertNotNull(errors, "invalid value must return a non-null error list"); | |
| assertFalse(errors.isEmpty(), "invalid value must return a non-empty error list"); | |
| if (containsFragment != null) { | |
| assertTrue( | |
| errors.stream().anyMatch(e -> e.contains(containsFragment)), | |
| "expected an error containing \"" + containsFragment + "\", got " + errors); | |
| } | |
| } | |
| // ===== String ===== | |
| public void stringValidReturnsNull() { | |
| assertNull(new Action.StringParameterSchema("p", "d", null, null, null, null).validate("ok")); | |
| } | |
| public void stringNullReturnsTypeError() { | |
| assertInvalid(new Action.StringParameterSchema("p", "d", null, null, null, null).validate(null), "cannot be null"); | |
| } | |
| public void stringWrongTypeReportsSimpleClassName() { | |
| final List<String> errors = | |
| new Action.StringParameterSchema("p", "d", null, null, null, null).validate(Integer.valueOf(5)); | |
| assertInvalid(errors, "got Integer"); | |
| assertEquals(1, errors.size(), "type mismatch returns early with a single error"); | |
| } | |
| public void stringTooShort() { | |
| assertInvalid(new Action.StringParameterSchema("p", "d", 3, null, null, null).validate("ab"), "less than minimum"); | |
| } | |
| public void stringTooLong() { | |
| assertInvalid(new Action.StringParameterSchema("p", "d", null, 3, null, null).validate("abcd"), "greater than maximum"); | |
| } | |
| public void stringPatternMismatch() { | |
| assertInvalid(new Action.StringParameterSchema("p", "d", null, null, "[0-9]+", null).validate("abc"), | |
| "does not match pattern"); | |
| } | |
| public void stringNotInEnum() { | |
| assertInvalid(new Action.StringParameterSchema("p", "d", null, null, null, Arrays.asList("a", "b")).validate("c"), | |
| "not in the allowed enum"); | |
| } | |
| public void stringEnumBoundaryValid() { | |
| assertNull(new Action.StringParameterSchema("p", "d", null, null, null, Arrays.asList("a", "b")).validate("a")); | |
| } | |
| // ===== Integer ===== | |
| public void integerValidReturnsNull() { | |
| assertNull(new Action.IntegerParameterSchema("p", "d", null, null).validate(Integer.valueOf(3))); | |
| } | |
| public void integerNullReturnsTypeError() { | |
| assertInvalid(new Action.IntegerParameterSchema("p", "d", null, null).validate(null), "cannot be null"); | |
| } | |
| public void integerRejectsLong() { | |
| // Only java.lang.Integer is accepted; a Long reports a type error. | |
| final List<String> errors = | |
| new Action.IntegerParameterSchema("p", "d", null, null).validate(Long.valueOf(3L)); | |
| assertInvalid(errors, "got Long"); | |
| } | |
| public void integerBelowMinimum() { | |
| assertInvalid(new Action.IntegerParameterSchema("p", "d", 0, null).validate(Integer.valueOf(-1)), "less than minimum"); | |
| } | |
| public void integerAboveMaximum() { | |
| assertInvalid(new Action.IntegerParameterSchema("p", "d", null, 10).validate(Integer.valueOf(11)), "greater than maximum"); | |
| } | |
| // ===== Number ===== | |
| public void numberAcceptsInteger() { | |
| assertNull(new Action.NumberParameterSchema("p", "d", null, null).validate(Integer.valueOf(3))); | |
| } | |
| public void numberAcceptsDouble() { | |
| assertNull(new Action.NumberParameterSchema("p", "d", null, null).validate(Double.valueOf(3.5))); | |
| } | |
| public void numberNullReturnsTypeError() { | |
| assertInvalid(new Action.NumberParameterSchema("p", "d", null, null).validate(null), "cannot be null"); | |
| } | |
| public void numberBelowMinimum() { | |
| assertInvalid(new Action.NumberParameterSchema("p", "d", 0.0, null).validate(Double.valueOf(-1.0)), "less than minimum"); | |
| } | |
| public void numberAboveMaximum() { | |
| assertInvalid(new Action.NumberParameterSchema("p", "d", null, 1.0).validate(Double.valueOf(2.5)), "greater than maximum"); | |
| } | |
| // ===== Boolean (regression: valid -> null, NOT an empty list) ===== | |
| public void booleanValidTrueReturnsNull() { | |
| assertNull(new Action.BooleanParameterSchema("p", "d").validate(Boolean.TRUE)); | |
| } | |
| public void booleanValidFalseReturnsNull() { | |
| assertNull(new Action.BooleanParameterSchema("p", "d").validate(Boolean.FALSE)); | |
| } | |
| public void booleanNullReturnsTypeError() { | |
| assertInvalid(new Action.BooleanParameterSchema("p", "d").validate(null), "cannot be null"); | |
| } | |
| public void booleanWrongTypeReportsSimpleClassName() { | |
| assertInvalid(new Action.BooleanParameterSchema("p", "d").validate("yes"), "got String"); | |
| } | |
| } | |