
Unit Test Utility Methods
Add thorough JUnit tests for small Java utility methods with boundary, null, and precision edge cases.
Overview
Unit Test Utility Methods is an agent skill for the Ship phase that guides JUnit unit tests for Java utility functions with boundary, null, and precision edge cases.
Install
npx skills add https://github.com/giuseppe-trisciuoglio/developer-kit --skill unit-test-utility-methodsWhat is this skill?
- JUnit patterns for numeric boundaries: Integer.MAX_VALUE, MIN_VALUE, BigDecimal, float precision
- String edge cases: null, empty, single char, Unicode (über), whitespace-only
- Collection edge cases section started in skill body (catalog excerpt)
- AssertJ-style assertions: isNull, isEmpty, isCloseTo with tolerance
- Named should* test methods for readable utility-method specs
- catalog excerpt shows 5+ string edge-case tests and 4+ numeric boundary tests
Adoption & trust: 1.2k installs on skills.sh; 271 GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your agent-generated MathUtils or StringUtils look fine in demos but you have no systematic tests for nulls, integer limits, or floating-point drift.
Who is it for?
Indie JVM developers hardening small pure functions before merge or release.
Skip if: End-to-end browser testing, infrastructure probes, or non-Java stacks—scope is Java unit tests for utilities.
When should I use this skill?
User is writing or reviewing JUnit tests for Java utility/helper methods and needs boundary, null, or precision cases (inferred from skill content).
What do I get? / Deliverables
You get copy-ready JUnit test classes with AssertJ assertions covering numeric, string, and collection boundary patterns for utility methods.
- Edge-case JUnit test class snippets for numeric and string utilities
- Boundary-condition checklist applied to new helpers
Recommended Skills
Journey fit
How it compares
Use for focused utility-method edge-case templates, not as a full CI or mutation-testing framework.
Common Questions / FAQ
Who is unit-test-utility-methods for?
Solo builders and small teams writing Java backend or library code who want disciplined edge-case coverage on helper methods.
When should I use unit-test-utility-methods?
In the Ship testing subphase when adding or reviewing JUnit coverage for string, math, and collection utilities before you tag a release or open a PR.
Is unit-test-utility-methods safe to install?
It is documentation and test patterns only; review the Security Audits panel on this Prism page before installing any catalog skill.
SKILL.md
READMESKILL.md - Unit Test Utility Methods
# Edge Cases and Boundary Testing ## Numeric Boundary Conditions ```java class MathUtilsEdgeCasesTest { @Test void shouldHandleMaxInteger() { assertThat(MathUtils.increment(Integer.MAX_VALUE)).isEqualTo(Integer.MAX_VALUE); } @Test void shouldHandleMinInteger() { assertThat(MathUtils.decrement(Integer.MIN_VALUE)).isEqualTo(Integer.MIN_VALUE); } @Test void shouldHandleLargeNumbers() { BigDecimal result = MathUtils.add( new BigDecimal("999999999999.99"), new BigDecimal("0.01") ); assertThat(result).isEqualTo(new BigDecimal("1000000000000.00")); } @Test void shouldHandleFloatingPointPrecision() { assertThat(MathUtils.multiply(0.1, 0.2)) .isCloseTo(0.02, within(0.0001)); } } ``` ## String Edge Cases ```java class StringUtilsEdgeCasesTest { @Test void shouldHandleNullInput() { assertThat(StringUtils.capitalize(null)).isNull(); } @Test void shouldHandleEmptyString() { assertThat(StringUtils.capitalize("")).isEmpty(); } @Test void shouldHandleSingleCharacter() { assertThat(StringUtils.capitalize("a")).isEqualTo("A"); } @Test void shouldHandleUnicodeCharacters() { assertThat(StringUtils.capitalize("über")).isEqualTo("Über"); } @Test void shouldHandleOnlyWhitespace() { assertThat(StringUtils.trim(" ")).isEmpty(); } } ``` ## Collection Edge Cases ```java class CollectionUtilsEdgeCasesTest { @Test void shouldReturnEmptyForNullInput() { assertThat(CollectionUtils.filter(null, n -> true)).isEmpty(); } @Test void shouldReturnEmptyForNoMatches() { List<Integer> numbers = List.of(1, 3, 5); assertThat(CollectionUtils.filter(numbers, n -> n % 2 == 0)).isEmpty(); } @Test void shouldHandleEmptyCollection() { assertThat(CollectionUtils.join(List.of(), "-")).isEmpty(); } @Test void shouldHandleSingleElement() { assertThat(CollectionUtils.join(List.of("a"), "-")).isEqualTo("a"); } } ``` ## Validation Edge Cases ```java class ValidatorUtilsEdgeCasesTest { @Test void shouldRejectEmptyEmail() { assertThat(ValidatorUtils.isValidEmail("")).isFalse(); } @Test void shouldRejectNullEmail() { assertThat(ValidatorUtils.isValidEmail(null)).isFalse(); } @Test void shouldHandleLongStrings() { String longString = "a".repeat(10000); assertThat(StringUtils.truncate(longString, 100)).hasSize(100); } @Test void shouldHandleSpecialCharactersInUrls() { assertThat(ValidatorUtils.isValidUrl("https://example.com/path?query=value")) .isTrue(); } } ``` ## Floating Point Precision Rules | Operation | Use | Example | |-----------|-----|---------| | Addition | `isCloseTo(delta)` | `isCloseTo(0.3, within(0.001))` | | Comparison | `isEqualTo()` | Use `BigDecimal` for exact decimals | | Percentage | Tolerance-based | `isCloseTo(expected, within(0.01))` | # Parameterized Tests for Utility Methods Use `@ParameterizedTest` for testing multiple similar inputs efficiently. ## ValueSource - Single Parameter ```java @ParameterizedTest @ValueSource(strings = {"", " ", "null", " \t "}) void shouldConsiderFalsyValuesAsEmpty(String input) { assertThat(StringUtils.isEmpty(input)).isTrue(); } ``` ## CsvSource - Multiple Parameters ```java @ParameterizedTest @CsvSource({ "hello, HELLO", "world, WORLD", "test, TEST", "123abc, 123ABC" }) void shouldConvertToUpperCase(String input, String expected) { assertThat(StringUtils.toUpperCase(input)).isEqualTo(expected); } ``` ## CsvSource - Email Validation ```java @ParameterizedTest @CsvSource({ "user@example.com, true", "test@domain.org, true", "invalid-email, false", '", false', "no-at-sign.com, false" }) void shouldValidateEmailsCorrectly(String email, boo