Skip to content

Commit

Permalink
Updated Robotium tests
Browse files Browse the repository at this point in the history
Splits set default transaction type based on sign of amount
  • Loading branch information
codinguser committed Feb 9, 2015
1 parent 17b4b8b commit f6a157c
Show file tree
Hide file tree
Showing 13 changed files with 269 additions and 195 deletions.
2 changes: 1 addition & 1 deletion app/res/layout/fragment_new_account.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
android:ellipsize="start"
android:hint="@string/label_account_name"
style="@style/ListItemText">
<requestFocus />
<!-- <requestFocus /> -->
</EditText>

<TextView
Expand Down
26 changes: 21 additions & 5 deletions app/src/org/gnucash/android/db/TransactionsDbAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,8 @@ public Transaction getTransaction(long rowId){
}

/**
* Returns a cursor to a set of all transactions for the account with UID <code>accountUID</code>
* or for which this account is the origin account (double entry)
* i.e <code>accountUID</code> is double entry account UID
* Returns a cursor to a set of all transactions which have a split belonging to the accound with unique ID
* <code>accountUID</code>.
* @param accountUID UID of the account whose transactions are to be retrieved
* @return Cursor holding set of transactions for particular account
* @throws java.lang.IllegalArgumentException if the accountUID is null
Expand Down Expand Up @@ -521,8 +520,25 @@ public int getTransactionsCount(long accountId){
}
return count;
}

/**

/**
* Returns the number of transactions belonging to an account
* @param accountUID GUID of the account
* @return Number of transactions with splits in the account
*/
public int getTransactionsCount(String accountUID){
Cursor cursor = fetchAllTransactionsForAccount(accountUID);
int count = 0;
if (cursor == null)
return count;
else {
count = cursor.getCount();
cursor.close();
}
return count;
}

/**
* Returns the total number of transactions in the database
* regardless of what account they belong to
* @return Number of transaction in the database
Expand Down
1 change: 1 addition & 0 deletions app/src/org/gnucash/android/model/Split.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public Split(Money amount, String accountUID){
setAmount(amount);
setAccountUID(accountUID);
mUID = UUID.randomUUID().toString().replaceAll("-","");
mSplitType = amount.isNegative() ? TransactionType.DEBIT : TransactionType.CREDIT;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
getSherlockActivity().getSupportActionBar().setTitle(R.string.title_add_account);
mCurrencySpinner = (Spinner) view.findViewById(R.id.input_currency_spinner);
mNameEditText = (EditText) view.findViewById(R.id.edit_text_account_name);
mNameEditText.requestFocus();
//mNameEditText.requestFocus();

mAccountTypeSpinner = (Spinner) view.findViewById(R.id.input_account_type_spinner);
mAccountTypeSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
Expand Down
4 changes: 4 additions & 0 deletions app/src/org/gnucash/android/ui/account/AccountsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,10 @@ public void onCreate(Bundle savedInstanceState) {

}

public void setTab(int index){
mPager.setCurrentItem(index);
}

/**
* Loads default setting for currency and performs app first-run initialization
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public class TransactionsActivity extends PassLockActivity implements
private TextView mSectionHeaderTransactions;
private TitlePageIndicator mTitlePageIndicator;

private ViewPager mPager;

private SparseArray<Refreshable> mFragmentPageReferenceMap = new SparseArray<Refreshable>();

private OnNavigationListener mTransactionListNavigationListener = new OnNavigationListener() {
Expand Down Expand Up @@ -275,7 +277,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_transactions);

ViewPager pager = (ViewPager) findViewById(R.id.pager);
mPager = (ViewPager) findViewById(R.id.pager);
mTitlePageIndicator = (TitlePageIndicator) findViewById(R.id.titles);
mSectionHeaderTransactions = (TextView) findViewById(R.id.section_header_transactions);

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

if (getIntent().getAction().equals(Intent.ACTION_INSERT_OR_EDIT)) {
pager.setVisibility(View.GONE);
mPager.setVisibility(View.GONE);
mTitlePageIndicator.setVisibility(View.GONE);

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

PagerAdapter pagerAdapter = new AccountViewPagerAdapter(getSupportFragmentManager());
pager.setAdapter(pagerAdapter);
mTitlePageIndicator.setViewPager(pager);
mPager.setAdapter(pagerAdapter);
mTitlePageIndicator.setViewPager(mPager);

pager.setCurrentItem(INDEX_TRANSACTIONS_FRAGMENT);
mPager.setCurrentItem(INDEX_TRANSACTIONS_FRAGMENT);
}

// done creating, activity now running
Expand Down Expand Up @@ -471,7 +473,16 @@ protected void onDestroy() {
mAccountsCursor.close();
mAccountsDbAdapter.close();
}


/**
* Returns the current fragment (either sub-accounts, or transactions) displayed in the activity
* @return Current fragment displayed by the view pager
*/
public Fragment getCurrentPagerFragment(){
int index = mPager.getCurrentItem();
return (Fragment) mFragmentPageReferenceMap.get(index);
}

