Skip to content

Commit

Permalink
Feature: Add support for specific language tag in TextControlDescriptor
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewhorridge committed Jun 12, 2024
1 parent e69e76f commit 3f4deca
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ public class TextControlDescriptor implements FormControlDescriptor {

private LanguageMap patternViolationErrorMessage = LanguageMap.empty();

private String specificLangTag = "";

private TextControlDescriptor() {
}

public TextControlDescriptor(@Nonnull LanguageMap placeholder,
@Nonnull StringType stringType,
@Nonnull String specificLangTag,
@Nonnull LineMode lineMode,
@Nonnull String pattern,
@Nonnull LanguageMap patternViolationErrorMessage) {
this.placeholder = checkNotNull(placeholder);
this.stringType = checkNotNull(stringType);
this.specificLangTag = checkNotNull(specificLangTag);
this.lineMode = checkNotNull(lineMode);
this.pattern = checkNotNull(pattern);
this.patternViolationErrorMessage = checkNotNull(patternViolationErrorMessage);
Expand All @@ -53,6 +57,7 @@ public static String getType() {
public static TextControlDescriptor getDefault() {
return new TextControlDescriptor(LanguageMap.empty(),
StringType.SIMPLE_STRING,
"",
LineMode.SINGLE_LINE,
"",
LanguageMap.empty());
Expand Down Expand Up @@ -119,6 +124,11 @@ public StringType getStringType() {
return stringType;
}

@Nonnull
public String getSpecificLangTag() {
return specificLangTag;
}

@Override
public int hashCode() {
return Objects.hashCode(placeholder, stringType, pattern, patternViolationErrorMessage, lineMode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public void shouldSerializeAndDeserialize() throws IOException {
new TextControlDescriptor(
LanguageMap.empty(),
StringType.SIMPLE_STRING,
"en",
LineMode.SINGLE_LINE,
"Pattern",
LanguageMap.empty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class TextControlDescriptor_TestCase {

private final StringType stringType = StringType.SIMPLE_STRING;

private final String specificLangTag = "";

private final LineMode lineMode = LineMode.SINGLE_LINE;

private final String pattern = "The pattern";
Expand All @@ -31,14 +33,14 @@ public class TextControlDescriptor_TestCase {
public void setUp()
throws Exception
{
textFieldDescriptor = new TextControlDescriptor(placeholder, stringType, lineMode, pattern, patternViolationErrorMessage);
textFieldDescriptor = new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, pattern, patternViolationErrorMessage);
}

@SuppressWarnings("ConstantConditions")
@Test
public void shouldThrowNullPointerExceptionIf_placeholder_IsNull() {
assertThrows(NullPointerException.class, () -> {
new TextControlDescriptor(null, stringType, lineMode, pattern, patternViolationErrorMessage);
new TextControlDescriptor(null, stringType, specificLangTag, lineMode, pattern, patternViolationErrorMessage);
});
}

Expand All @@ -50,7 +52,7 @@ public void shouldReturnSupplied_placeholder() {
@SuppressWarnings("ConstantConditions")
// @Test(expected = NullPointerException.class)
public void shouldThrowNullPointerExceptionIf_stringType_IsNull() {
new TextControlDescriptor(placeholder, null, lineMode, pattern, patternViolationErrorMessage);
new TextControlDescriptor(placeholder, null, specificLangTag, lineMode, pattern, patternViolationErrorMessage);
}

@Test
Expand All @@ -61,7 +63,7 @@ public void shouldReturnSupplied_stringType() {
@SuppressWarnings("ConstantConditions")
// @Test(expected = NullPointerException.class)
public void shouldThrowNullPointerExceptionIf_lineMode_IsNull() {
new TextControlDescriptor(placeholder, stringType, null, pattern, patternViolationErrorMessage);
new TextControlDescriptor(placeholder, stringType, specificLangTag, null, pattern, patternViolationErrorMessage);
}

@Test
Expand All @@ -72,7 +74,7 @@ public void shouldReturnSupplied_lineMode() {
@SuppressWarnings("ConstantConditions")
// @Test(expected = NullPointerException.class)
public void shouldThrowNullPointerExceptionIf_pattern_IsNull() {
new TextControlDescriptor(placeholder, stringType, lineMode, null, patternViolationErrorMessage);
new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, null, patternViolationErrorMessage);
}

@Test
Expand All @@ -83,7 +85,7 @@ public void shouldReturnSupplied_pattern() {
@SuppressWarnings("ConstantConditions")
// @Test(expected = NullPointerException.class)
public void shouldThrowNullPointerExceptionIf_patternViolationErrorMessage_IsNull() {
new TextControlDescriptor(placeholder, stringType, lineMode, pattern, null);
new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, pattern, null);
}

@Test
Expand All @@ -104,37 +106,37 @@ public void shouldNotBeEqualToNull() {

@Test
public void shouldBeEqualToOther() {
assertThat(textFieldDescriptor, is(new TextControlDescriptor(placeholder, stringType, lineMode, pattern, patternViolationErrorMessage)));
assertThat(textFieldDescriptor, is(new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, pattern, patternViolationErrorMessage)));
}

@Test
public void shouldNotBeEqualToOtherThatHasDifferent_placeholder() {
assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(LanguageMap.of("en", "String-1a3f1304-8c2f-48b2-8c60-3407b27d579f"), stringType, lineMode, pattern, patternViolationErrorMessage))));
assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(LanguageMap.of("en", "String-1a3f1304-8c2f-48b2-8c60-3407b27d579f"), stringType, specificLangTag, lineMode, pattern, patternViolationErrorMessage))));
}

@Test
public void shouldNotBeEqualToOtherThatHasDifferent_stringType() {
assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, StringType.LANG_STRING, lineMode, pattern, patternViolationErrorMessage))));
assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, StringType.LANG_STRING, "de", lineMode, pattern, patternViolationErrorMessage))));
}

@Test
public void shouldNotBeEqualToOtherThatHasDifferent_lineMode() {
assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, LineMode.MULTI_LINE, pattern, patternViolationErrorMessage))));
assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, specificLangTag, LineMode.MULTI_LINE, pattern, patternViolationErrorMessage))));
}

@Test
public void shouldNotBeEqualToOtherThatHasDifferent_pattern() {
assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, lineMode, "String-ac3398da-4b52-48b5-a858-1f8571134db7", patternViolationErrorMessage))));
assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, "String-ac3398da-4b52-48b5-a858-1f8571134db7", patternViolationErrorMessage))));
}

@Test
public void shouldNotBeEqualToOtherThatHasDifferent_patternViolationErrorMessage() {
assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, lineMode, pattern, LanguageMap.of("en", "String-1abd718d-0eb4-4530-b465-02aed8dd66a2")))));
assertThat(textFieldDescriptor, is(not(new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, pattern, LanguageMap.of("en", "String-1abd718d-0eb4-4530-b465-02aed8dd66a2")))));
}

@Test
public void shouldBeEqualToOtherHashCode() {
assertThat(textFieldDescriptor.hashCode(), is(new TextControlDescriptor(placeholder, stringType, lineMode, pattern, patternViolationErrorMessage).hashCode()));
assertThat(textFieldDescriptor.hashCode(), is(new TextControlDescriptor(placeholder, stringType, specificLangTag, lineMode, pattern, patternViolationErrorMessage).hashCode()));
}

@Test
Expand Down

0 comments on commit 3f4deca

Please sign in to comment.