EmployeeConverter extends AbstractConverter<Employee, EmployeeResource> { @Override public EmployeeResource convert(final Employee source, final EmployeeResource target) { if (source.getEmployeeType() != null) { target.setEmployeeTypeId(source.getEmployeeType().getId()); } if (source.getPerson() != null) { target.setPersonId(source.getPerson().getId()); } if (source.getGenderType() != null) { target.setGenderTypeId(source.getGenderType().getId()); } if (source.getDepartment() != null) { target.setDepartmentId(source.getDepartment().getId()); } if (source.getPost() != null) { target.setPostId(source.getPost().getId()); } if (source.getJobType() != null) { target.setJobTypeId(source.getJobType().getId()); } if (source.getEmployeeStatus() != null) { target.setEmployeeStatusId(source.getEmployeeStatus().getId()); } if (source.getOrder() != null) { target.setOrderId(source.getOrder().getId()); } if (source.getParent() != null) { target.setParentId(source.getParent().getId()); } target.setName(source.getName()); target.setFirstName(source.getFirstName()); target.setFatherName(source.getFatherName()); target.setSurname(source.getSurname()); target.setBirthDate(source.getBirthDate()); target.setInvNum(source.getInvNum()); target.setRate(source.getRate()); target.setIsPlurality(source.getIsPlurality()); target.setIsPensioner(source.getIsPensioner()); target.setBegDate(source.getBegDate()); target.setEndDate(source.getEndDate()); target.setDocSeries(source.getDocSeries()); target.setDocNum(source.getDocNum()); target.setPhone(source.getPhone()); target.setEmail(source.getEmail()); return target; }  @Override EmployeeResource convert(final Employee source, final EmployeeResource target); @Override EmployeeResource convert(final Employee source);  }
@Test public void testConvert() throws Exception { Long employeeTypeId = 2L; EmployeeType employeeType = new EmployeeType(); employeeType.setId(employeeTypeId); Long personId = 3L; Person person = new Person(); person.setId(personId); Long genderTypeId = 4L; GenderType genderType = new GenderType(); genderType.setId(genderTypeId); Long departmentId = 5L; Department department = new Department(); department.setId(departmentId); Long postId = 6L; Post post = new Post(); post.setId(postId); Long jobTypeId = 7L; JobType jobType = new JobType(); jobType.setId(jobTypeId); Long employeeStatusId = 8L; EmployeeStatus employeeStatus = new EmployeeStatus(); employeeStatus.setId(employeeStatusId); Long orderId = 9L; Order order = new Order(); order.setId(orderId); Long parentId = 10L; Employee parent = new Employee(); parent.setId(parentId); String name = "name1"; String firstName = "first name"; String fatherName = "father name"; String surname = "surname"; String invNum = "inv num"; Double rate = 1.0; Integer isPlurality = 1; Integer isPensioner = 2; Date endDate = new Date(); String docSeries = "doc series"; String docNum = "Dco num"; String phone = "phone number"; String email = "email@email.com"; Date begDate = new Date(); Date birthDate = new Date(); EmployeeResource expected = new EmployeeResource(); expected.setName(name); expected.setFirstName(firstName); expected.setFatherName(fatherName); expected.setSurname(surname); expected.setBirthDate(birthDate); expected.setInvNum(invNum); expected.setRate(rate); expected.setIsPlurality(isPlurality); expected.setIsPensioner(isPensioner); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setDocSeries(docSeries); expected.setDocNum(docNum); expected.setPhone(phone); expected.setEmail(email); expected.setEmployeeTypeId(employeeTypeId); expected.setPersonId(personId); expected.setGenderTypeId(genderTypeId); expected.setDepartmentId(departmentId); expected.setPostId(postId); expected.setJobTypeId(jobTypeId); expected.setEmployeeStatusId(employeeStatusId); expected.setOrderId(orderId); expected.setParentId(parentId); Employee source = new Employee(); source.setName(name); source.setFirstName(firstName); source.setFatherName(fatherName); source.setSurname(surname); source.setBirthDate(birthDate); source.setInvNum(invNum); source.setRate(rate); source.setIsPlurality(isPlurality); source.setIsPensioner(isPensioner); source.setBegDate(begDate); source.setEndDate(endDate); source.setDocSeries(docSeries); source.setDocNum(docNum); source.setPhone(phone); source.setEmail(email); source.setEmployeeType(employeeType); source.setPerson(person); source.setGenderType(genderType); source.setDepartment(department); source.setPost(post); source.setJobType(jobType); source.setEmployeeStatus(employeeStatus); source.setOrder(order); source.setParent(parent); EmployeeResource actual = unit.convert(source); assertEquals(expected, actual); }
@Test public void testConvertWithNoRelations() throws Exception { String name = "name1"; String firstName = "first name"; String fatherName = "father name"; String surname = "surname"; String invNum = "inv num"; Double rate = 1.0; Integer isPlurality = 1; Integer isPensioner = 2; Date endDate = new Date(); String docSeries = "doc series"; String docNum = "Dco num"; String phone = "phone number"; String email = "email@email.com"; Date begDate = new Date(); Date birthDate = new Date(); EmployeeResource expected = new EmployeeResource(); expected.setName(name); expected.setFirstName(firstName); expected.setFatherName(fatherName); expected.setSurname(surname); expected.setBirthDate(birthDate); expected.setInvNum(invNum); expected.setRate(rate); expected.setIsPlurality(isPlurality); expected.setIsPensioner(isPensioner); expected.setBegDate(begDate); expected.setEndDate(endDate); expected.setDocSeries(docSeries); expected.setDocNum(docNum); expected.setPhone(phone); expected.setEmail(email); Employee source = new Employee(); source.setName(name); source.setFirstName(firstName); source.setFatherName(fatherName); source.setSurname(surname); source.setBirthDate(birthDate); source.setInvNum(invNum); source.setRate(rate); source.setIsPlurality(isPlurality); source.setIsPensioner(isPensioner); source.setBegDate(begDate); source.setEndDate(endDate); source.setDocSeries(docSeries); source.setDocNum(docNum); source.setPhone(phone); source.setEmail(email); EmployeeResource actual = unit.convert(source); assertEquals(expected, actual); }