DepartmentAddressParametersExtractor extends AbstractParametersExtractor<DepartmentAddress> { @Override protected Map<String, Object> getParameters(final DepartmentAddress entity, final Map<String, Object> parameters) { addParameter(entity.getDepartment(), departmentDao, "department", parameters); addParameter(entity.getAddressType(), addressTypeDao, "addressType", parameters); addParameter(entity.getAdminUnit(), adminUnitDao, "adminUnit", parameters); addParameter(entity.getStreetType(), streetTypeDao, "streetType", parameters); addParameter(entity.getZipCode(), "zipCode", parameters); addParameter(entity.getStreet(), "street", parameters); addParameter(entity.getHouse(), "house", parameters); addParameter(entity.getApartment(), "apartment", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { String zipCode = "zip code"; String street = "Street"; String apartment = "apartment"; String house = "house"; Long departmentId = 1L; Department department = new Department(); department.setId(departmentId); Long addressTypeId = 2L; AddressType addressType = new AddressType(); addressType.setId(addressTypeId); Long adminUnitId = 3L; AdminUnit adminUnit = new AdminUnit(); adminUnit.setId(adminUnitId); Long streetTypeId = 4L; StreetType streetType = new StreetType(); streetType.setId(streetTypeId); DepartmentAddress entity = new DepartmentAddress(); entity.setDepartment(department); entity.setAddressType(addressType); entity.setAdminUnit(adminUnit); entity.setStreetType(streetType); entity.setZipCode(zipCode); entity.setStreet(street); entity.setHouse(house); entity.setApartment(apartment); Map<String, Object> expected = new HashMap<>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); expected.put("department", department); expected.put("addressType", addressType); expected.put("streetType", streetType); expected.put("adminUnit", adminUnit); expected.put("zipCode", zipCode); expected.put("street", street); expected.put("house", house); expected.put("apartment", apartment); when(departmentDao.getEntityById(anyLong())).thenReturn(department); when(addressTypeDao.getEntityById(anyLong())).thenReturn(addressType); when(adminUnitDao.getEntityById(anyLong())).thenReturn(adminUnit); when(streetTypeDao.getEntityById(anyLong())).thenReturn(streetType); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao).getEntityById(departmentId); verify(addressTypeDao).getEntityById(addressTypeId); verify(adminUnitDao).getEntityById(adminUnitId); verify(streetTypeDao).getEntityById(streetTypeId); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyParameters() throws Exception { DepartmentAddress entity = new DepartmentAddress(); Map<String, Object> expected = new HashMap<>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); Map<String, Object> actual = unit.getParameters(entity); assertEquals(expected, actual); }
@Test(expected = EntityNotFoundException.class) public void testGetParametersWithException() throws Exception { String zipCode = "zip code"; String street = "Street"; String apartment = "apartment"; String house = "house"; Long departmentId = 1L; Department department = new Department(); department.setId(departmentId); DepartmentAddress entity = new DepartmentAddress(); entity.setDepartment(department); entity.setZipCode(zipCode); entity.setStreet(street); entity.setHouse(house); entity.setApartment(apartment); doThrow(EntityNotFoundException.class).when(departmentDao).getEntityById(anyLong()); unit.getParameters(entity); verify(departmentDao).getEntityById(departmentId); }