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.
Both
assertThat(Iterable, AssertFactory)andassertThat(Iterable, Class)have been added in version 3.5.0 to aid the creation of type-specific assertions for the elements of anIterableinstance.Today, it's possible to write the following:
However, with the introduction of
InstanceOfAssertFactoryin version 3.13.0 and the correspondingfirst(InstanceOfAssertFactory)variant in version 3.14.0, the above can be rewritten as:The main advantage of the latter is easier discoverability therefore we should deprecate the two
assertThatentry points.