]> git.ktnx.net Git - mobile-ledger.git/blob - app/src/test/java/net/ktnx/mobileledger/async/LegacyParserTest.java
more pronounced day/month delimiters in the transaction list
[mobile-ledger.git] / app / src / test / java / net / ktnx / mobileledger / async / LegacyParserTest.java
1 /*
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.
8  *
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.
13  *
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/>.
16  */
17
18 package net.ktnx.mobileledger.async;
19
20 import net.ktnx.mobileledger.model.LedgerTransactionAccount;
21
22 import org.junit.Test;
23
24 import static junit.framework.TestCase.assertEquals;
25 import static junit.framework.TestCase.assertNotNull;
26 import static junit.framework.TestCase.assertNull;
27
28 public class LegacyParserTest {
29
30     private void expectParsedData(String input, String accountName, Float amount, String currency,
31                                   String comment) {
32         LedgerTransactionAccount lta = RetrieveTransactionsTask.parseTransactionAccountLine(input);
33
34         assertNotNull(lta);
35         assertEquals(accountName, lta.getAccountName());
36         assertEquals(amount, lta.getAmount());
37         assertEquals(currency, lta.getCurrency());
38         assertEquals(comment, lta.getComment());
39     }
40     private void expectNotParsed(String input) {
41         assertNull(RetrieveTransactionsTask.parseTransactionAccountLine(input));
42     }
43     @Test
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);
48
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);
53
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);
58     }
59 }