Skip to content

Commit

Permalink
CU-86b1g1mye_Generar-un-enum-de-FieldNames-para-validar-que-el-Field-…
Browse files Browse the repository at this point in the history
…exista
  • Loading branch information
ptorres-prowide authored and zubri committed Sep 30, 2024
1 parent 77ff190 commit 287b11b
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Prowide Core - CHANGELOG

#### 9.4.18 - SNAPSHOT
* Added new SRU2023FieldEnum with all the available field names
* Added new FieldEnum with all the available field names

#### 9.4.17 - June 2024
* (PW-1913) Added IBAN validation for Egypt local account structure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -723,13 +723,34 @@ public enum FieldEnum {
F619,
F999;

public String getFieldName() {
/**
* Retrieves the field name associated with the enum constant.
* The field name is the part of the enum constant name after the initial 'F'.
*
* @return the field name as a {@code String}
* <p>
* Example:
* FieldEnum field = FieldEnum.F11A;
* String fieldName = field.fieldName(); // returns "11A"
*/
public String fieldName() {
return name().substring(1); // Skips the first character 'F' and returns the rest of the name
}

public static FieldEnum fromCode(String code) {
/**
* Converts a string field name into its corresponding {@code FieldEnum} constant.
* The input should be the string representation of the field without the initial 'F'.
*
* @param fieldName the string field name (e.g., "11A", "12B")
* @return the corresponding {@code FieldEnum} constant, or {@code null} if not found
* <p>
* Example:
* FieldEnum field = FieldEnum.fromFieldName("11A"); // returns FieldEnum.F11A
* FieldEnum unknownField = FieldEnum.fromFieldName("99Z"); // returns null
*/
public static FieldEnum fromFieldName(String fieldName) {
for (FieldEnum field : FieldEnum.values()) {
if (field.getFieldName().equals(code)) {
if (field.fieldName().equals(fieldName)) {
return field;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@
class FieldEnumTest {

@Test
void testGetFieldName() {
// Validate that getFieldName returns the correct value
assertEquals("11A", FieldEnum.F11A.getFieldName());
assertEquals("22J", FieldEnum.F22J.getFieldName());
assertEquals("44H", FieldEnum.F44H.getFieldName());
void testfieldName() {
// Validate that fieldName returns the correct value
assertEquals("11A", FieldEnum.F11A.fieldName());
assertEquals("22J", FieldEnum.F22J.fieldName());
assertEquals("44H", FieldEnum.F44H.fieldName());
}

@Test
void testFromCodeValid() {
// Validate that fromCode returns the correct enum when a valid code is provided
assertEquals(FieldEnum.F11A, FieldEnum.fromCode("11A"));
assertEquals(FieldEnum.F22J, FieldEnum.fromCode("22J"));
assertEquals(FieldEnum.F44H, FieldEnum.fromCode("44H"));
void testfromFieldNameValid() {
// Validate that fromFieldName returns the correct enum when a valid code is provided
assertEquals(FieldEnum.F11A, FieldEnum.fromFieldName("11A"));
assertEquals(FieldEnum.F22J, FieldEnum.fromFieldName("22J"));
assertEquals(FieldEnum.F44H, FieldEnum.fromFieldName("44H"));
}

@Test
void testFromCodeInvalid() {
// Validate that fromCode returns null when an invalid code is provided
assertNull(FieldEnum.fromCode("999A"));
assertNull(FieldEnum.fromCode("ABC"));
assertNull(FieldEnum.fromCode(""));
void testfromFieldNameInvalid() {
// Validate that fromFieldName returns null when an invalid code is provided
assertNull(FieldEnum.fromFieldName("999A"));
assertNull(FieldEnum.fromFieldName("ABC"));
assertNull(FieldEnum.fromFieldName(""));
}

@Test
void testFromCodeEdgeCases() {
void testfromFieldNameEdgeCases() {
// Validate edge cases, such as lowercase inputs, to ensure the method is case-sensitive
assertNull(FieldEnum.fromCode("11a")); // should return null because "11a" is lowercase
assertNull(FieldEnum.fromCode(" 11A")); // should return null because of the leading space
assertNull(FieldEnum.fromCode("11A ")); // should return null because of the trailing space
assertNull(FieldEnum.fromFieldName("11a")); // should return null because "11a" is lowercase
assertNull(FieldEnum.fromFieldName(" 11A")); // should return null because of the leading space
assertNull(FieldEnum.fromFieldName("11A ")); // should return null because of the trailing space
}

@Test
void testAllEnumValues() {
// Validate that all enum values have the correct field name
for (FieldEnum field : FieldEnum.values()) {
assertEquals(field.name().substring(1), field.getFieldName());
assertEquals(field.name().substring(1), field.fieldName());
}
}
}

0 comments on commit 287b11b

Please sign in to comment.