|
17 | 17 | package org.gnucash.android.test.ui; |
18 | 18 |
|
19 | 19 | import android.Manifest; |
20 | | -import android.annotation.TargetApi; |
21 | 20 | import android.content.Context; |
22 | 21 | import android.content.Intent; |
23 | 22 | import android.content.SharedPreferences.Editor; |
24 | 23 | import android.database.SQLException; |
25 | 24 | import android.database.sqlite.SQLiteDatabase; |
26 | | -import android.os.Build; |
27 | 25 | import android.preference.PreferenceManager; |
28 | 26 | import android.support.test.espresso.Espresso; |
29 | 27 | import android.support.test.espresso.matcher.ViewMatchers; |
|
32 | 30 | import android.support.test.runner.AndroidJUnit4; |
33 | 31 | import android.support.v4.app.Fragment; |
34 | 32 | import android.util.Log; |
| 33 | +import android.view.View; |
35 | 34 |
|
36 | 35 | import com.kobakei.ratethisapp.RateThisApp; |
37 | 36 |
|
|
54 | 53 | import org.gnucash.android.test.ui.util.DisableAnimationsRule; |
55 | 54 | import org.gnucash.android.ui.account.AccountsActivity; |
56 | 55 | import org.gnucash.android.ui.account.AccountsListFragment; |
| 56 | +import org.hamcrest.Description; |
| 57 | +import org.hamcrest.Matcher; |
| 58 | +import org.hamcrest.TypeSafeMatcher; |
57 | 59 | import org.junit.After; |
58 | 60 | import org.junit.Before; |
59 | 61 | import org.junit.BeforeClass; |
|
87 | 89 | import static android.support.test.espresso.matcher.ViewMatchers.withText; |
88 | 90 | import static org.assertj.core.api.Assertions.assertThat; |
89 | 91 | import static org.hamcrest.Matchers.allOf; |
| 92 | +import static org.hamcrest.Matchers.containsString; |
90 | 93 | import static org.hamcrest.Matchers.instanceOf; |
91 | 94 | import static org.hamcrest.Matchers.is; |
92 | 95 | import static org.hamcrest.Matchers.not; |
@@ -236,6 +239,21 @@ public void testCreateAccount(){ |
236 | 239 | assertThat(newestAccount.isPlaceholderAccount()).isTrue(); |
237 | 240 | } |
238 | 241 |
|
| 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 | + |
239 | 257 | @Test |
240 | 258 | public void testChangeParentAccount() { |
241 | 259 | final String accountName = "Euro Account"; |
@@ -511,4 +529,31 @@ public void run() { |
511 | 529 | System.err.println("Failed to refresh fragment"); |
512 | 530 | } |
513 | 531 | } |
| 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 | + } |
514 | 559 | } |
0 commit comments