mirror of
https://github.com/mapstruct/mapstruct.git
synced 2025-07-12 00:00:08 +08:00
Update assertj and used dedicated method in tests (#1204)
This commit is contained in:
parent
70dbdcde0d
commit
f2ad90042c
@ -50,7 +50,7 @@
|
|||||||
<com.puppycrawl.tools.checkstyle.version>7.2</com.puppycrawl.tools.checkstyle.version>
|
<com.puppycrawl.tools.checkstyle.version>7.2</com.puppycrawl.tools.checkstyle.version>
|
||||||
<add.release.arguments />
|
<add.release.arguments />
|
||||||
<forkCount>1</forkCount>
|
<forkCount>1</forkCount>
|
||||||
<assertj.version>3.5.2</assertj.version>
|
<assertj.version>3.7.0</assertj.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<licenses>
|
<licenses>
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.mapstruct.ap.test.nestedbeans;
|
package org.mapstruct.ap.test.nestedbeans;
|
||||||
|
|
||||||
import java.lang.reflect.Field;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
@ -59,50 +57,29 @@ public class NestedSimpleBeansMappingTest {
|
|||||||
UserDtoUpdateMapperSmart.class
|
UserDtoUpdateMapperSmart.class
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Extracts all non synthetic declared fields from a class. This is needed, because jacoco adds a synthetic field
|
|
||||||
* to the classes and also assertj does not support testing that all fields are exactly there.
|
|
||||||
* This will be needed until <a href="https://github.com/joel-costigliola/assertj-core/issues/953">953</a> from
|
|
||||||
* assertj-core is implemented.
|
|
||||||
*
|
|
||||||
* @param clazz to extract from
|
|
||||||
*
|
|
||||||
* @return all the non synthetic declared fields
|
|
||||||
*/
|
|
||||||
private static List<Field> extractAllFields(Class<?> clazz) {
|
|
||||||
List<Field> nonSyntheticFields = new ArrayList<Field>();
|
|
||||||
for ( Field field : clazz.getDeclaredFields() ) {
|
|
||||||
if ( !field.isSynthetic() ) {
|
|
||||||
nonSyntheticFields.add( field );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nonSyntheticFields;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHaveAllFields() throws Exception {
|
public void shouldHaveAllFields() throws Exception {
|
||||||
// If this test fails that means something new was added to the structure of the User/UserDto.
|
// If this test fails that means something new was added to the structure of the User/UserDto.
|
||||||
// Make sure that the other tests are also updated (the new field is asserted)
|
// Make sure that the other tests are also updated (the new field is asserted)
|
||||||
Object[] userFields = new String[] { "name", "car", "secondCar", "house" };
|
String[] userFields = new String[] { "name", "car", "secondCar", "house" };
|
||||||
assertThat( extractAllFields( User.class ) ).extracting( "name" ).containsExactlyInAnyOrder( userFields );
|
assertThat( User.class ).hasOnlyDeclaredFields( userFields );
|
||||||
assertThat( extractAllFields( UserDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( userFields );
|
assertThat( UserDto.class ).hasOnlyDeclaredFields( userFields );
|
||||||
|
|
||||||
Object[] carFields = new String[] { "name", "year", "wheels" };
|
String[] carFields = new String[] { "name", "year", "wheels" };
|
||||||
assertThat( extractAllFields( Car.class ) ).extracting( "name" ).containsExactlyInAnyOrder( carFields );
|
assertThat( Car.class ).hasOnlyDeclaredFields( carFields );
|
||||||
assertThat( extractAllFields( CarDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( carFields );
|
assertThat( CarDto.class ).hasOnlyDeclaredFields( carFields );
|
||||||
|
|
||||||
Object[] wheelFields = new String[] { "front", "right" };
|
String[] wheelFields = new String[] { "front", "right" };
|
||||||
assertThat( extractAllFields( Wheel.class ) ).extracting( "name" ).containsExactlyInAnyOrder( wheelFields );
|
assertThat( Wheel.class ).hasOnlyDeclaredFields( wheelFields );
|
||||||
assertThat( extractAllFields( WheelDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( wheelFields );
|
assertThat( WheelDto.class ).hasOnlyDeclaredFields( wheelFields );
|
||||||
|
|
||||||
Object[] houseFields = new String[] { "name", "year", "roof" };
|
String[] houseFields = new String[] { "name", "year", "roof" };
|
||||||
assertThat( extractAllFields( House.class ) ).extracting( "name" ).containsExactlyInAnyOrder( houseFields );
|
assertThat( House.class ).hasOnlyDeclaredFields( houseFields );
|
||||||
assertThat( extractAllFields( HouseDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( houseFields );
|
assertThat( HouseDto.class ).hasOnlyDeclaredFields( houseFields );
|
||||||
|
|
||||||
Object[] roofFields = new String[] { "color", "type" };
|
String[] roofFields = new String[] { "color", "type" };
|
||||||
assertThat( extractAllFields( Roof.class ) ).extracting( "name" ).containsExactlyInAnyOrder( roofFields );
|
assertThat( Roof.class ).hasOnlyDeclaredFields( roofFields );
|
||||||
assertThat( extractAllFields( RoofDto.class ) ).extracting( "name" ).containsExactlyInAnyOrder( roofFields );
|
assertThat( RoofDto.class ).hasOnlyDeclaredFields( roofFields );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user