Skip to content

Support range filter in @EnumSource #4185

@bjmi

Description

@bjmi

Sometimes it is necessary to test a consecutive range of enum constants in a unit test. The existing matchers of @EnumSource can't help here.
As Enum constants have a natural order, it would be useful to support a range in @EnumSource. If a bound is not specified, it is considered unbounded.

Following example would work then: all constants of ChronoUnit starting at WEEKS aren't supported by Instant.plus(..).

class InstantTests {

@EnumSource(from = "WEEKS")
@ParameterizedTest
void plus_unsupportedUnits(ChronoUnit unit) {
    Instant now = Instant.now();
    assertThrows(UnsupportedTemporalTypeException.class, () -> now.plus(1, unit));
}
...

Candidates are

  • @EnumSource(from = "..", to = ".."),
  • @EnumSource(begin = "..", end = "..") or
  • @EnumSource(start = "..", end = "..")
  • ...

The existing matchers could be applied to a specified range additionally.

Deliverables

  • @EnumSource with optional from and to attributes
  • Update documentation and release notes

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions