Skip to content

Commit bec24f6

Browse files
committed
Include future transactions when computing account balance in account list - fixes #465
- This would make it consistent with GnuCash desktop accounts display
1 parent 261a109 commit bec24f6

2 files changed

Lines changed: 48 additions & 3 deletions

File tree

app/src/androidTest/java/org/gnucash/android/test/ui/AccountsActivityTest.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717
package org.gnucash.android.test.ui;
1818

1919
import android.Manifest;
20-
import android.annotation.TargetApi;
2120
import android.content.Context;
2221
import android.content.Intent;
2322
import android.content.SharedPreferences.Editor;
2423
import android.database.SQLException;
2524
import android.database.sqlite.SQLiteDatabase;
26-
import android.os.Build;
2725
import android.preference.PreferenceManager;
2826
import android.support.test.espresso.Espresso;
2927
import android.support.test.espresso.matcher.ViewMatchers;
@@ -32,6 +30,7 @@
3230
import android.support.test.runner.AndroidJUnit4;
3331
import android.support.v4.app.Fragment;
3432
import android.util.Log;
33+
import android.view.View;
3534

3635
import com.kobakei.ratethisapp.RateThisApp;
3736

@@ -54,6 +53,9 @@
5453
import org.gnucash.android.test.ui.util.DisableAnimationsRule;
5554
import org.gnucash.android.ui.account.AccountsActivity;
5655
import org.gnucash.android.ui.account.AccountsListFragment;
56+
import org.hamcrest.Description;
57+
import org.hamcrest.Matcher;
58+
import org.hamcrest.TypeSafeMatcher;
5759
import org.junit.After;
5860
import org.junit.Before;
5961
import org.junit.BeforeClass;
@@ -87,6 +89,7 @@
8789
import static android.support.test.espresso.matcher.ViewMatchers.withText;
8890
import static org.assertj.core.api.Assertions.assertThat;
8991
import static org.hamcrest.Matchers.allOf;
92+
import static org.hamcrest.Matchers.containsString;
9093
import static org.hamcrest.Matchers.instanceOf;
9194
import static org.hamcrest.Matchers.is;
9295
import static org.hamcrest.Matchers.not;
@@ -236,6 +239,21 @@ public void testCreateAccount(){
236239
assertThat(newestAccount.isPlaceholderAccount()).isTrue();
237240
}
238241

242+
@Test
243+
public void should_IncludeFutureTransactionsInAccountBalance(){
244+
Transaction transaction = new Transaction("Future transaction");
245+
Split split1 = new Split(new Money("4.15", ACCOUNTS_CURRENCY_CODE), SIMPLE_ACCOUNT_UID);
246+
transaction.addSplit(split1);
247+
transaction.setTime(System.currentTimeMillis() + 4815162342L);
248+
mTransactionsDbAdapter.addRecord(transaction);
249+
250+
refreshAccountsList();
251+
252+
List<Transaction> trxns = mTransactionsDbAdapter.getAllTransactions();
253+
254+
onView(first(withText(containsString("4.15")))).check(matches(isDisplayed()));
255+
}
256+
239257
@Test
240258
public void testChangeParentAccount() {
241259
final String accountName = "Euro Account";
@@ -511,4 +529,31 @@ public void run() {
511529
System.err.println("Failed to refresh fragment");
512530
}
513531
}
532+
533+
/**
534+
* Matcher to select the first of multiple views which are matched in the UI
535+
* @param expected Matcher which fits multiple views
536+
* @return Single match
537+
*/
538+
public static Matcher<View> first(final Matcher<View> expected){
539+
540+
return new TypeSafeMatcher<View>() {
541+
private boolean first = false;
542+
543+
@Override
544+
protected boolean matchesSafely(View item) {
545+
546+
if( expected.matches(item) && !first ){
547+
return first = true;
548+
}
549+
550+
return false;
551+
}
552+
553+
@Override
554+
public void describeTo(Description description) {
555+
description.appendText("Matcher.first( " + expected.toString() + " )" );
556+
}
557+
};
558+
}
514559
}

app/src/main/java/org/gnucash/android/ui/util/AccountBalanceTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected Money doInBackground(String... params) {
5555

5656
Money balance = Money.getZeroInstance();
5757
try {
58-
balance = accountsDbAdapter.getAccountBalance(params[0], -1, System.currentTimeMillis());
58+
balance = accountsDbAdapter.getAccountBalance(params[0], -1, -1);
5959
} catch (Exception ex) {
6060
Log.e(LOG_TAG, "Error computing account balance ", ex);
6161
Crashlytics.logException(ex);

0 commit comments

Comments
 (0)