11package com .blogspot .e_kanivets .moneytracker .repo ;
22
3- import org .junit .Test ;
3+ import android .content .ContentValues ;
4+ import android .database .Cursor ;
45
5- import static org .junit .Assert .*;
6+ import com .blogspot .e_kanivets .moneytracker .DbHelper ;
7+ import com .blogspot .e_kanivets .moneytracker .model .Account ;
8+
9+ import junit .framework .TestCase ;
10+
11+ import org .mockito .Mockito ;
12+
13+ import java .util .ArrayList ;
14+ import java .util .List ;
615
716/**
8- * Created by evgenii_kanivets on 2/17/16.
17+ * Android Test case.
18+ * Created on 3/1/16.
19+ *
20+ * @author Evgenii Kanivets
921 */
10- public class AccountRepoTest {
22+ public class AccountRepoTest extends TestCase {
23+ private AccountRepo repo ;
24+
25+ public void setUp () throws Exception {
26+ DbHelper mock = Mockito .mock (DbHelper .class );
27+ repo = new AccountRepo (mock );
28+ }
29+
30+ public void tearDown () throws Exception {
31+ repo = null ;
32+ }
1133
12- @ Test
1334 public void testGetTable () throws Exception {
35+ assertEquals (DbHelper .TABLE_ACCOUNTS , repo .getTable ());
36+ }
37+
38+ public void testContentValues () throws Exception {
39+ Account account = new Account (-1 , "title1" , 100 , "NON" );
40+
41+ ContentValues expected = new ContentValues ();
42+ expected .put (DbHelper .TITLE_COLUMN , "title1" );
43+ expected .put (DbHelper .CUR_SUM_COLUMN , 100 );
44+ expected .put (DbHelper .CURRENCY_COLUMN , "NON" );
45+
46+ ContentValues actual = repo .contentValues (account );
47+
48+ assertEquals (expected , actual );
49+ }
50+
51+ public void testGetListFromCursor () throws Exception {
52+ assertEquals (new ArrayList <Account >(), repo .getListFromCursor (Mockito .mock (Cursor .class )));
53+
54+ Cursor mockCursor = Mockito .mock (Cursor .class );
55+ Mockito .when (mockCursor .moveToFirst ()).thenReturn (true );
56+ Mockito .when (mockCursor .getColumnIndex (DbHelper .ID_COLUMN )).thenReturn (1 );
57+ Mockito .when (mockCursor .getColumnIndex (DbHelper .TITLE_COLUMN )).thenReturn (2 );
58+ Mockito .when (mockCursor .getColumnIndex (DbHelper .CUR_SUM_COLUMN )).thenReturn (3 );
59+ Mockito .when (mockCursor .getColumnIndex (DbHelper .CURRENCY_COLUMN )).thenReturn (4 );
60+ Mockito .when (mockCursor .getLong (1 )).thenReturn (1L );
61+ Mockito .when (mockCursor .getString (2 )).thenReturn ("title" );
62+ Mockito .when (mockCursor .getInt (3 )).thenReturn (100 );
63+ Mockito .when (mockCursor .getString (4 )).thenReturn ("NON" );
64+
65+ List <Account > expected = new ArrayList <>();
66+ expected .add (new Account (1 , "title" , 100 , "NON" ));
1467
68+ assertEquals (expected , repo .getListFromCursor (mockCursor ));
1569 }
1670}
0 commit comments