[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
@@ -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>
@@ -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"));
}
}