Skip to content

Commit f6a157c

Browse files
committed
Updated Robotium tests
Splits set default transaction type based on sign of amount
1 parent 17b4b8b commit f6a157c

13 files changed

Lines changed: 269 additions & 195 deletions

File tree

app/res/layout/fragment_new_account.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
android:ellipsize="start"
3636
android:hint="@string/label_account_name"
3737
style="@style/ListItemText">
38-
<requestFocus />
38+
<!-- <requestFocus /> -->
3939
</EditText>
4040

4141
<TextView

app/src/org/gnucash/android/db/TransactionsDbAdapter.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,8 @@ public Transaction getTransaction(long rowId){
228228
}
229229

230230
/**
231-
* Returns a cursor to a set of all transactions for the account with UID <code>accountUID</code>
232-
* or for which this account is the origin account (double entry)
233-
* i.e <code>accountUID</code> is double entry account UID
231+
* Returns a cursor to a set of all transactions which have a split belonging to the accound with unique ID
232+
* <code>accountUID</code>.
234233
* @param accountUID UID of the account whose transactions are to be retrieved
235234
* @return Cursor holding set of transactions for particular account
236235
* @throws java.lang.IllegalArgumentException if the accountUID is null
@@ -521,8 +520,25 @@ public int getTransactionsCount(long accountId){
521520
}
522521
return count;
523522
}
524-
525-
/**
523+
524+
/**
525+
* Returns the number of transactions belonging to an account
526+
* @param accountUID GUID of the account
527+
* @return Number of transactions with splits in the account
528+
*/
529+
public int getTransactionsCount(String accountUID){
530+
Cursor cursor = fetchAllTransactionsForAccount(accountUID);
531+
int count = 0;
532+
if (cursor == null)
533+
return count;
534+
else {
535+
count = cursor.getCount();
536+
cursor.close();
537+
}
538+
return count;
539+
}
540+
541+
/**
526542
* Returns the total number of transactions in the database
527543
* regardless of what account they belong to
528544
* @return Number of transaction in the database

app/src/org/gnucash/android/model/Split.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public Split(Money amount, String accountUID){
5656
setAmount(amount);
5757
setAccountUID(accountUID);
5858
mUID = UUID.randomUUID().toString().replaceAll("-","");
59+
mSplitType = amount.isNegative() ? TransactionType.DEBIT : TransactionType.CREDIT;
5960
}
6061

6162
/**

app/src/org/gnucash/android/ui/account/AccountFormFragment.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
241241
getSherlockActivity().getSupportActionBar().setTitle(R.string.title_add_account);
242242
mCurrencySpinner = (Spinner) view.findViewById(R.id.input_currency_spinner);
243243
mNameEditText = (EditText) view.findViewById(R.id.edit_text_account_name);
244-
mNameEditText.requestFocus();
244+
//mNameEditText.requestFocus();
245245

246246
mAccountTypeSpinner = (Spinner) view.findViewById(R.id.input_account_type_spinner);
247247
mAccountTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

app/src/org/gnucash/android/ui/account/AccountsActivity.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,10 @@ public void onCreate(Bundle savedInstanceState) {
255255

256256
}
257257

258+
public void setTab(int index){
259+
mPager.setCurrentItem(index);
260+
}
261+
258262
/**
259263
* Loads default setting for currency and performs app first-run initialization
260264
*/

app/src/org/gnucash/android/ui/transaction/TransactionsActivity.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@ public class TransactionsActivity extends PassLockActivity implements
133133
private TextView mSectionHeaderTransactions;
134134
private TitlePageIndicator mTitlePageIndicator;
135135

136+
private ViewPager mPager;
137+
136138
private SparseArray<Refreshable> mFragmentPageReferenceMap = new SparseArray<Refreshable>();
137139

