Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Specific lang tag support #2

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ public enum StringType {

SIMPLE_STRING,

LANG_STRING
LANG_STRING,

SPECIFIC_LANG_STRING
}
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
Loading