From 9fc3f68c159fc2d7ad78eff4a8c9f17f8f65027b Mon Sep 17 00:00:00 2001 From: Damyan Ivanov Date: Fri, 12 Jun 2020 22:51:44 +0300 Subject: [PATCH] add (partial) tests for legacy text transaction parser --- .../mobileledger/async/LegacyParserTest.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 app/src/test/java/net/ktnx/mobileledger/async/LegacyParserTest.java 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 index 00000000..985368a6 --- /dev/null +++ b/app/src/test/java/net/ktnx/mobileledger/async/LegacyParserTest.java @@ -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 . + */ + +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 -- 2.39.5