Skip to content

Commit

Permalink
Deprecate asList in favor of asInstanceOf (#3138)
Browse files Browse the repository at this point in the history
  • Loading branch information
scordio committed Sep 15, 2023
1 parent fd20abf commit 55356a5
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -591,12 +591,11 @@ public SELF isNotOfAnyClassIn(Class<?>... types) {
}

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Deprecated
@Override
@CheckReturnValue
public AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>> asList() {
objects.assertIsInstanceOf(info, actual, List.class);
return newListAssertInstance((List<Object>) actual).as(info.description());
return asInstanceOf(InstanceOfAssertFactories.LIST);
}

/** {@inheritDoc} */
Expand Down
2 changes: 2 additions & 0 deletions assertj-core/src/main/java/org/assertj/core/api/Assert.java
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,9 @@ public interface Assert<SELF extends Assert<SELF, ACTUAL>, ACTUAL> extends Descr
* assertThat(unsortedListAsObject).asList().isSorted();</code></pre>
*
* @return a list assertion object
* @deprecated use {@link #asInstanceOf(InstanceOfAssertFactory) asInstanceOf(InstanceOfAssertFactories.LIST)} instead
*/
@Deprecated
AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>> asList();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class SoftProxies {
"asFloat",
"asInstanceOf",
"asInt",
"asList",
"asLong",
"asShort",
"asString",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@

import org.junit.jupiter.api.Test;

/**
* Tests for Assert.asList() methods
*/
@SuppressWarnings("deprecation")
class Assertions_assertThat_asList_Test {

@Test
Expand Down Expand Up @@ -57,4 +55,5 @@ void should_keep_existing_description_set_before_calling_asList() {
// THEN
assertThat(error).hasMessageContaining("oops");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -1608,6 +1608,7 @@ void class_soft_assertions_should_report_errors_on_final_methods() {
}

// the test would fail if any method was not proxyable as the assertion error would not be softly caught
@SuppressWarnings("deprecation")
@Test
void object_soft_assertions_should_report_errors_on_final_methods_and_methods_that_switch_the_object_under_test() {
// GIVEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1954,6 +1954,7 @@ void class_soft_assertions_should_report_errors_on_final_methods() {
}

// the test would fail if any method was not proxyable as the assertion error would not be softly caught
@SuppressWarnings("deprecation")
@Test
void object_soft_assertions_should_report_errors_on_final_methods_and_methods_that_switch_the_object_under_test() {
// GIVEN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ void should_run_test_when_assumption_for_internally_created_string_passes() {
assertThatCode(() -> assumeThat(STRING_OBJECT).isNotNull().asString().startsWith("te")).doesNotThrowAnyException();
}

@SuppressWarnings("deprecation")
@Test
void should_run_test_when_assumption_for_internally_created_list_passes() {
Object listObject = asList(1, 2, 3);
Expand All @@ -52,6 +53,7 @@ void should_ignore_test_when_assumption_for_internally_created_string_assertion_
.isEqualTo("other"));
}

@SuppressWarnings("deprecation")
@Test
void should_ignore_test_when_assumption_for_internally_created_list_assertion_fails() {
Object listObject = asList(1, 2, 3);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ private static void assertThatNoDiff(IterableDiff diff) {
}

// issue #2147
@SuppressWarnings("deprecation")
@Test
void should_work_when_comparison_strategy_is_not_symmetrical() {
// GIVEN
Expand Down

0 comments on commit 55356a5

Please sign in to comment.