Renaming test methods and formatting

This commit is contained in:
Sasa M 2020-04-21 21:29:38 +02:00
parent b9cbfa49c4
commit 4bc8c329fc
2 changed files with 1 additions and 87 deletions

View File

@ -7,10 +7,9 @@ import java.util.ArrayList;
import java.util.List;
/**
* @author sasam0320
* @description
* UserPropertyMap class instantiates the converter to map the data from the user list to the user name list.
* In the configuration method, we call a converter to do the mapping.
* @author sasam0320
*/
public class UserPropertyMap extends PropertyMap<UserList, UserListDTO> {

View File

@ -1,85 +0,0 @@
package com.baeldung.modelmapper;
import org.hamcrest.Matchers;
import org.junit.Before;
import org.junit.Test;
import org.modelmapper.ModelMapper;
import org.modelmapper.TypeToken;
import java.util.ArrayList;
import java.util.List;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasItems;
import static org.hamcrest.Matchers.hasProperty;
import static org.hamcrest.collection.IsCollectionWithSize.hasSize;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
/**
* @sasam0320
* @description
* This class has test methods of mapping Integer to Character list,
* mapping user list to DTO list using MapperUtil generic methods and Converter
*/
public class UserMappingTest {
private ModelMapper mapper;
private List<User> users;
@Before
public void init() {
mapper = new ModelMapper();
mapper.addMappings(new UserPropertyMap());
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 testMapIntegerList() {
List<Integer> integers = new ArrayList<Integer>();
integers.add(1);
integers.add(2);
integers.add(3);
List<Character> characters = mapper.map(integers, new TypeToken<List<Character>>() {
}.getType());
assertThat(characters, hasItems('1','2','3'));
}
@Test
public void testMapGenericTypeLists() {
// Mapping lists using generic type methods
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")))));
// Mapping lists using PropertyMap and Converter
UserList userList = new UserList();
userList.setUsers(users);
UserListDTO dto = new UserListDTO();
mapper.map(userList, dto);
assertNotNull(dto);
assertThat(dto, Matchers.hasProperty("usernames"));
assertThat(dto.getUsernames(), hasSize(3));
}
}