From 1c71e9efbfedcfa67c501a955484a9137da0096d Mon Sep 17 00:00:00 2001 From: teridax Date: Thu, 22 Jun 2023 12:58:56 +0200 Subject: [PATCH] added new tests for decoding --- res/banking_invalid.csv | 6 ++++++ res/{BankCSV_etwurf.csv => banking_valid.csv} | 0 res/banking_valid_other_formats.csv | 6 ++++++ src/me/teridax/jcash/banking/Testing.java | 8 +++++++- src/me/teridax/jcash/decode/Decoder.java | 4 ++++ 5 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 res/banking_invalid.csv rename res/{BankCSV_etwurf.csv => banking_valid.csv} (100%) create mode 100644 res/banking_valid_other_formats.csv diff --git a/res/banking_invalid.csv b/res/banking_invalid.csv new file mode 100644 index 0000000..31563e3 --- /dev/null +++ b/res/banking_invalid.csv @@ -0,0 +1,6 @@ +Bank;BLZ;Kontonummer;PIN;Kontostand;Kontoart;Zins %;Ueberziehungsbetrag;Kundennummer;Name;Vorname;Kunde Straße;Kunde PLZ;Kunde Ort +VR Bank Rhein-Neckar;MA2424;4711;1234; -50,14 €;Sparkonto;3%;;123456;Mustermann;Max;Bahnhofstraße 1;68159;Mannheim +VR Bank Rhein-Neckar;MA2424;-8321;1234; 500, €;Girokonto;;1.000,27 €; 123456;Mustermann;Max; Bahnhof straße 1;68159;Mannheim +Berliner Bank;19087;1717;1234; 500,1400;Sparkonto; 1,003 ;;717171;Mustermann;Max;Bahnhofstraße 1;68159;Mannheim +Berliner Bank;19087;1919;1234;540,2 € ;Sparkonto; ,001;;717171;Mustermann Hans-Peter;Max;Bahnhofstraße 1;68159;Mannheim +Zocker Bank;Zock7777;4444;7777; -8000,5 €;Girokonto;;50000,5;31124;Hogo;Gruber;Berlinestraß 33 / 1;7899;Berlin diff --git a/res/BankCSV_etwurf.csv b/res/banking_valid.csv similarity index 100% rename from res/BankCSV_etwurf.csv rename to res/banking_valid.csv diff --git a/res/banking_valid_other_formats.csv b/res/banking_valid_other_formats.csv new file mode 100644 index 0000000..4fff6e8 --- /dev/null +++ b/res/banking_valid_other_formats.csv @@ -0,0 +1,6 @@ +Bank;BLZ;Kontonummer;PIN;Kontostand;Kontoart;Zins %;Ueberziehungsbetrag;Kundennummer;Name;Vorname;Kunde Straße;Kunde PLZ;Kunde Ort +VR Bank Rhein-Neckar;MA2424;4711;1234; -50,14 €;Sparkonto;3%;;123456;Mustermann;Max;Bahnhofstraße 1;68159;Mannheim +VR Bank Rhein-Neckar;MA2424;8321;1234; 500, €;Girokonto;;1.000,27 €; 123456;Mustermann;Max; Bahnhof straße 1;68159;Mannheim +Berliner Bank;19087;1717;1234; 500,1400;Sparkonto; 1,003 ;;717171;Mustermann;Max;Bahnhofstraße 1;68159;Mannheim +Berliner Bank;19087;1919;1234;540,2 € ;Sparkonto; ,001;;717171;Mustermann Hans-Peter;Max;Bahnhofstraße 1;68159;Mannheim +Zocker Bank;Zock7777;4444;7777; -8000,5 €;Girokonto;;50000,5;31124;Hogo;Gruber;Berlinestraß 33 / 1;7899;Berlin diff --git a/src/me/teridax/jcash/banking/Testing.java b/src/me/teridax/jcash/banking/Testing.java index 0154cfc..dee3fa9 100644 --- a/src/me/teridax/jcash/banking/Testing.java +++ b/src/me/teridax/jcash/banking/Testing.java @@ -8,6 +8,12 @@ public class Testing { @Test public void test() { - BankingManagementSystem.loadFromCsv(Paths.get("res/BankCSV_etwurf.csv")); + BankingManagementSystem.loadFromCsv(Paths.get("res/banking_valid.csv")); + BankingManagementSystem.loadFromCsv(Paths.get("res/banking_valid_other_formats.csv")); + } + + @Test(expected = IllegalArgumentException.class) + public void testInvalid() { + BankingManagementSystem.loadFromCsv(Paths.get("res/banking_invalid.csv")); } } diff --git a/src/me/teridax/jcash/decode/Decoder.java b/src/me/teridax/jcash/decode/Decoder.java index b0e805b..4af70b8 100644 --- a/src/me/teridax/jcash/decode/Decoder.java +++ b/src/me/teridax/jcash/decode/Decoder.java @@ -46,6 +46,10 @@ public class Decoder { LOCAL_NUMBER_FORMAT.setParseIntegerOnly(true); var serialNumber = LOCAL_NUMBER_FORMAT.parse(number.trim()); LOCAL_NUMBER_FORMAT.setParseIntegerOnly(false); + + if (serialNumber.intValue() < 0) + throw new IllegalArgumentException("Not a valid unique identification number: " + number); + return serialNumber.intValue(); } catch (ParseException ex) { throw new IllegalArgumentException("Not a valid serial number: " + number, ex);