@@ -891,7 +891,7 @@ public AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>> extracting(S
891891 List <Object > values = FieldsOrPropertiesExtractor .extract (actual , byName (propertyOrField ));
892892 String extractedDescription = extractedDescriptionOf (propertyOrField );
893893 String description = mostRelevantDescription (info .description (), extractedDescription );
894- return propagateState ( newListAssertInstanceForMethodsChangingElementType (values ).as (description ) );
894+ return newListAssertInstanceForMethodsChangingElementType (values ).as (description );
895895 }
896896
897897 /**
@@ -939,7 +939,7 @@ public AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>> extractingRe
939939 List <Object > values = FieldsOrPropertiesExtractor .extract (actual , resultOf (method ));
940940 String extractedDescription = extractedDescriptionOfMethod (method );
941941 String description = mostRelevantDescription (info .description (), extractedDescription );
942- return propagateState ( newListAssertInstanceForMethodsChangingElementType (values ).as (description ) );
942+ return newListAssertInstanceForMethodsChangingElementType (values ).as (description );
943943 }
944944
945945 /**
@@ -989,7 +989,7 @@ public <P> AbstractListAssert<?, List<? extends P>, P, ObjectAssert<P>> extracti
989989 List <P > values = (List <P >) FieldsOrPropertiesExtractor .extract (actual , resultOf (method ));
990990 String extractedDescription = extractedDescriptionOfMethod (method );
991991 String description = mostRelevantDescription (info .description (), extractedDescription );
992- return propagateState ( newListAssertInstanceForMethodsChangingElementType (values ).as (description ) );
992+ return newListAssertInstanceForMethodsChangingElementType (values ).as (description );
993993 }
994994
995995 /**
@@ -1079,7 +1079,7 @@ public <P> AbstractListAssert<?, List<? extends P>, P, ObjectAssert<P>> extracti
10791079 List <P > values = (List <P >) FieldsOrPropertiesExtractor .extract (actual , byName (propertyOrField ));
10801080 String extractedDescription = extractedDescriptionOf (propertyOrField );
10811081 String description = mostRelevantDescription (info .description (), extractedDescription );
1082- return propagateState ( newListAssertInstanceForMethodsChangingElementType (values ).as (description ) );
1082+ return newListAssertInstanceForMethodsChangingElementType (values ).as (description );
10831083 }
10841084
10851085 /**
@@ -1171,7 +1171,7 @@ public AbstractListAssert<?, List<? extends Tuple>, Tuple, ObjectAssert<Tuple>>
11711171 List <Tuple > values = FieldsOrPropertiesExtractor .extract (actual , byName (propertiesOrFields ));
11721172 String extractedDescription = extractedDescriptionOf (propertiesOrFields );
11731173 String description = mostRelevantDescription (info .description (), extractedDescription );
1174- return propagateState ( newListAssertInstanceForMethodsChangingElementType (values ).as (description ) );
1174+ return newListAssertInstanceForMethodsChangingElementType (values ).as (description );
11751175 }
11761176
11771177 /**
@@ -1213,7 +1213,7 @@ public <V> AbstractListAssert<?, List<? extends V>, V, ObjectAssert<V>> extracti
12131213 private <V > AbstractListAssert <?, List <? extends V >, V , ObjectAssert <V >> internalExtracting (Function <? super ELEMENT , V > extractor ) {
12141214 if (actual == null ) throwAssertionError (shouldNotBeNull ());
12151215 List <V > values = FieldsOrPropertiesExtractor .extract (actual , extractor );
1216- return propagateState ( newListAssertInstanceForMethodsChangingElementType (values ) );
1216+ return newListAssertInstanceForMethodsChangingElementType (values );
12171217 }
12181218
12191219 /**
@@ -1348,21 +1348,7 @@ private <V> AbstractListAssert<?, List<? extends V>, V, ObjectAssert<V>> newList
13481348 // extracting names we get a List<String> which is mot suitable for the age comparator
13491349 usingDefaultElementComparator ();
13501350 }
1351- return newListAssertInstance (values );
1352- }
1353-
1354- /**
1355- * Called after an extracting/mapping/filtering method creates a new assert and sets its description.
1356- * Propagates the soft assertion collector and assertion state from the parent, with the description
1357- * being the most relevant between the parent's existing description and the new one.
1358- * <p>
1359- * This method must be called AFTER {@code .as(description)} so that {@code withAssertionState}
1360- * overwrites the description with the parent's if the parent had one set.
1361- */
1362- @ SuppressWarnings ("rawtypes" )
1363- private <A extends AbstractAssert > A propagateState (A result ) {
1364- result .withAssertionState (myself );
1365- return result ;
1351+ return newListAssertInstance (values ).withAssertionState (myself );
13661352 }
13671353
13681354 /**
@@ -1514,7 +1500,7 @@ private <V> AbstractListAssert<?, List<? extends V>, V, ObjectAssert<V>> doFlatE
15141500 List <V > result = FieldsOrPropertiesExtractor .extract (actual , extractor ).stream ()
15151501 .flatMap (Collection ::stream )
15161502 .collect (toList ());
1517- return propagateState ( newListAssertInstanceForMethodsChangingElementType (result ) );
1503+ return newListAssertInstanceForMethodsChangingElementType (result );
15181504 }
15191505
15201506 /**
@@ -1588,7 +1574,7 @@ protected AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>> flatExtra
15881574 Stream <? extends ELEMENT > actualStream = stream (actual .spliterator (), false );
15891575 List <Object > result = actualStream .flatMap (element -> Stream .of (extractors ).map (extractor -> extractor .apply (element )))
15901576 .collect (toList ());
1591- return propagateState ( newListAssertInstanceForMethodsChangingElementType (result ) );
1577+ return newListAssertInstanceForMethodsChangingElementType (result );
15921578 }
15931579
15941580 /**
@@ -1723,7 +1709,7 @@ public AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>> flatExtracti
17231709 CommonErrors .wrongElementTypeForFlatExtracting (group );
17241710 }
17251711 }
1726- return propagateState ( newListAssertInstanceForMethodsChangingElementType (extractedValues ) );
1712+ return newListAssertInstanceForMethodsChangingElementType (extractedValues );
17271713 }
17281714
17291715 /**
@@ -1790,7 +1776,7 @@ protected AbstractListAssert<?, List<? extends Tuple>, Tuple, ObjectAssert<Tuple
17901776 .map (extractor -> extractor .apply (objectToExtractValueFrom ))
17911777 .toArray ());
17921778 List <Tuple > tuples = stream (actual .spliterator (), false ).map (tupleExtractor ).collect (toList ());
1793- return propagateState ( newListAssertInstanceForMethodsChangingElementType (tuples ) );
1779+ return newListAssertInstanceForMethodsChangingElementType (tuples );
17941780 }
17951781
17961782 /**
@@ -1875,7 +1861,7 @@ public AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>> flatExtracti
18751861 List <Object > extractedValues = FieldsOrPropertiesExtractor .extract (actual , byName (fieldOrPropertyNames )).stream ()
18761862 .flatMap (tuple -> tuple .toList ().stream ())
18771863 .collect (toList ());
1878- return propagateState ( newListAssertInstanceForMethodsChangingElementType (extractedValues ) );
1864+ return newListAssertInstanceForMethodsChangingElementType (extractedValues );
18791865 }
18801866
18811867 @ Override
@@ -2834,9 +2820,7 @@ public ELEMENT_ASSERT first() {
28342820
28352821 private ELEMENT_ASSERT internalFirst () {
28362822 isNotEmpty ();
2837- ELEMENT_ASSERT result = toAssert (actual .iterator ().next (), navigationDescription ("check first element" ));
2838- result .withAssertionState (myself );
2839- return result ;
2823+ return toAssert (actual .iterator ().next (), navigationDescription ("check first element" ));
28402824 }
28412825
28422826 /**
@@ -2900,9 +2884,7 @@ public ELEMENT_ASSERT last() {
29002884
29012885 private ELEMENT_ASSERT internalLast () {
29022886 isNotEmpty ();
2903- ELEMENT_ASSERT result = toAssert (lastElement (), navigationDescription ("check last element" ));
2904- result .withAssertionState (myself );
2905- return result ;
2887+ return toAssert (lastElement (), navigationDescription ("check last element" ));
29062888 }
29072889
29082890 @ SuppressWarnings ("unchecked" )
@@ -3055,9 +3037,7 @@ private ELEMENT_ASSERT internalElement(int index) {
30553037 elementAtIndex = actualIterator .next ();
30563038 }
30573039
3058- ELEMENT_ASSERT result = toAssert (elementAtIndex , navigationDescription ("element at index " + index ));
3059- result .withAssertionState (myself );
3060- return result ;
3040+ return toAssert (elementAtIndex , navigationDescription ("element at index " + index ));
30613041 }
30623042
30633043 /**
@@ -3143,9 +3123,7 @@ public ELEMENT_ASSERT singleElement() {
31433123
31443124 private ELEMENT_ASSERT internalSingleElement () {
31453125 iterables .assertHasSize (info , actual , 1 );
3146- ELEMENT_ASSERT result = toAssert (actual .iterator ().next (), navigationDescription ("check single element" ));
3147- result .withAssertionState (myself );
3148- return result ;
3126+ return toAssert (actual .iterator ().next (), navigationDescription ("check single element" ));
31493127 }
31503128
31513129 /**
@@ -3159,7 +3137,12 @@ private ELEMENT_ASSERT internalSingleElement() {
31593137 * @param description describes the element, ex: "check first element" for {@link #first()}, used in assertion description.
31603138 * @return the assertion for the given element
31613139 */
3162- protected abstract ELEMENT_ASSERT toAssert (ELEMENT value , String description );
3140+ @ SuppressWarnings ("unchecked" )
3141+ protected ELEMENT_ASSERT toAssert (ELEMENT value , String description ) {
3142+ return toAssert (value ).withAssertionState (myself ).as (description );
3143+ }
3144+
3145+ protected abstract ELEMENT_ASSERT toAssert (ELEMENT value );
31633146
31643147 protected String navigationDescription (String propertyName ) {
31653148 String text = descriptionText ();
@@ -3657,10 +3640,9 @@ private FactoryBasedAssert(ACTUAL actual, AssertFactory<ELEMENT, ELEMENT_ASSERT>
36573640 this .assertFactory = assertFactory ;
36583641 }
36593642
3660- @ SuppressWarnings ("unchecked" )
36613643 @ Override
3662- protected ELEMENT_ASSERT toAssert (ELEMENT value , String description ) {
3663- return assertFactory .createAssert (value ). as ( description ) ;
3644+ protected ELEMENT_ASSERT toAssert (ELEMENT value ) {
3645+ return assertFactory .createAssert (value );
36643646 }
36653647
36663648 @ SuppressWarnings ("unchecked" )
0 commit comments