Skip to content

Commit

Permalink
✨ default notice type by enum #48
Browse files Browse the repository at this point in the history
  • Loading branch information
trydofor committed Jan 25, 2025
1 parent 33ecb3a commit 9ef2cb9
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
11 changes: 10 additions & 1 deletion src/main/java/pro/fessional/mirana/i18n/I18nNotice.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* <pre>
* specified message for user to know what and why.
*
* - type - notice type, 'BindingValidation', 'IllegalArgument', 'IllegalState'
* - type - notice type, 'Validation', 'IllegalArgument', 'IllegalState'
* - target - target input name, 'city', 'tab1.zipcode'
* - message - default i18n message
* - i18nCode - i18n template code
Expand All @@ -22,6 +22,15 @@
*/
public class I18nNotice extends I18nMessage {

/**
* the notice type that should be able to locate the input
*/
public enum Type {
Validation,
IllegalArgument,
IllegalState,
}

protected String type;
protected String target;
public String getType() {
Expand Down
13 changes: 7 additions & 6 deletions src/test/java/pro/fessional/mirana/i18n/I18nNoticeTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package pro.fessional.mirana.i18n;

import org.junit.jupiter.api.Test;
import pro.fessional.mirana.i18n.I18nNotice.Type;

import java.util.Locale;

Expand All @@ -23,11 +24,11 @@ void testI18nNoticeSettersAndGetters() {
@Test
void testI18nNoticeEquals() {
I18nNotice notice1 = new I18nNotice();
notice1.setType("BindingValidation");
notice1.setType(Type.IllegalState.name());
notice1.setTarget("city");

I18nNotice notice2 = new I18nNotice();
notice2.setType("BindingValidation");
notice2.setType(Type.IllegalState.name());
notice2.setTarget("city");

I18nNotice notice3 = new I18nNotice();
Expand All @@ -41,11 +42,11 @@ void testI18nNoticeEquals() {
@Test
void testI18nNoticeHashCode() {
I18nNotice notice1 = new I18nNotice();
notice1.setType("BindingValidation");
notice1.setType(Type.IllegalArgument.name());
notice1.setTarget("city");

I18nNotice notice2 = new I18nNotice();
notice2.setType("BindingValidation");
notice2.setType(Type.IllegalArgument.name());
notice2.setTarget("city");

assertEquals(notice1.hashCode(), notice2.hashCode());
Expand All @@ -54,13 +55,13 @@ void testI18nNoticeHashCode() {
@Test
void testI18nNoticeToString() {
I18nNotice notice = new I18nNotice();
notice.setType("BindingValidation");
notice.setType(Type.Validation.name());
notice.setTarget("city");
notice.message = "default message";
notice.i18nCode = "i18n_code";
notice.i18nArgs = new Object[]{ "arg1", "arg2" };

String expected = "I18nNotice{type='BindingValidation', target='city', message='default message', i18nCode='i18n_code', i18nArgs=[arg1, arg2]} ";
String expected = "I18nNotice{type='Validation', target='city', message='default message', i18nCode='i18n_code', i18nArgs=[arg1, arg2]} ";
assertEquals(expected, notice.toString());
}

Expand Down

0 comments on commit 9ef2cb9

Please sign in to comment.