- Adding a small test to count transaction list items
This commit is contained in:
parent
09b6f75a1f
commit
7306652dda
5 changed files with 115 additions and 29 deletions
|
@ -27,12 +27,15 @@ android {
|
|||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
//androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
androidTestCompile('com.android.support.test.espresso:espresso-core:3.0.1', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
compile 'com.android.support:appcompat-v7:26.+'
|
||||
compile 'com.android.support:appcompat-v7:26.1.0'
|
||||
compile 'com.android.support.constraint:constraint-layout:1.0.2'
|
||||
testCompile 'junit:junit:4.12'
|
||||
testCompile 'org.mockito:mockito-core:1.10.19'
|
||||
//testCompile 'com.android.support.test:runner:1.0.1'
|
||||
|
||||
compile "android.arch.lifecycle:runtime:1.0.0-alpha9-1"
|
||||
compile "android.arch.lifecycle:extensions:1.0.0-alpha9-1"
|
||||
|
|
|
@ -0,0 +1,32 @@
|
|||
package carbon.crypto.com.carbon.Assertions;
|
||||
|
||||
import android.support.test.espresso.NoMatchingViewException;
|
||||
import android.support.test.espresso.ViewAssertion;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.view.View;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 19/9/2017.
|
||||
*/
|
||||
|
||||
public class RecyclerViewItemsCountAssertion implements ViewAssertion {
|
||||
private final int expectedCount;
|
||||
|
||||
public RecyclerViewItemsCountAssertion(int expectedCount) {
|
||||
this.expectedCount = expectedCount;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void check(View view, NoMatchingViewException noViewFoundException) {
|
||||
if (noViewFoundException != null) {
|
||||
throw noViewFoundException;
|
||||
}
|
||||
|
||||
RecyclerView recyclerView = (RecyclerView) view;
|
||||
RecyclerView.Adapter adapter = recyclerView.getAdapter();
|
||||
assertThat(adapter.getItemCount(), is(expectedCount));
|
||||
}
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package carbon.crypto.com.carbon;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Instrumentation test, which will execute on an Android device.
|
||||
*
|
||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class ExampleInstrumentedTest {
|
||||
@Test
|
||||
public void useAppContext() throws Exception {
|
||||
// Context of the app under test.
|
||||
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||
|
||||
assertEquals("carbon.crypto.com.carbon", appContext.getPackageName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
package carbon.crypto.com.carbon;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import android.support.test.InstrumentationRegistry;
|
||||
import android.support.test.rule.ActivityTestRule;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import carbon.crypto.com.carbon.Assertions.RecyclerViewItemsCountAssertion;
|
||||
import cy.agorise.crystalwallet.IntroActivity;
|
||||
import cy.agorise.crystalwallet.R;
|
||||
import cy.agorise.crystalwallet.dao.CrystalDatabase;
|
||||
import cy.agorise.crystalwallet.models.CryptoCoinTransaction;
|
||||
|
||||
import static android.support.test.espresso.Espresso.onView;
|
||||
import static android.support.test.espresso.matcher.ViewMatchers.withId;
|
||||
|
||||
/**
|
||||
* Created by Henry Varona on 19/9/2017.
|
||||
*/
|
||||
@RunWith(AndroidJUnit4.class)
|
||||
public class TransactionListTest {
|
||||
CrystalDatabase db;
|
||||
|
||||
@Before
|
||||
public void addingTransactions(){
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
this.db = CrystalDatabase.getAppDatabase(InstrumentationRegistry.getTargetContext());
|
||||
cal.set(2017,01,01,01,01,01);
|
||||
CryptoCoinTransaction newTransaction = new CryptoCoinTransaction();
|
||||
newTransaction.setAmount(1);
|
||||
newTransaction.setFrom("friend1");
|
||||
newTransaction.setTo("me1");
|
||||
newTransaction.setDate(cal.getTime());
|
||||
db.transactionDao().insertTransaction(newTransaction);
|
||||
|
||||
cal.set(2017,02,02,02,02,02);
|
||||
newTransaction = new CryptoCoinTransaction();
|
||||
newTransaction.setAmount(2);
|
||||
newTransaction.setFrom("friend2");
|
||||
newTransaction.setTo("me2");
|
||||
newTransaction.setDate(cal.getTime());
|
||||
db.transactionDao().insertTransaction(newTransaction);
|
||||
|
||||
cal.set(2017,03,03,03,03,03);
|
||||
newTransaction = new CryptoCoinTransaction();
|
||||
newTransaction.setAmount(3);
|
||||
newTransaction.setFrom("friend3");
|
||||
newTransaction.setTo("me3");
|
||||
newTransaction.setDate(cal.getTime());
|
||||
db.transactionDao().insertTransaction(newTransaction);
|
||||
}
|
||||
|
||||
@Rule
|
||||
public ActivityTestRule<IntroActivity> activityTestRule = new ActivityTestRule<IntroActivity>(IntroActivity.class);
|
||||
|
||||
@Test
|
||||
public void numberOfTransactionsInList(){
|
||||
onView(withId(R.id.transactionListView)).check(new RecyclerViewItemsCountAssertion(3));
|
||||
}
|
||||
|
||||
@After
|
||||
public void deleteTransactions(){
|
||||
this.db.transactionDao().deleteAllTransactions();
|
||||
}
|
||||
}
|
|
@ -25,4 +25,7 @@ public interface TransactionDao {
|
|||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
public void insertTransaction(CryptoCoinTransaction... transactions);
|
||||
|
||||
@Query("DELETE FROM crypto_coin_transaction")
|
||||
public void deleteAllTransactions();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue