Skip to content

Deprecate assertThat(Iterable, AssertFactory) and assertThat(Iterable, Class) #3453

@scordio

Description

@scordio

Both assertThat(Iterable, AssertFactory) and assertThat(Iterable, Class) have been added in version 3.5.0 to aid the creation of type-specific assertions for the elements of an Iterable instance.

Today, it's possible to write the following:

Iterable<String> hobbits = Set.of("frodo", "sam", "Pippin");

// with AssertFactory
assertThat(hobbits, StringAssert::new).first()
                                      .startsWith("fro")
                                      .endsWith("do");

// with Class
assertThat(hobbits, StringAssert.class).first()
                                       .startsWith("fro")
                                       .endsWith("do");

However, with the introduction of InstanceOfAssertFactory in version 3.13.0 and the corresponding first(InstanceOfAssertFactory) variant in version 3.14.0, the above can be rewritten as:

assertThat(hobbits).first(STRING) // static import of InstanceOfAssertFactories.STRING
                   .startsWith("fro")
                   .endsWith("do");

The main advantage of the latter is easier discoverability therefore we should deprecate the two assertThat entry points.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions