2 * Copyright © 2020 Damyan Ivanov.
3 * This file is part of MoLe.
4 * MoLe is free software: you can distribute it and/or modify it
5 * under the term of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your opinion), any later version.
9 * MoLe is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License terms for details.
14 * You should have received a copy of the GNU General Public License
15 * along with MoLe. If not, see <https://www.gnu.org/licenses/>.
18 package net.ktnx.mobileledger.async;
20 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
22 import org.junit.Test;
24 import static junit.framework.TestCase.assertEquals;
25 import static junit.framework.TestCase.assertNotNull;
26 import static junit.framework.TestCase.assertNull;
28 public class LegacyParserTest {
30 private void expectParsedData(String input, String accountName, Float amount, String currency,
32 LedgerTransactionAccount lta = RetrieveTransactionsTask.parseTransactionAccountLine(input);
35 assertEquals(accountName, lta.getAccountName());
36 assertEquals(amount, lta.getAmount());
37 assertEquals(currency, lta.getCurrency());
38 assertEquals(comment, lta.getComment());
40 private void expectNotParsed(String input) {
41 assertNull(RetrieveTransactionsTask.parseTransactionAccountLine(input));
44 public void parseTransactionAccountLine() {
45 expectParsedData(" acc:name -34.56", "acc:name", -34.56f, null, null);
46 expectParsedData(" acc:name3 34.56", "acc:name3", 34.56f, null, null);
47 expectParsedData(" acc:name +34.56", "acc:name", 34.56f, null, null);
49 expectParsedData(" acc:name $-34.56", "acc:name", -34.56f, "$", null);
50 expectParsedData(" acc:name $ -34.56", "acc:name", -34.56f, "$", null);
51 expectParsedData(" acc:name -34.56$", "acc:name", -34.56f, "$", null);
52 expectParsedData(" acc:name -34.56 $", "acc:name", -34.56f, "$", null);
54 expectParsedData(" acc:name AU$-34.56", "acc:name", -34.56f, "AU$", null);
55 expectParsedData(" acc:name AU$ -34.56", "acc:name", -34.56f, "AU$", null);
56 expectParsedData(" acc:name -34.56AU$", "acc:name", -34.56f, "AU$", null);
57 expectParsedData(" acc:name -34.56 AU$", "acc:name", -34.56f, "AU$", null);