generated from hmcts/spring-boot-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #66 from hmcts/PUB-1974
PUB-1974 Add list type friendly name
- Loading branch information
Showing
4 changed files
with
82 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ publishing { | |
} | ||
|
||
group = 'com.github.hmcts' | ||
version = '2.1.2' | ||
version = '2.1.3' | ||
|
||
java { | ||
toolchain { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
src/main/java/uk/gov/hmcts/reform/pip/model/publication/helpers/ListTypeHelper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package uk.gov.hmcts.reform.pip.model.publication.helpers; | ||
|
||
import org.apache.commons.text.WordUtils; | ||
import uk.gov.hmcts.reform.pip.model.publication.ListType; | ||
|
||
import java.util.Arrays; | ||
import java.util.Locale; | ||
import java.util.Set; | ||
import java.util.stream.Collectors; | ||
|
||
public final class ListTypeHelper { | ||
private static final Set<String> ACRONYMS = Set.of("COP", "ET", "IAC", "SSCS", "SJP"); | ||
private static final Set<String> CONJUNCTIONS = Set.of("and"); | ||
|
||
private ListTypeHelper() { | ||
} | ||
|
||
public static String buildFriendlyName(ListType listType) { | ||
return Arrays.stream(WordUtils.capitalizeFully(listType.name(), '_').split("_")) | ||
.map(word -> ACRONYMS.contains(word.toUpperCase(Locale.ENGLISH)) | ||
? word.toUpperCase(Locale.ENGLISH) : word) | ||
.map(word -> CONJUNCTIONS.contains(word.toLowerCase(Locale.ENGLISH)) | ||
? word.toLowerCase(Locale.ENGLISH) : word) | ||
.collect(Collectors.joining(" ")); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/java/uk/gov/hmcts/reform/pip/model/publication/ListTypeTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package uk.gov.hmcts.reform.pip.model.publication; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static uk.gov.hmcts.reform.pip.model.publication.ListType.CIVIL_AND_FAMILY_DAILY_CAUSE_LIST; | ||
import static uk.gov.hmcts.reform.pip.model.publication.ListType.COP_DAILY_CAUSE_LIST; | ||
import static uk.gov.hmcts.reform.pip.model.publication.ListType.MAGISTRATES_PUBLIC_LIST; | ||
import static uk.gov.hmcts.reform.pip.model.publication.ListType.SSCS_DAILY_LIST_ADDITIONAL_HEARINGS; | ||
|
||
class ListTypeTest { | ||
private static final String LIST_TYPE_NAME_MESSAGE = "List type name does not match"; | ||
|
||
@Test | ||
void testStandardListTypeFriendlyName() { | ||
assertThat(MAGISTRATES_PUBLIC_LIST.getFriendlyName()) | ||
.as(LIST_TYPE_NAME_MESSAGE) | ||
.isEqualTo("Magistrates Public List"); | ||
} | ||
|
||
@Test | ||
void testListTypeWithAcronymFriendlyName() { | ||
assertThat(COP_DAILY_CAUSE_LIST.getFriendlyName()) | ||
.as(LIST_TYPE_NAME_MESSAGE) | ||
.isEqualTo("COP Daily Cause List"); | ||
} | ||
|
||
@Test | ||
void testListTypeWithConjunctionFriendlyName() { | ||
assertThat(CIVIL_AND_FAMILY_DAILY_CAUSE_LIST.getFriendlyName()) | ||
.as(LIST_TYPE_NAME_MESSAGE) | ||
.isEqualTo("Civil and Family Daily Cause List"); | ||
} | ||
|
||
@Test | ||
void testListTypeWithCustomFriendlyName() { | ||
assertThat(SSCS_DAILY_LIST_ADDITIONAL_HEARINGS.getFriendlyName()) | ||
.as(LIST_TYPE_NAME_MESSAGE) | ||
.isEqualTo("SSCS Daily List - Additional Hearings"); | ||
} | ||
} |