UserProfileHelper { public static List<Map<String, String>> getSortedExperiences(Profile currentProfile) { List<Map<String, String>> experiences = getMultiValues(currentProfile, Profile.EXPERIENCES); if (experiences != null) { Collections.sort(experiences, Comparator.comparing(UserProfileHelper::isCurrent).thenComparing(UserProfileHelper::getStartDate).reversed()); } return experiences; }  static Map<String, Object> getDisplayProfileInfo(Profile currentProfile); static List<Map<String, String>> getSortedExperiences(Profile currentProfile); static List<Map<String, String>> getMultiValues(Profile currentProfile, String key); static List<String> getURLValues(Profile currentProfile); static boolean isString(Object s); static boolean isURL(String key); static String toAbsoluteURL(String url); static boolean isIMs(String key); static boolean isGender(String key); static String getIconCss(String key); static Map<String, String> escapeExperience(Map<String, String> experience); static String getLabel(WebuiRequestContext context, String key); static boolean isExistingEmail(String email); static final String CSS_ICON_PREFIX; final static String KEY; final static String VALUE; final static String URL_KEY; final static String OTHER_KEY; final static String DEFAULT_PROTOCOL; final static DateTimeFormatter DATE_TIME_FORMATTER; }
@Test public void shouldSortExperiencesWithCurrentExperienceFirst() throws Exception { Profile profile = new Profile(new Identity("john")); List<Map<String, String>> experiences = new ArrayList<>(); Map<String, String> experience1 = new HashMap<>(); experience1.put(Profile.EXPERIENCES_ID, "1"); experience1.put(Profile.EXPERIENCES_COMPANY, "Google"); experience1.put(Profile.EXPERIENCES_POSITION, "Developer"); experience1.put(Profile.EXPERIENCES_IS_CURRENT, "true"); experience1.put(Profile.EXPERIENCES_START_DATE,"01/09/2001"); experiences.add(experience1); Map<String, String> experience2 = new HashMap<>(); experience2.put(Profile.EXPERIENCES_ID, "2"); experience2.put(Profile.EXPERIENCES_COMPANY, "eXo"); experience2.put(Profile.EXPERIENCES_POSITION, "Developer"); experience2.put(Profile.EXPERIENCES_IS_CURRENT, "false"); experience2.put(Profile.EXPERIENCES_START_DATE,"01/09/2003"); experience2.put(Profile.EXPERIENCES_END_DATE,"01/09/2004"); experiences.add(experience2); Map<String, String> experience3 = new HashMap<>(); experience3.put(Profile.EXPERIENCES_ID, "3"); experience3.put(Profile.EXPERIENCES_COMPANY, "Apple"); experience3.put(Profile.EXPERIENCES_POSITION, "Developer"); experience3.put(Profile.EXPERIENCES_IS_CURRENT, "true"); experience3.put(Profile.EXPERIENCES_START_DATE,"01/09/2007"); experiences.add(experience3); Map<String, String> experience4 = new HashMap<>(); experience4.put(Profile.EXPERIENCES_ID, "4"); experience4.put(Profile.EXPERIENCES_COMPANY, "Youtube"); experience4.put(Profile.EXPERIENCES_POSITION, "Developer"); experience4.put(Profile.EXPERIENCES_IS_CURRENT, "false"); experience4.put(Profile.EXPERIENCES_START_DATE,"01/09/2005"); experience4.put(Profile.EXPERIENCES_END_DATE,"01/12/2006"); experiences.add(experience4); profile.setProperty(Profile.EXPERIENCES, experiences); List<Map<String, String>> displayExperiences = UserProfileHelper.getSortedExperiences(profile); assertNotNull(displayExperiences); assertEquals(4, displayExperiences.size()); assertEquals("3", displayExperiences.get(0).get(Profile.EXPERIENCES_ID)); assertEquals("1", displayExperiences.get(1).get(Profile.EXPERIENCES_ID)); assertEquals("4", displayExperiences.get(2).get(Profile.EXPERIENCES_ID)); assertEquals("2", displayExperiences.get(3).get(Profile.EXPERIENCES_ID)); }