Skip to content

Commit 517c9c6

Browse files
committed
Add navigation method tests to extracting variants
1 parent 9f24545 commit 517c9c6

6 files changed

+56
-37
lines changed

src/test/java/org/assertj/core/api/object/ObjectAssert_extracting_with_Function_Array_Test.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import java.util.List;
2424
import java.util.function.Function;
2525

26+
import org.assertj.core.api.AbstractAssert;
2627
import org.assertj.core.api.AbstractListAssert;
28+
import org.assertj.core.api.NavigationMethodBaseTest;
2729
import org.assertj.core.api.ObjectAssert;
2830
import org.assertj.core.internal.Objects;
2931
import org.assertj.core.test.Employee;
@@ -32,10 +34,7 @@
3234
import org.junit.jupiter.api.BeforeEach;
3335
import org.junit.jupiter.api.Test;
3436

35-
/**
36-
* Tests for <code>{@link ObjectAssert#extracting(Function[])}</code>.
37-
*/
38-
class ObjectAssert_extracting_with_Function_Array_Test {
37+
class ObjectAssert_extracting_with_Function_Array_Test implements NavigationMethodBaseTest<ObjectAssert<Employee>> {
3938

4039
private Employee luke;
4140

@@ -113,4 +112,14 @@ private static Objects comparatorOf(AbstractListAssert<?, ?, ?, ?> assertion) {
113112
return (Objects) PropertyOrFieldSupport.EXTRACTION.getValueOf("objects", assertion);
114113
}
115114

115+
@Override
116+
public ObjectAssert<Employee> getAssertion() {
117+
return new ObjectAssert<>(luke);
118+
}
119+
120+
@Override
121+
public AbstractAssert<?, ?> invoke_navigation_method(ObjectAssert<Employee> assertion) {
122+
return assertion.extracting(Employee::getName, Employee::getAge);
123+
}
124+
116125
}

src/test/java/org/assertj/core/api/object/ObjectAssert_extracting_with_Function_Test.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
import java.util.Map;
2525
import java.util.function.Function;
2626

27+
import org.assertj.core.api.AbstractAssert;
2728
import org.assertj.core.api.AbstractObjectAssert;
29+
import org.assertj.core.api.NavigationMethodBaseTest;
2830
import org.assertj.core.api.ObjectAssert;
2931
import org.assertj.core.internal.Objects;
3032
import org.assertj.core.internal.TypeComparators;
@@ -34,10 +36,7 @@
3436
import org.junit.jupiter.api.BeforeEach;
3537
import org.junit.jupiter.api.Test;
3638

37-
/**
38-
* Tests for <code>{@link ObjectAssert#extracting(Function)}</code>.
39-
*/
40-
class ObjectAssert_extracting_with_Function_Test {
39+
class ObjectAssert_extracting_with_Function_Test implements NavigationMethodBaseTest<ObjectAssert<Employee>> {
4140

4241
private Employee luke;
4342

@@ -90,16 +89,6 @@ void should_throw_a_NullPointerException_if_the_given_extractor_is_null() {
9089
.hasMessage(shouldNotBeNull("extractor").create());
9190
}
9291

93-
@Test
94-
void extracting_should_honor_registered_comparator() {
95-
// GIVEN
96-
ObjectAssert<Employee> assertion = assertThat(luke).usingComparator(ALWAYS_EQUALS);
97-
// WHEN
98-
AbstractObjectAssert<?, String> result = assertion.extracting(firstName);
99-
// THEN
100-
result.isEqualTo("YODA");
101-
}
102-
10392
@Test
10493
void extracting_should_keep_assertion_state() {
10594
// GIVEN
@@ -133,4 +122,15 @@ private static TypeComparators comparatorsByTypeOf(AbstractObjectAssert<?, ?> as
133122
private static Map<String, Comparator<?>> comparatorByPropertyOrFieldOf(AbstractObjectAssert<?, ?> assertion) {
134123
return (Map<String, Comparator<?>>) PropertyOrFieldSupport.EXTRACTION.getValueOf("comparatorByPropertyOrField", assertion);
135124
}
125+
126+
@Override
127+
public ObjectAssert<Employee> getAssertion() {
128+
return new ObjectAssert<>(luke);
129+
}
130+
131+
@Override
132+
public AbstractAssert<?, ?> invoke_navigation_method(ObjectAssert<Employee> assertion) {
133+
return assertion.extracting(Employee::getAge);
134+
}
135+
136136
}

src/test/java/org/assertj/core/api/object/ObjectAssert_extracting_with_Function_and_InstanceOfAssertFactory_Test.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,16 @@
2727
import org.assertj.core.api.AbstractCharSequenceAssert;
2828
import org.assertj.core.api.AbstractIntegerAssert;
2929
import org.assertj.core.api.AbstractStringAssert;
30-
import org.assertj.core.api.InstanceOfAssertFactory;
3130
import org.assertj.core.api.NavigationMethodBaseTest;
3231
import org.assertj.core.api.ObjectAssert;
3332
import org.assertj.core.test.Employee;
3433
import org.assertj.core.test.Name;
3534
import org.junit.jupiter.api.BeforeEach;
36-
import org.junit.jupiter.api.DisplayName;
3735
import org.junit.jupiter.api.Test;
3836

3937
/**
40-
* Tests for <code>{@link ObjectAssert#extracting(Function, InstanceOfAssertFactory)}</code>.
41-
*
4238
* @author Stefano Cordio
4339
*/
44-
@DisplayName("ObjectAssert extracting(Function, InstanceOfAssertFactory)")
4540
class ObjectAssert_extracting_with_Function_and_InstanceOfAssertFactory_Test
4641
implements NavigationMethodBaseTest<ObjectAssert<Employee>> {
4742

@@ -130,7 +125,7 @@ void should_rethrow_any_extractor_function_exception() {
130125

131126
@Override
132127
public ObjectAssert<Employee> getAssertion() {
133-
return assertThat(luke);
128+
return new ObjectAssert<>(luke);
134129
}
135130

136131
@Override

src/test/java/org/assertj/core/api/object/ObjectAssert_extracting_with_String_Array_Test.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@
2020

2121
import java.math.BigDecimal;
2222

23+
import org.assertj.core.api.AbstractAssert;
24+
import org.assertj.core.api.NavigationMethodBaseTest;
2325
import org.assertj.core.api.ObjectAssert;
2426
import org.assertj.core.test.Employee;
2527
import org.assertj.core.test.Name;
2628
import org.assertj.core.util.introspection.IntrospectionError;
2729
import org.junit.jupiter.api.BeforeEach;
28-
import org.junit.jupiter.api.DisplayName;
2930
import org.junit.jupiter.api.Test;
3031

31-
/**
32-
* Tests for <code>{@link ObjectAssert#extracting(String[])}</code>.
33-
*/
34-
@DisplayName("ObjectAssert extracting(String[])")
35-
class ObjectAssert_extracting_with_String_Array_Test {
32+
class ObjectAssert_extracting_with_String_Array_Test implements NavigationMethodBaseTest<ObjectAssert<Employee>> {
3633

3734
private Employee luke;
3835
private Employee leia;
@@ -115,6 +112,16 @@ void should_allow_to_specify_type_comparator_after_using_extracting_with_multipl
115112
.containsExactly("Obi-Wan", new BigDecimal("1.82"));
116113
}
117114

115+
@Override
116+
public ObjectAssert<Employee> getAssertion() {
117+
return new ObjectAssert<>(luke);
118+
}
119+
120+
@Override
121+
public AbstractAssert<?, ?> invoke_navigation_method(ObjectAssert<Employee> assertion) {
122+
return assertion.extracting("id", "name");
123+
}
124+
118125
@SuppressWarnings("unused")
119126
private static class Person {
120127

src/test/java/org/assertj/core/api/object/ObjectAssert_extracting_with_String_Test.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@
2222
import java.util.Comparator;
2323
import java.util.Optional;
2424

25+
import org.assertj.core.api.AbstractAssert;
26+
import org.assertj.core.api.NavigationMethodBaseTest;
27+
import org.assertj.core.api.ObjectAssert;
2528
import org.assertj.core.test.Employee;
2629
import org.assertj.core.test.Name;
2730
import org.assertj.core.util.introspection.IntrospectionError;
2831
import org.junit.jupiter.api.BeforeEach;
2932
import org.junit.jupiter.api.Test;
3033

31-
class ObjectAssert_extracting_with_String_Test {
34+
class ObjectAssert_extracting_with_String_Test implements NavigationMethodBaseTest<ObjectAssert<Employee>> {
3235

3336
private Employee luke;
3437
private Employee leia;
@@ -109,6 +112,16 @@ void should_throw_IntrospectionError_if_given_field_name_cannot_be_read() {
109112
.hasMessageContaining("Can't find any field or property with name 'foo'.");
110113
}
111114

115+
@Override
116+
public ObjectAssert<Employee> getAssertion() {
117+
return new ObjectAssert<>(luke);
118+
}
119+
120+
@Override
121+
public AbstractAssert<?, ?> invoke_navigation_method(ObjectAssert<Employee> assertion) {
122+
return assertion.extracting("name.first");
123+
}
124+
112125
@SuppressWarnings("unused")
113126
private static class Person {
114127

src/test/java/org/assertj/core/api/object/ObjectAssert_extracting_with_String_and_InstanceOfAssertFactory_Test.java

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,22 +29,17 @@
2929
import org.assertj.core.api.AbstractBigDecimalAssert;
3030
import org.assertj.core.api.AbstractLongAssert;
3131
import org.assertj.core.api.AbstractStringAssert;
32-
import org.assertj.core.api.InstanceOfAssertFactory;
3332
import org.assertj.core.api.NavigationMethodBaseTest;
3433
import org.assertj.core.api.ObjectAssert;
3534
import org.assertj.core.test.Employee;
3635
import org.assertj.core.test.Name;
3736
import org.assertj.core.util.introspection.IntrospectionError;
3837
import org.junit.jupiter.api.BeforeEach;
39-
import org.junit.jupiter.api.DisplayName;
4038
import org.junit.jupiter.api.Test;
4139

4240
/**
43-
* Tests for <code>{@link ObjectAssert#extracting(String, InstanceOfAssertFactory)}</code>.
44-
*
4541
* @author Stefano Cordio
4642
*/
47-
@DisplayName("ObjectAssert extracting(String, InstanceOfAssertFactory)")
4843
class ObjectAssert_extracting_with_String_and_InstanceOfAssertFactory_Test
4944
implements NavigationMethodBaseTest<ObjectAssert<Employee>> {
5045

@@ -125,7 +120,7 @@ void should_allow_to_specify_type_comparator_after_using_extracting_with_single_
125120

126121
@Override
127122
public ObjectAssert<Employee> getAssertion() {
128-
return assertThat(luke);
123+
return new ObjectAssert<>(luke);
129124
}
130125

131126
@Override

0 commit comments

Comments
 (0)