Skip to content

Commit

Permalink
CU-86b1g1mye_SRU2024_Generar-un-enum-de-FieldNames-para-validar-que-e…
Browse files Browse the repository at this point in the history
…l-Field-exista
  • Loading branch information
ptorres-prowide authored and zubri committed Sep 30, 2024
1 parent 9a09803 commit b6c99c0
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.5.2 - SNAPSHOT
* Added new SRU2023FieldEnum with all the available field names
* Added new FieldEnum with all the available field names

#### 9.5.1 - 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 @@ -725,13 +725,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("14P", FieldEnum.F14P.getFieldName());
assertEquals("30K", FieldEnum.F30K.getFieldName());
void testfieldName() {
// Validate that fieldName returns the correct value
assertEquals("11A", FieldEnum.F11A.fieldName());
assertEquals("14P", FieldEnum.F14P.fieldName());
assertEquals("30K", FieldEnum.F30K.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.F14R, FieldEnum.fromCode("14R"));
assertEquals(FieldEnum.F30K, FieldEnum.fromCode("30K"));
void testfromFieldNameValid() {
// Validate that fromFieldName returns the correct enum when a valid code is provided
assertEquals(FieldEnum.F11A, FieldEnum.fromFieldName("11A"));
assertEquals(FieldEnum.F14R, FieldEnum.fromFieldName("14R"));
assertEquals(FieldEnum.F30K, FieldEnum.fromFieldName("30K"));
}

@Test
void testFromCodeInvalid() {
// Validate that fromCode returns null when an invalid code is provided
assertNull(FieldEnum.fromCode("930K"));
assertNull(FieldEnum.fromCode("ABC"));
assertNull(FieldEnum.fromCode(""));
void testfromFieldNameInvalid() {
// Validate that fromFieldName returns null when an invalid code is provided
assertNull(FieldEnum.fromFieldName("930K"));
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 b6c99c0

Please sign in to comment.