Skip to content

Commit

Permalink
Merge branch 'pr/706' into hotfix/patches
Browse files Browse the repository at this point in the history
  • Loading branch information
rivaldi8 committed Jul 7, 2017
2 parents c18b040 + 8da9ee8 commit 26277c6
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ public List<String> generateExport() throws ExporterException {
TransactionEntry.TABLE_NAME + "_" + TransactionEntry.COLUMN_UID + " AS trans_uid",
TransactionEntry.TABLE_NAME + "_" + TransactionEntry.COLUMN_TIMESTAMP + " AS trans_time",
TransactionEntry.TABLE_NAME + "_" + TransactionEntry.COLUMN_DESCRIPTION + " AS trans_desc",
TransactionEntry.TABLE_NAME + "_" + TransactionEntry.COLUMN_NOTES + " AS trans_notes",
SplitEntry.TABLE_NAME + "_" + SplitEntry.COLUMN_QUANTITY_NUM + " AS split_quantity_num",
SplitEntry.TABLE_NAME + "_" + SplitEntry.COLUMN_QUANTITY_DENOM + " AS split_quantity_denom",
SplitEntry.TABLE_NAME + "_" + SplitEntry.COLUMN_TYPE + " AS split_type",
Expand Down Expand Up @@ -151,9 +152,14 @@ public List<String> generateExport() throws ExporterException {
writer.append(QifHelper.DATE_PREFIX)
.append(QifHelper.formatDate(cursor.getLong(cursor.getColumnIndexOrThrow("trans_time"))))
.append(newLine);
writer.append(QifHelper.MEMO_PREFIX)
// Payee / description
writer.append(QifHelper.PAYEE_PREFIX)
.append(cursor.getString(cursor.getColumnIndexOrThrow("trans_desc")))
.append(newLine);
// Notes, memo
writer.append(QifHelper.MEMO_PREFIX)
.append(cursor.getString(cursor.getColumnIndexOrThrow("trans_notes")))
.append(newLine);
// deal with imbalance first
double imbalance = cursor.getDouble(cursor.getColumnIndexOrThrow("trans_acct_balance"));
BigDecimal decimalImbalance = BigDecimal.valueOf(imbalance).setScale(2, BigDecimal.ROUND_HALF_UP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class QifHelper {
/*
Prefixes for the QIF file
*/
public static final String PAYEE_PREFIX = "P";
public static final String DATE_PREFIX = "D";
public static final String AMOUNT_PREFIX = "T";
public static final String MEMO_PREFIX = "M";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@
import org.junit.runner.RunWith;
import org.robolectric.annotation.Config;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -144,4 +149,46 @@ public void multiCurrencyTransactions_shouldResultInMultipleQifFiles(){
assertThat(file.length()).isGreaterThan(0L);
}

//@Test
public void description_and_memo_field_test() {
// arrange

String expectedDescription = "my description";
String expectedMemo = "my memo";

AccountsDbAdapter accountsDbAdapter = new AccountsDbAdapter(mDb);
Account account = new Account("Basic Account");
Transaction transaction = new Transaction("One transaction");
transaction.setDescription(expectedDescription);
transaction.setNote(expectedMemo);
account.addTransaction(transaction);
accountsDbAdapter.addRecord(account);

ExportParams exportParameters = new ExportParams(ExportFormat.QIF);
exportParameters.setExportStartTime(TimestampHelper.getTimestampFromEpochZero());
exportParameters.setExportTarget(ExportParams.ExportTarget.SD_CARD);
exportParameters.setDeleteTransactionsAfterExport(false);

// act

QifExporter qifExporter = new QifExporter(exportParameters, mDb);
List<String> exportedFiles = qifExporter.generateExport();

// assert

assertThat(exportedFiles).hasSize(1);
File file = new File(exportedFiles.get(0));
assertThat(file).exists().hasExtension("qif");
StringBuilder fileContentsBuilder = new StringBuilder();
try {
BufferedReader reader = new BufferedReader(new FileReader(file));
fileContentsBuilder.append(reader.readLine());
} catch (IOException e) {
e.printStackTrace();
}
// todo: check the description & memo fields.
String fileContent = fileContentsBuilder.toString();
assertThat(fileContent.contains(expectedDescription));
assertThat(fileContent.contains(expectedMemo));
}
}

0 comments on commit 26277c6

Please sign in to comment.