[JAVA-26709] Upgraded modelmapper to latest version

This commit is contained in:
panos-kakos 2023-11-11 08:29:09 +02:00
parent 7c1065b494
commit b87609265d
7 changed files with 28 additions and 35 deletions

View File

@ -44,6 +44,6 @@
<properties>
<vavr.version>0.10.3</vavr.version>
<java.version>11</java.version>
<modelmapper.version>3.1.1</modelmapper.version>
<modelmapper.version>3.2.0</modelmapper.version>
</properties>
</project>

View File

@ -1,8 +1,9 @@
package com.baeldung.modelmapper;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.modelmapper.ModelMapper;
import org.modelmapper.TypeMap;
import org.modelmapper.TypeToken;
@ -10,11 +11,10 @@ import org.modelmapper.TypeToken;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasProperty;
import static org.junit.Assert.assertThat;
/**
* This class has test methods of mapping Integer to Character list,
@ -22,12 +22,12 @@ import static org.junit.Assert.assertThat;
*
* @author Sasa Milenkovic
*/
public class UsersListMappingUnitTest {
class UsersListMappingUnitTest {
private ModelMapper modelMapper;
private List<User> users;
@Before
@BeforeEach
public void init() {
modelMapper = new ModelMapper();
@ -35,18 +35,16 @@ public class UsersListMappingUnitTest {
TypeMap<UserList, UserListDTO> typeMap = modelMapper.createTypeMap(UserList.class, UserListDTO.class);
typeMap.addMappings(mapper -> mapper.using(new UsersListConverter())
.map(UserList::getUsers, UserListDTO::setUsernames));
.map(UserList::getUsers, UserListDTO::setUsernames));
users = new ArrayList();
users = new ArrayList<>();
users.add(new User("b100", "user1", "user1@baeldung.com", "111-222", "USER"));
users.add(new User("b101", "user2", "user2@baeldung.com", "111-333", "USER"));
users.add(new User("b102", "user3", "user3@baeldung.com", "111-444", "ADMIN"));
}
@Test
public void whenInteger_thenMapToCharacter() {
void whenInteger_thenMapToCharacter() {
List<Integer> integers = new ArrayList<Integer>();
integers.add(1);
@ -57,36 +55,27 @@ public class UsersListMappingUnitTest {
}.getType());
assertThat(characters, hasItems('1', '2', '3'));
}
@Test
public void givenUsersList_whenUseGenericType_thenMapToUserDTO() {
void givenUsersList_whenUseGenericType_thenMapToUserDTO() {
// Mapping lists using custom (generic) type mapping
List<UserDTO> userDtoList = MapperUtil.mapList(users, UserDTO.class);
assertThat(userDtoList, Matchers.<UserDTO>hasItem(
Matchers.both(hasProperty("userId", equalTo("b100")))
.and(hasProperty("email", equalTo("user1@baeldung.com")))
.and(hasProperty("username", equalTo("user1")))));
assertThat(userDtoList, Matchers.<UserDTO> hasItem(Matchers.both(hasProperty("userId", equalTo("b100")))
.and(hasProperty("email", equalTo("user1@baeldung.com")))
.and(hasProperty("username", equalTo("user1")))));
}
@Test
public void givenUsersList_whenUseConverter_thenMapToUsernames() {
void givenUsersList_whenUseConverter_thenMapToUsernames() {
// Mapping lists using property mapping and converter
UserList userList = new UserList();
userList.setUsers(users);
UserListDTO dtos = new UserListDTO();
modelMapper.map(userList, dtos);
assertThat(dtos.getUsernames(), hasItems("user1", "user2", "user3"));
}
}

View File

@ -108,7 +108,7 @@
<dependency>
<groupId>org.agrona</groupId>
<artifactId>agrona</artifactId>
<version>1.17.1</version>
<version>${agrona.version}</version>
</dependency>
</dependencies>
@ -126,7 +126,7 @@
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<version>${exec-maven-plugin.version}</version>
<executions>
<execution>
<phase>generate-sources</phase>
@ -154,14 +154,14 @@
<dependency>
<groupId>uk.co.real-logic</groupId>
<artifactId>sbe-tool</artifactId>
<version>1.27.0</version>
<version>${sbe-tool.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<version>${build-helper-maven-plugin.version}</version>
<executions>
<execution>
<id>add-source</id>
@ -204,7 +204,11 @@
<rcaller.version>3.0</rcaller.version>
<rserve.version>1.8.1</rserve.version>
<libphonenumber.version>8.12.9</libphonenumber.version>
<org.modelmapper.version>2.4.4</org.modelmapper.version>
<org.modelmapper.version>3.2.0</org.modelmapper.version>
<agrona.version>1.17.1</agrona.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>
<sbe-tool.version>1.27.0</sbe-tool.version>
<build-helper-maven-plugin.version>3.0.0</build-helper-maven-plugin.version>
</properties>
</project>

View File

@ -40,7 +40,7 @@
</dependencies>
<properties>
<modelmapper.version>2.3.7</modelmapper.version>
<modelmapper.version>3.2.0</modelmapper.version>
</properties>
</project>

View File

@ -152,7 +152,7 @@
<orika.version>1.5.4</orika.version>
<dozer.version>6.5.2</dozer.version>
<mapstruct.version>1.5.2.Final</mapstruct.version>
<modelmapper.version>3.1.0</modelmapper.version>
<modelmapper.version>3.2.0</modelmapper.version>
<jmapper.version>1.6.1.CR2</jmapper.version>
<!-- Java source/target to use for compilation. -->
<javac.target>1.8</javac.target>

View File

@ -219,7 +219,7 @@
<graphql-spring-boot-starter.version>5.0.2</graphql-spring-boot-starter.version>
<graphql-java-tools.version>5.2.4</graphql-java-tools.version>
<git-commit-id-plugin.version>2.2.4</git-commit-id-plugin.version>
<modelmapper.version>2.3.2</modelmapper.version>
<modelmapper.version>3.2.0</modelmapper.version>
<problem-spring-web.version>0.23.0</problem-spring-web.version>
<shedlock.version>2.1.0</shedlock.version>
<barbecue.version>1.5-beta1</barbecue.version>

View File

@ -162,7 +162,7 @@
<properties>
<start-class>com.baeldung.SpringBootRestApplication</start-class>
<xstream.version>1.4.11.1</xstream.version>
<modelmapper.version>3.1.0</modelmapper.version>
<modelmapper.version>3.2.0</modelmapper.version>
<rest-assured.version>3.3.0</rest-assured.version>
<jaxb-runtime.version>2.3.7</jaxb-runtime.version>
</properties>