3636import org .gnucash .android .db .TransactionsDbAdapter ;
3737import org .gnucash .android .model .Account ;
3838import org .gnucash .android .model .Money ;
39- import org .gnucash .android .model .Split ;
40- import org .gnucash .android .model .Transaction ;
4139import org .gnucash .android .receivers .AccountCreator ;
4240import org .gnucash .android .ui .account .AccountsActivity ;
4341import org .gnucash .android .ui .account .AccountsListFragment ;
6058import static android .support .test .espresso .matcher .ViewMatchers .isNotChecked ;
6159import static android .support .test .espresso .matcher .ViewMatchers .withId ;
6260import static android .support .test .espresso .matcher .ViewMatchers .withText ;
63- import static org .assertj .android .api .Assertions .assertThat ;
6461import static org .assertj .core .api .Assertions .assertThat ;
6562import static org .hamcrest .Matchers .allOf ;
6663import static org .hamcrest .Matchers .not ;
@@ -98,6 +95,7 @@ public void setUp() throws Exception {
9895 mSplitsDbAdapter = new SplitsDbAdapter (mDb );
9996 mTransactionsDbAdapter = new TransactionsDbAdapter (mDb , mSplitsDbAdapter );
10097 mAccountsDbAdapter = new AccountsDbAdapter (mDb , mTransactionsDbAdapter );
98+ mAccountsDbAdapter .deleteAllRecords (); //clear the data
10199
102100 Account account = new Account (DUMMY_ACCOUNT_NAME );
103101 account .setUID (DUMMY_ACCOUNT_UID );
@@ -218,8 +216,8 @@ public void testChangeParentAccount() {
218216 @ Test
219217 public void testEditAccount (){
220218 String editedAccountName = "Edited Account" ;
221- // onView(withText(DUMMY_ACCOUNT_NAME)).perform(longClick() );
222- onView (withId (R .id .primary_text )).perform (longClick ());
219+ sleep ( 2000 );
220+ onView (withId (R .id .primary_text )).perform (longClick ());
223221 onView (withId (R .id .context_menu_edit_accounts )).perform (click ());
224222
225223 onView (withId (R .id .fragment_account_form )).check (matches (isDisplayed ()));
@@ -235,28 +233,34 @@ public void testEditAccount(){
235233 assertThat (latest .getCurrency ().getCurrencyCode ()).isEqualTo (DUMMY_ACCOUNT_CURRENCY_CODE );
236234 }
237235
236+ /**
237+ * Sleep the thread for a specified period
238+ * @param millis Duration to sleep in milliseconds
239+ */
240+ private void sleep (long millis ) {
241+ try {
242+ Thread .sleep (millis );
243+ } catch (InterruptedException e ) {
244+ e .printStackTrace ();
245+ }
246+ }
247+
238248 //TODO: Add test for moving content of accounts before deleting it
239249 @ Test (expected = IllegalArgumentException .class )
240- public void testDeleteAccount () {
241- Transaction transaction = new Transaction ("hats" );
242- transaction .addSplit (new Split (Money .getZeroInstance (), DUMMY_ACCOUNT_UID ));
243- mTransactionsDbAdapter .addTransaction (transaction );
244-
245- onView (withText (DUMMY_ACCOUNT_NAME )).perform (longClick ());
250+ public void testDeleteSimpleAccount () {
251+ sleep (2000 );
252+ onView (withId (R .id .primary_text )).perform (longClick ());
246253 onView (withId (R .id .context_menu_delete )).perform (click ());
247254
248255 //the account has no sub-accounts
249- onView (withId (R .id .accounts_options )).check (matches (not (isDisplayed ())));
250- onView (withId (R .id .transactions_options )).check (matches (isDisplayed ()));
256+ // onView(withId(R.id.accounts_options)).check(matches(not(isDisplayed())));
257+ // onView(withId(R.id.transactions_options)).check(matches(isDisplayed()));
251258
252- onView (withText (R .string .label_delete_transactions )).perform (click ());
253- onView (withId (R .id .btn_save )).perform (click ());
259+ // onView(withText(R.string.label_delete_transactions)).perform(click());
260+ // onView(withId(R.id.btn_save)).perform(click());
254261
255262 //should throw expected exception
256- mAccountsDbAdapter .getID (DUMMY_ACCOUNT_UID );
257-
258- List <Transaction > transactions = mTransactionsDbAdapter .getAllTransactionsForAccount (DUMMY_ACCOUNT_UID );
259- assertThat (transactions ).isEmpty ();
263+ mAccountsDbAdapter .getID (DUMMY_ACCOUNT_UID );;
260264 }
261265
262266 //TODO: Test import of account file
@@ -281,8 +285,6 @@ public void testIntentAccountCreation(){
281285 @ After
282286 public void tearDown () throws Exception {
283287 mAcccountsActivity .finish ();
284- Thread .sleep (1000 );
285- mAccountsDbAdapter .deleteAllRecords (); //clear the data
286288 super .tearDown ();
287289 }
288290
0 commit comments