Skip to content

New annotations and type-safe accessors #7

@ignaciotcrespo

Description

@ignaciotcrespo

Feature requests

1. @WithNullParam

Like @WithBooleanParams but injects null alongside a provided value. Useful for null-safety testing.

@Test
@WithNullParam("hello")
public void handlesNull() {
    String value = params.get(); // runs twice: "hello", then null
}

2. @WithEnumParams(MyEnum.class)

Auto-iterate all enum values without listing them as strings.

@Test
@WithEnumParams(Color.class)
public void testAllColors() {
    Color color = params.asEnum(Color.class);
}

3. @WithParamsSource("methodName")

Like JUnit 5's @MethodSource — reference a method that returns parameter sets. Avoids huge annotation arrays.

@Test
@WithParamsSource("provideNumbers")
public void sum() {
    int n1 = params.asInt("n1");
    int n2 = params.asInt("n2");
    assertEquals(params.asInt("result"), calculator.sum(n1, n2));
}

static String[][] provideNumbers() {
    return new String[][] { {"1", "2", "3"}, {"11", "-2", "9"} };
}

4. asEnum(MyEnum.class) accessor

Type-safe enum accessor to complement asInt(), asFloat(), etc.

Color color = params.asEnum(Color.class);
Color color = params.asEnum("colorParam", Color.class);

Requirements

Each feature must include comprehensive unit tests covering all possible combinations:

  • Happy path (single and named parameters)
  • Error/edge cases (invalid values, missing parameters, wrong types)
  • Integration tests using @Rule with the full annotation lifecycle (similar to WithBooleanParamsTest)
  • Accessor tests with and without named parameters, including exception cases (similar to existing patterns in WithParamsRuleTest)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions