DepartmentNameParametersExtractor extends AbstractParametersExtractor<DepartmentName> { @Override protected Map<String, Object> getParameters(final DepartmentName entity, final Map<String, Object> parameters) { addParameter(entity.getDepartment(), departmentDao, "department", parameters); addParameter(entity.getLanguage(), languageDao, "language", parameters); addParameter(entity.getAbbrName(), "abbrName", parameters); addParameter(entity.getName(), "name", parameters); return parameters; }    }
@Test public void testGetParameters() throws Exception { Long departmentId = 1L; Department department = new Department(); department.setId(departmentId); Long languageId = 2L; Language language = new Language(); language.setId(languageId); String abbrName = "abbr name"; String name = "name"; DepartmentName entity = new DepartmentName(); entity.setDepartment(department); entity.setLanguage(language); entity.setAbbrName(abbrName); entity.setName(name); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); expected.put("department", department); expected.put("language", language); expected.put("name", name); expected.put("abbrName", abbrName); when(departmentDao.getEntityById(anyLong())).thenReturn(department); when(languageDao.getEntityById(anyLong())).thenReturn(language); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao).getEntityById(departmentId); verify(languageDao).getEntityById(languageId); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFields() throws Exception { DepartmentName entity = new DepartmentName(); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("userGroups", groups); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao, times(0)).getEntityById(anyLong()); verify(languageDao, times(0)).getEntityById(anyLong()); assertEquals(expected, actual); }
@Test public void testGetParametersWithEmptyFieldsAndWithoutDefaults() throws Exception { unit.setActive(false); unit.setSecurity(false); DepartmentName entity = new DepartmentName(); Map<String, Object> expected = new HashMap<String, Object>(); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao, times(0)).getEntityById(anyLong()); verify(languageDao, times(0)).getEntityById(anyLong()); assertEquals(expected, actual); }
@Test public void testGetParamteresWithoutSecurity() throws Exception { unit.setSecurity(false); Long departmentId = 1L; Department department = new Department(); department.setId(departmentId); Long languageId = 2L; Language language = new Language(); language.setId(languageId); String abbrName = "abbr name"; String name = "name"; DepartmentName entity = new DepartmentName(); entity.setDepartment(department); entity.setLanguage(language); entity.setAbbrName(abbrName); entity.setName(name); Map<String, Object> expected = new HashMap<String, Object>(); expected.put("status", RowStatus.ACTIVE); expected.put("department", department); expected.put("language", language); expected.put("name", name); expected.put("abbrName", abbrName); when(departmentDao.getEntityById(anyLong())).thenReturn(department); when(languageDao.getEntityById(anyLong())).thenReturn(language); Map<String, Object> actual = unit.getParameters(entity); verify(departmentDao).getEntityById(departmentId); verify(languageDao).getEntityById(languageId); verify(sessionService, times(0)).getGroups(); assertEquals(expected, actual); }