]> git.ktnx.net Git - mobile-ledger.git/commitdiff
add (partial) tests for legacy text transaction parser
authorDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 12 Jun 2020 19:51:44 +0000 (22:51 +0300)
committerDamyan Ivanov <dam+mobileledger@ktnx.net>
Fri, 12 Jun 2020 19:51:44 +0000 (22:51 +0300)
app/src/test/java/net/ktnx/mobileledger/async/LegacyParserTest.java [new file with mode: 0644]

diff --git a/app/src/test/java/net/ktnx/mobileledger/async/LegacyParserTest.java b/app/src/test/java/net/ktnx/mobileledger/async/LegacyParserTest.java
new file mode 100644 (file)
index 0000000..985368a
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright © 2020 Damyan Ivanov.
+ * This file is part of MoLe.
+ * MoLe is free software: you can distribute it and/or modify it
+ * under the term of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your opinion), any later version.
+ *
+ * MoLe is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License terms for details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+package net.ktnx.mobileledger.async;
+
+import net.ktnx.mobileledger.model.LedgerTransactionAccount;
+
+import org.junit.Test;
+
+import static junit.framework.TestCase.assertEquals;
+import static junit.framework.TestCase.assertNotNull;
+import static junit.framework.TestCase.assertNull;
+
+public class LegacyParserTest {
+
+    private void expectParsedData(String input, String accountName, Float amount, String currency,
+                                  String comment) {
+        LedgerTransactionAccount lta = RetrieveTransactionsTask.parseTransactionAccountLine(input);
+
+        assertNotNull(lta);
+        assertEquals(accountName, lta.getAccountName());
+        assertEquals(amount, lta.getAmount());
+        assertEquals(currency, lta.getCurrency());
+        assertEquals(comment, lta.getComment());
+    }
+    private void expectNotParsed(String input) {
+        assertNull(RetrieveTransactionsTask.parseTransactionAccountLine(input));
+    }
+    @Test
+    public void parseTransactionAccountLine() {
+        expectParsedData(" acc:name  -34.56", "acc:name", -34.56f, null, null);
+        expectParsedData(" acc:name3  34.56", "acc:name3", 34.56f, null, null);
+        expectParsedData(" acc:name  +34.56", "acc:name", 34.56f, null, null);
+
+        expectParsedData(" acc:name  $-34.56", "acc:name", -34.56f, "$", null);
+        expectParsedData(" acc:name  $ -34.56", "acc:name", -34.56f, "$", null);
+        expectParsedData(" acc:name  -34.56$", "acc:name", -34.56f, "$", null);
+        expectParsedData(" acc:name  -34.56 $", "acc:name", -34.56f, "$", null);
+
+        expectParsedData(" acc:name  AU$-34.56", "acc:name", -34.56f, "AU$", null);
+        expectParsedData(" acc:name  AU$ -34.56", "acc:name", -34.56f, "AU$", null);
+        expectParsedData(" acc:name  -34.56AU$", "acc:name", -34.56f, "AU$", null);
+        expectParsedData(" acc:name  -34.56 AU$", "acc:name", -34.56f, "AU$", null);
+    }
+}
\ No newline at end of file