PropertyUtils { public static PropertyEditorCategory convertMapToCategory(Map<String, List<String>> map) { if (map != null && !map.keySet().isEmpty()) { String categoryName = map.keySet().iterator().next(); PropertyEditorCategory category = new PropertyEditorCategory(categoryName); List<String> fields = map.get(categoryName); for (String field : fields) { category.withField(new PropertyEditorFieldInfo(field, PropertyEditorType.TEXT)); } return category; } return null; }  static PropertyEditorCategory convertMapToCategory(Map<String, List<String>> map);  }
@Test public void convertMapToCategoryNullCase() { assertNull(PropertyUtils.convertMapToCategory(null)); assertNull(PropertyUtils.convertMapToCategory(new HashMap<String, List<String>>())); }
@Test public void convertMapToCategory() { HashMap<String, List<String>> categoryMap = new HashMap<String, List<String>>(); List<String> categoryFields = new ArrayList<String>(); categoryFields.add("field1"); categoryFields.add("field2"); categoryMap.put("Category1", categoryFields); PropertyEditorCategory category = PropertyUtils.convertMapToCategory(categoryMap); assertNotNull(category); assertEquals(category.getFields().size(), 2); assertEquals(category.getFields().get(0).getLabel(), "field1"); assertEquals(category.getFields().get(1).getLabel(), "field2"); }