SKILL.md--- name: unit-test-boundary-conditions description: Provides edge case, corner case, boundary condition, and limit testing patterns for Java unit tests. Validates minimum/maximum values, null cases, empty collections, numeric overflow/underflow, floating-point precision, and off-by-one scenarios using JUnit 5 and AssertJ. Use when writing .java test files to ensure code handles limits, corner cases, and special inputs correctly. allowed-tools: Read, Write, Bash, Glob, Grep --- # Unit Testing Boundary Conditions and Edge Cases ## Overview Systematic patterns for testing boundary conditions, corner cases, and limit values in Java using JUnit 5. Covers numeric boundaries, string edge cases, collection states, floating-point precision, date/time limits, and off-by-one scenarios. ## When to Use - Numeric min/max limits, null/empty/whitespace inputs - Overflow/underflow validation, collection boundaries - Off-by-one errors, floating-point precision ## Instructions 1. **Identify boundaries**: List numeric limits (MIN_VALUE, MAX_VALUE, zero), string states (null, empty, whitespace), collection sizes (0, 1, many) 2. **Apply parameterized tests**: Use `@ParameterizedTest` with `@ValueSource` or `@CsvSource` for multiple boundary values 3. **Test both sides of boundaries**: Cover values just below, at, and just above each boundary 4. **Run tests after adding each boundary category** to catch issues early 5. **Verify floating-point precision**: Use `isCloseTo(expected, within(tolerance))` with AssertJ 6. **Test collection states**: Explicitly test empty (0), single (1), and many (>1) element scenarios 7. **Handle overflow/underflow**: Use `Math.addExact()` and `Math.subtractExact()` to detect arithmetic overflow 8. **Test date/time edges**: Verify leap years, month boundaries, timezone transitions 9. **Iterate based on failures**: When a boundary test fails, analyze the error to discover additional untested boundaries; add test cases for the newly discovered edge conditions ## Examples Requires: `junit-jupiter`, `junit-jupiter-params`, `assertj-core`. ## Integer Boundary Testing ```java import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import static org.assertj.core.api.Assertions.*; class IntegerBoundaryTest { @ParameterizedTest @ValueSource(ints = {Integer.MIN_VALUE, Integer.MIN_VALUE + 1, 0, Integer.MAX_VALUE - 1, Integer.MAX_VALUE}) void shouldHandleIntegerBoundaries(int value) { assertThat(value).isNotNull(); } @Test void shouldDetectIntegerOverflow() { assertThatThrownBy(() -> Math.addExact(Integer.MAX_VALUE, 1)) .isInstanceOf(ArithmeticException.class); } @Test void shouldDetectIntegerUnderflow() { assertThatThrownBy(() -> Math.subtractExact(Integer.MIN_VALUE, 1)) .isInstanceOf(ArithmeticException.class); } @Test void shouldHandleZeroEdge() { int result = MathUtils.divide(0, 5); assertThat(result).