/**
* Returns the global unique ID of the current account
* @return GUID of the current account
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
<description>Instrumentation tests for Gnucash for Android</description>

<properties>
<robotium.version>4.2</robotium.version>
<robotium.version>5.2.1</robotium.version>
<spoon-client.version>1.0.5</spoon-client.version>
<fest-android.version>1.0.6</fest-android.version>
<android.device>usb</android.device>
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
<resources>

<string name="hello">Hello World!</string>
<string name="app_name">GnucashMobileTest</string>
<string name="app_name">GnuCash Android Integration Tests</string>

</resources>
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
import java.util.List;

import org.gnucash.android.model.Account;
import org.gnucash.android.model.Money;
import org.gnucash.android.model.Split;
import org.gnucash.android.model.Transaction;
import org.gnucash.android.db.AccountsDbAdapter;
import org.gnucash.android.db.TransactionsDbAdapter;

import android.test.AndroidTestCase;

public class TransactionsDbAdapterTest extends AndroidTestCase {
private static final String ALPHA_ACCOUNT_NAME = "Alpha";
private static final String BRAVO_ACCOUNT_NAME = "Bravo";
private static final String ALPHA_ACCOUNT_UID = "alpha-team";

private static final String ALPHA_ACCOUNT_NAME = "Alpha";
private static final String BRAVO_ACCOUNT_NAME = "Bravo";
private static final String ALPHA_ACCOUNT_UID = "alpha-team";
private static final String BRAVO_ACCOUNT_UID = "bravo-team";
private TransactionsDbAdapter mAdapter;

@Override
Expand All @@ -23,19 +25,28 @@ protected void setUp() throws Exception {
AccountsDbAdapter accountsAdapter = new AccountsDbAdapter(mContext);
Account first = new Account(ALPHA_ACCOUNT_NAME);
first.setUID(ALPHA_ACCOUNT_UID);
Account second = new Account(BRAVO_ACCOUNT_NAME);
second.setUID(BRAVO_ACCOUNT_UID);

accountsAdapter.addAccount(first);
accountsAdapter.addAccount(second);

Transaction t1 = new Transaction("T800");
t1.setTime(System.currentTimeMillis() - 10000);
Split split = new Split(Money.getZeroInstance(), ALPHA_ACCOUNT_UID);
t1.addSplit(split);
t1.addSplit(split.createPair(BRAVO_ACCOUNT_UID));

Transaction t2 = new Transaction( "T1000");
t2.setTime(System.currentTimeMillis());
first.addTransaction(t1);
first.addTransaction(t2);

Account second = new Account(BRAVO_ACCOUNT_NAME);
Transaction t = new Transaction( "buyout");
second.addTransaction(t);

accountsAdapter.addAccount(second);
accountsAdapter.addAccount(first);
Split split2 = new Split(new Money("23.50"), BRAVO_ACCOUNT_UID);
t2.addSplit(split2);
t2.addSplit(split2.createPair(ALPHA_ACCOUNT_UID));

TransactionsDbAdapter transactionsDbAdapter = new TransactionsDbAdapter(mContext);
transactionsDbAdapter.addTransaction(t1);
transactionsDbAdapter.addTransaction(t2);

}

public void testTransactionsAreTimeSorted(){
Expand Down
Loading

0 comments on commit f6a157c

Please sign in to comment.