Skip to content

Commit 7bc3c74

Browse files
authored
feat: 1976 modifying notice description for invalid currency amount (#1988)
1 parent 03cd4dd commit 7bc3c74

File tree

4 files changed

+20
-17
lines changed

4 files changed

+20
-17
lines changed

core/src/main/java/org/mobilitydata/gtfsvalidator/notice/InvalidCurrencyAmountNotice.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,34 @@
1111
* A currency amount field has a value that does not match the format of its corresponding currency
1212
* code field.
1313
*
14-
* <p>Typically, this means the amount did not have the expected number of decimal places. The
15-
* number of decimal places is specified by <a
16-
* href="https://en.wikipedia.org/wiki/ISO_4217#Active_codes">ISO 4217</a>.
17-
*
18-
* @see org.mobilitydata.gtfsvalidator.annotation.CurrencyAmount
14+
* <p>Typically, this means the amount did not have the expected number of decimal places. Check the
15+
* formatting of your amount field so it matches the number of decimal places specified by the <a
16+
* href="https://en.wikipedia.org/wiki/ISO_4217#Active_codes">currency_code value</a>.
1917
*/
2018
@GtfsValidationNotice(severity = ERROR, sections = @SectionRefs(FILED_TYPES))
2119
public class InvalidCurrencyAmountNotice extends ValidationNotice {
2220

2321
/** The name of the faulty file. */
2422
private final String filename;
2523

26-
/** Faulty record's field name. */
27-
private final String fieldName;
28-
2924
/** The row of the faulty record. */
3025
private final int csvRowNumber;
3126

32-
/** Faulty currency amount value. */
33-
private final String amount;
27+
/** Faulty record's currency code. */
28+
private final String currencyCode;
29+
30+
/** Faulty record's field name. */
31+
private final String fieldName;
32+
33+
/** Faulty currency field amount value. */
34+
private final String fieldValue;
3435

3536
public InvalidCurrencyAmountNotice(
36-
String filename, String fieldName, int csvRowNumber, BigDecimal amount) {
37+
String filename, int csvRowNumber, String currencyCode, String fieldName, BigDecimal amount) {
3738
this.filename = filename;
38-
this.fieldName = fieldName;
3939
this.csvRowNumber = csvRowNumber;
40-
this.amount = amount.toPlainString();
40+
this.currencyCode = currencyCode;
41+
this.fieldName = fieldName;
42+
this.fieldValue = amount.toPlainString();
4143
}
4244
}

main/src/test/java/org/mobilitydata/gtfsvalidator/validator/NoticeFieldsTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,8 @@ public void testNoticeClassFieldNames() {
227227
"validator",
228228
"value",
229229
"duplicatedElement",
230-
"unknownElement");
230+
"unknownElement",
231+
"currencyCode");
231232
}
232233

233234
private static List<String> discoverValidationNoticeFieldNames() {

processor/src/main/java/org/mobilitydata/gtfsvalidator/processor/CurrencyAmountValidatorGenerator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ private static TypeSpec generateValidator(GtfsFileDescriptor fileDescriptor) {
9393
.addStatement("$T currency = entity.$L()", Currency.class, currencyField.name())
9494
.beginControlFlow("if (amount.scale() != currency.getDefaultFractionDigits())")
9595
.addStatement(
96-
"noticeContainer.addValidationNotice(new $T(\"$L\", \"$L\", entity.csvRowNumber(),"
96+
"noticeContainer.addValidationNotice(new $T(\"$L\", entity.csvRowNumber(), currency.getCurrencyCode(), \"$L\", "
9797
+ " amount))",
9898
InvalidCurrencyAmountNotice.class,
9999
fileDescriptor.filename(),

processor/tests/src/test/java/org/mobilitydata/gtfsvalidator/processor/tests/CurrencyAmountSchemaTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public void testInvalidCurrencyUSD() throws ValidatorLoaderException {
6060
assertThat(helper.getValidationNotices())
6161
.containsExactly(
6262
new InvalidCurrencyAmountNotice(
63-
"currency_amount.txt", "amount", 2, new BigDecimal("1.5")));
63+
"currency_amount.txt", 2, "USD", "amount", new BigDecimal("1.5")));
6464
}
6565

6666
@Test
@@ -79,6 +79,6 @@ public void testInvalidCurrencyISK() throws ValidatorLoaderException {
7979
assertThat(helper.getValidationNotices())
8080
.containsExactly(
8181
new InvalidCurrencyAmountNotice(
82-
"currency_amount.txt", "amount", 2, new BigDecimal("5.0")));
82+
"currency_amount.txt", 2, "ISK", "amount", new BigDecimal("5.0")));
8383
}
8484
}

0 commit comments

Comments
 (0)