138140
private OnNavigationListener mTransactionListNavigationListener = new OnNavigationListener() {
@@ -275,7 +277,7 @@ protected void onCreate(Bundle savedInstanceState) {
275277
super.onCreate(savedInstanceState);
276278
setContentView(R.layout.activity_transactions);
277279

278-
ViewPager pager = (ViewPager) findViewById(R.id.pager);
280+
mPager = (ViewPager) findViewById(R.id.pager);
279281
mTitlePageIndicator = (TitlePageIndicator) findViewById(R.id.titles);
280282
mSectionHeaderTransactions = (TextView) findViewById(R.id.section_header_transactions);
281283

@@ -286,18 +288,18 @@ protected void onCreate(Bundle savedInstanceState) {
286288
setupActionBarNavigation();
287289

288290
if (getIntent().getAction().equals(Intent.ACTION_INSERT_OR_EDIT)) {
289-
pager.setVisibility(View.GONE);
291+
mPager.setVisibility(View.GONE);
290292
mTitlePageIndicator.setVisibility(View.GONE);
291293

292294
initializeCreateOrEditTransaction();
293295
} else { //load the transactions list
294296
mSectionHeaderTransactions.setVisibility(View.GONE);
295297

296298
PagerAdapter pagerAdapter = new AccountViewPagerAdapter(getSupportFragmentManager());
297-
pager.setAdapter(pagerAdapter);
298-
mTitlePageIndicator.setViewPager(pager);
299+
mPager.setAdapter(pagerAdapter);
300+
mTitlePageIndicator.setViewPager(mPager);
299301

300-
pager.setCurrentItem(INDEX_TRANSACTIONS_FRAGMENT);
302+
mPager.setCurrentItem(INDEX_TRANSACTIONS_FRAGMENT);
301303
}
302304

303305
// done creating, activity now running
@@ -471,7 +473,16 @@ protected void onDestroy() {
471473
mAccountsCursor.close();
472474
mAccountsDbAdapter.close();
473475
}
474-
476+
477+
/**
478+
* Returns the current fragment (either sub-accounts, or transactions) displayed in the activity
479+
* @return Current fragment displayed by the view pager
480+
*/
481+
public Fragment getCurrentPagerFragment(){
482+
int index = mPager.getCurrentItem();
483+
return (Fragment) mFragmentPageReferenceMap.get(index);
484+
}
485+
475486
/**
476487
* Returns the global unique ID of the current account
477488
* @return GUID of the current account

integration-tests/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
<description>Instrumentation tests for Gnucash for Android</description>
2828

2929
<properties>
30-
<robotium.version>4.2</robotium.version>
30+
<robotium.version>5.2.1</robotium.version>
3131
<spoon-client.version>1.0.5</spoon-client.version>
3232
<fest-android.version>1.0.6</fest-android.version>
3333
<android.device>usb</android.device>

integration-tests/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
<resources>
33

44
<string name="hello">Hello World!</string>
5-
<string name="app_name">GnucashMobileTest</string>
5+
<string name="app_name">GnuCash Android Integration Tests</string>
66

77
</resources>

integration-tests/src/org/gnucash/android/test/db/TransactionsDbAdapterTest.java

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,19 @@
33
import java.util.List;
44

55
import org.gnucash.android.model.Account;
6+
import org.gnucash.android.model.Money;
7+
import org.gnucash.android.model.Split;
68
import org.gnucash.android.model.Transaction;
79
import org.gnucash.android.db.AccountsDbAdapter;
810
import org.gnucash.android.db.TransactionsDbAdapter;
911

1012
import android.test.AndroidTestCase;
1113

1214
public class TransactionsDbAdapterTest extends AndroidTestCase {
13-
private static final String ALPHA_ACCOUNT_NAME = "Alpha";
14-
private static final String BRAVO_ACCOUNT_NAME = "Bravo";
15-
private static final String ALPHA_ACCOUNT_UID = "alpha-team";
16-
15+
private static final String ALPHA_ACCOUNT_NAME = "Alpha";
16+
private static final String BRAVO_ACCOUNT_NAME = "Bravo";
17+
private static final String ALPHA_ACCOUNT_UID = "alpha-team";
18+
private static final String BRAVO_ACCOUNT_UID = "bravo-team";
1719
private TransactionsDbAdapter mAdapter;
1820

1921
@Override
@@ -23,19 +25,28 @@ protected void setUp() throws Exception {
2325
AccountsDbAdapter accountsAdapter = new AccountsDbAdapter(mContext);
2426
Account first = new Account(ALPHA_ACCOUNT_NAME);
2527
first.setUID(ALPHA_ACCOUNT_UID);
28+
Account second = new Account(BRAVO_ACCOUNT_NAME);
29+
second.setUID(BRAVO_ACCOUNT_UID);
30+
31+
accountsAdapter.addAccount(first);
32+
accountsAdapter.addAccount(second);
33+
2634
Transaction t1 = new Transaction("T800");
2735
t1.setTime(System.currentTimeMillis() - 10000);
36+
Split split = new Split(Money.getZeroInstance(), ALPHA_ACCOUNT_UID);
37+
t1.addSplit(split);
38+
t1.addSplit(split.createPair(BRAVO_ACCOUNT_UID));
39+
2840
Transaction t2 = new Transaction( "T1000");
2941
t2.setTime(System.currentTimeMillis());
30-
first.addTransaction(t1);
31-
first.addTransaction(t2);
32-
33-
Account second = new Account(BRAVO_ACCOUNT_NAME);
34-
Transaction t = new Transaction( "buyout");
35-
second.addTransaction(t);
36-
37-
accountsAdapter.addAccount(second);
38-
accountsAdapter.addAccount(first);
42+
Split split2 = new Split(new Money("23.50"), BRAVO_ACCOUNT_UID);
43+
t2.addSplit(split2);
44+
t2.addSplit(split2.createPair(ALPHA_ACCOUNT_UID));
45+
46+
TransactionsDbAdapter transactionsDbAdapter = new TransactionsDbAdapter(mContext);
47+
transactionsDbAdapter.addTransaction(t1);
48+
transactionsDbAdapter.addTransaction(t2);
49+
3950
}
4051

4152
public void testTransactionsAreTimeSorted(){

0 commit comments

Comments
 (0)