### Question:
Converter { public final T convertFromEntity(final U entity) { return fromEntity.apply(entity); } Converter(final Function<T, U> fromDto, final Function<U, T> fromEntity); final U convertFromDto(final T dto); final T convertFromEntity(final U entity); final List<U> createFromDtos(final Collection<T> dtos); final List<T> createFromEntities(final Collection<U> entities);  }### Answer:
@Test public void testCustomConverter() { Converter<UserDto, User> converter = new Converter<>( userDto -> new User(userDto.getFirstName(), userDto.getLastName(), userDto.isActive(), String.valueOf(new Random().nextInt())), user -> new UserDto(user.getFirstName(), user.getLastName(), user.isActive(), user.getFirstName().toLowerCase() + user.getLastName().toLowerCase() + "@whatever.com")); User u1 = new User("John", "Doe", false, "12324"); UserDto userDto = converter.convertFromEntity(u1); assertEquals("johndoe@whatever.com", userDto.getEmail()); }
@Test public void testCustomConverter() { var converter = new Converter<UserDto, User>( userDto -> new User( userDto.getFirstName(), userDto.getLastName(), userDto.isActive(), String.valueOf(new Random().nextInt()) ), user -> new UserDto( user.getFirstName(), user.getLastName(), user.isActive(), user.getFirstName().toLowerCase() + user.getLastName().toLowerCase() + "@whatever.com") ); var u1 = new User("John", "Doe", false, "12324"); var userDto = converter.convertFromEntity(u1); assertEquals("johndoe@whatever.com", userDto.getEmail()); }
@Test public void testCustomConverter() { Converter<UserDto, User> converter = new Converter<>( userDto -> new User(userDto.getFirstName(), userDto.getLastName(), userDto.isActive(), String.valueOf(new Random().nextInt())), user -> new UserDto(user.getFirstName(), user.getLastName(), user.isActive(), user.getFirstName().toLowerCase() + user.getLastName().toLowerCase() + "@whatever.com")); User u1 = new User("John", "Doe", false, "12324"); UserDto userDto = converter.convertFromEntity(u1); assertEquals(userDto.getEmail(), "johndoe@whatever.com"); }