Commit 4d153a80 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Group names bugfix

parent e7c7f84d
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -85,9 +85,14 @@ public class GroupNameService {
    }

    public String getShortGroupName(String completeGroupName, Optional<String> groupPrefix) {
        if (groupPrefix.isPresent()) {
        if (groupPrefix.isPresent() && !groupPrefix.get().isBlank()) {
            if (groupPrefix.get().endsWith(".")) {
                // this branch is kept for retro-compatibility with old API, it will be removed in the future
                return completeGroupName.substring(groupPrefix.get().length());
            } else {
                return completeGroupName.substring(groupPrefix.get().length() + 1);
            }
        }
        return completeGroupName;
    }

+15 −0
Original line number Diff line number Diff line
@@ -99,4 +99,19 @@ public class GroupNameServiceTest {
    public void extractGroupNamesTestNull() {
        assertTrue(groupNameService.extractGroupNames(null).isEmpty());
    }

    @Test
    public void testGetShortGroupNameOld() {
        assertEquals("INAF", groupNameService.getShortGroupName("LBT.INAF", Optional.of("LBT.")));
    }

    @Test
    public void testGetShortGroupName() {
        assertEquals("INAF", groupNameService.getShortGroupName("LBT.INAF", Optional.of("LBT")));
    }

    @Test
    public void testGetShortGroupNameEmpty() {
        assertEquals("LBT.INAF", groupNameService.getShortGroupName("LBT.INAF", Optional.of("")));
    }
}