Skip to content

Commit

Permalink
Deprecate assertThat/then(Iterable, AssertFactory) and assertThat/the…
Browse files Browse the repository at this point in the history
…n(Iterable, Class)

Fix #3453

(cherry picked from commit fd04639640c9ad048e926693c1614dd9b83df224)
  • Loading branch information
joel-costigliola committed May 12, 2024
1 parent 30230bb commit ad950f0
Show file tree
Hide file tree
Showing 10 changed files with 582 additions and 8 deletions.
80 changes: 80 additions & 0 deletions assertj-core/src/main/java/org/assertj/core/api/Assertions.java
Original file line number Diff line number Diff line change
Expand Up @@ -671,7 +671,27 @@ public static AbstractIntegerAssert<?> assertThat(Integer actual) {
* @param assertFactory the factory used to create the elements assert instance.
* @return the created assertion object.
* @since 2.5.0 / 3.5.0
* @deprecated
* This was added to help creating type-specific assertions for the elements of an {@link Iterable} instance.
* <p>
* Deprecated way:
* <pre><code class='java'> Iterable&lt;String&gt; hobbits = Set.of("frodo", "sam", "Pippin");
* assertThat(hobbits, StringAssert::new).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* However, there is a better way with {@link InstanceOfAssertFactory} and the corresponding
* {@link AbstractIterableAssert#first(InstanceOfAssertFactory) first(InstanceOfAssertFactory)}.
* <p>
* New way:
* <pre><code class='java'> assertThat(hobbits).first(STRING) // static import of InstanceOfAssertFactories.STRING
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* The main advantage of the latter is easier discoverability and the use of InstanceOfAssertFactory which is the
* preferred way to create type-specific assertions in AssertJ API.
*/
@Deprecated
//@format:off
public static <ACTUAL extends Iterable<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
FactoryBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(Iterable<? extends ELEMENT> actual,
Expand Down Expand Up @@ -708,7 +728,27 @@ FactoryBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertTh
* @param assertClass the class used to create the elements assert instance.
* @return the created assertion object.
* @since 2.5.0 / 3.5.0
* @deprecated
* This was added to help creating type-specific assertions for the elements of an {@link Iterable} instance.
* <p>
* Deprecated way:
* <pre><code class='java'> Iterable&lt;String&gt; hobbits = Set.of("frodo", "sam", "Pippin");
* assertThat(hobbits, StringAssert.class).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* However, there is a better way with {@link InstanceOfAssertFactory} and the corresponding
* {@link AbstractIterableAssert#first(InstanceOfAssertFactory) first(InstanceOfAssertFactory)}.
* <p>
* New way:
* <pre><code class='java'> assertThat(hobbits).first(STRING) // static import of InstanceOfAssertFactories.STRING
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* The main advantage of the latter is easier discoverability and the use of InstanceOfAssertFactory which is the
* preferred way to create type-specific assertions in AssertJ API.
*/
@Deprecated
public static <ACTUAL extends Iterable<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
ClassBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(ACTUAL actual,
Class<ELEMENT_ASSERT> assertClass) {
Expand Down Expand Up @@ -752,7 +792,27 @@ ClassBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat
* @param assertFactory the factory used to create the elements assert instance.
* @return the created assertion object.
* @since 2.5.0 / 3.5.0
* @deprecated
* This was added to help creating type-specific assertions for the elements of an {@link List} instance.
* <p>
* Deprecated way:
* <pre><code class='java'> List&lt;String&gt; hobbits = List.of("frodo", "sam", "Pippin");
* assertThat(hobbits, StringAssert::new).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* However, there is a better way with {@link InstanceOfAssertFactory} and the corresponding
* {@link AbstractIterableAssert#first(InstanceOfAssertFactory) first(InstanceOfAssertFactory)}.
* <p>
* New way:
* <pre><code class='java'> assertThat(hobbits).first(STRING) // static import of InstanceOfAssertFactories.STRING
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* The main advantage of the latter is easier discoverability and the use of InstanceOfAssertFactory which is the
* preferred way to create type-specific assertions in AssertJ API.
*/
@Deprecated
public static <ACTUAL extends List<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
FactoryBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(List<? extends ELEMENT> actual,
AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) {
Expand Down Expand Up @@ -788,7 +848,27 @@ FactoryBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(L
* @param assertClass the class used to create the elements assert instance.
* @return the created assertion object.
* @since 2.5.0 / 3.5.0
* @deprecated
* This was added to help creating type-specific assertions for the elements of an {@link List} instance.
* <p>
* Deprecated way:
* <pre><code class='java'> List&lt;String&gt; hobbits = List.of("frodo", "sam", "Pippin");
* assertThat(hobbits, StringAssert.class).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* However, there is a better way with {@link InstanceOfAssertFactory} and the corresponding
* {@link AbstractIterableAssert#first(InstanceOfAssertFactory) first(InstanceOfAssertFactory)}.
* <p>
* New way:
* <pre><code class='java'> assertThat(hobbits).first(STRING) // static import of InstanceOfAssertFactories.STRING
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* The main advantage of the latter is easier discoverability and the use of InstanceOfAssertFactory which is the
* preferred way to create type-specific assertions in AssertJ API.
*/
@Deprecated
public static <ELEMENT, ACTUAL extends List<? extends ELEMENT>, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
ClassBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(List<? extends ELEMENT> actual,
Class<ELEMENT_ASSERT> assertClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,26 +367,111 @@ public static ListAssert<Integer> assertThat(IntStream actual) {
* @param actual the actual value.
* @param assertFactory the factory used to create the elements assert instance.
* @return the created assertion object.
* @deprecated
* This was added to help creating type-specific assertions for the elements of an {@link Iterable} instance.
* <p>
* Deprecated way:
* <pre><code class='java'> Iterable&lt;String&gt; hobbits = Set.of("frodo", "sam", "Pippin");
* assertThat(hobbits, StringAssert::new).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* However, there is a better way with {@link InstanceOfAssertFactory} and the corresponding
* {@link AbstractIterableAssert#first(InstanceOfAssertFactory) first(InstanceOfAssertFactory)}.
* <p>
* New way:
* <pre><code class='java'> assertThat(hobbits).first(STRING) // static import of InstanceOfAssertFactories.STRING
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* The main advantage of the latter is easier discoverability and the use of InstanceOfAssertFactory which is the
* preferred way to create type-specific assertions in AssertJ API.
*/
@Deprecated
//@format:off
public static <ACTUAL extends Iterable<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
FactoryBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(Iterable<? extends ELEMENT> actual,
AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) {
return FactoryBasedNavigableIterableAssert.assertThat(actual, assertFactory);
}

/**
* @deprecated
* This was added to help creating type-specific assertions for the elements of an {@link Iterable} instance.
* <p>
* Deprecated way:
* <pre><code class='java'> Iterable&lt;String&gt; hobbits = Set.of("frodo", "sam", "Pippin");
* assertThat(hobbits, StringAssert.class).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* However, there is a better way with {@link InstanceOfAssertFactory} and the corresponding
* {@link AbstractIterableAssert#first(InstanceOfAssertFactory) first(InstanceOfAssertFactory)}.
* <p>
* New way:
* <pre><code class='java'> assertThat(hobbits).first(STRING) // static import of InstanceOfAssertFactories.STRING
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* The main advantage of the latter is easier discoverability and the use of InstanceOfAssertFactory which is the
* preferred way to create type-specific assertions in AssertJ API.
*/
@Deprecated
public static <ACTUAL extends Iterable<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
ClassBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(ACTUAL actual,
Class<ELEMENT_ASSERT> assertClass) {
return ClassBasedNavigableIterableAssert.assertThat(actual, assertClass);
}

/**
* @deprecated
* This was added to help creating type-specific assertions for the elements of an {@link Iterable} instance.
* <p>
* Deprecated way:
* <pre><code class='java'> List&lt;String&gt; hobbits = List.of("frodo", "sam", "Pippin");
* assertThat(hobbits, StringAssert::new).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* However, there is a better way with {@link InstanceOfAssertFactory} and the corresponding
* {@link AbstractIterableAssert#first(InstanceOfAssertFactory) first(InstanceOfAssertFactory)}.
* <p>
* New way:
* <pre><code class='java'> assertThat(hobbits).first(STRING) // static import of InstanceOfAssertFactories.STRING
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* The main advantage of the latter is easier discoverability and the use of InstanceOfAssertFactory which is the
* preferred way to create type-specific assertions in AssertJ API.
*/
@Deprecated
public static <ACTUAL extends List<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
FactoryBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(List<? extends ELEMENT> actual,
AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) {
return FactoryBasedNavigableListAssert.assertThat(actual, assertFactory);
}

/**
* @deprecated
* This was added to help creating type-specific assertions for the elements of an {@link List} instance.
* <p>
* Deprecated way:
* <pre><code class='java'> List&lt;String&gt; hobbits = List.of("frodo", "sam", "Pippin");
* assertThat(hobbits, StringAssert.class).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* However, there is a better way with {@link InstanceOfAssertFactory} and the corresponding
* {@link AbstractIterableAssert#first(InstanceOfAssertFactory) first(InstanceOfAssertFactory)}.
* <p>
* New way:
* <pre><code class='java'> assertThat(hobbits).first(STRING) // static import of InstanceOfAssertFactories.STRING
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* The main advantage of the latter is easier discoverability and the use of InstanceOfAssertFactory which is the
* preferred way to create type-specific assertions in AssertJ API.
*/
@Deprecated
public static <ELEMENT, ACTUAL extends List<? extends ELEMENT>, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
ClassBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(List<? extends ELEMENT> actual,
Class<ELEMENT_ASSERT> assertClass) {
Expand Down

0 comments on commit ad950f0

Please sign in to comment.