Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit 6c8329f

Browse files
author
Evgenii Kanivets
committed
#17[1h]. Add tests for AccountRepo.
1 parent 182e479 commit 6c8329f

File tree

3 files changed

+66
-60
lines changed

3 files changed

+66
-60
lines changed

app/build.gradle

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,19 @@ android {
4444
}
4545

4646
dependencies {
47-
compile fileTree(include: ['*.jar'], dir: 'libs')
47+
compile fileTree(dir: 'libs', include: ['*.jar'])
4848
compile 'com.android.support:support-v4:23.0.0'
4949
compile 'com.android.support:appcompat-v7:23.0.0'
50-
compile 'junit:junit:4.12'
51-
compile 'org.mockito:mockito-core:2.0.2-beta'
5250
compile 'com.jakewharton:butterknife:7.0.1'
53-
5451
compile 'com.google.dagger:dagger:2.0.1'
52+
5553
apt 'com.google.dagger:dagger-compiler:2.0.1'
5654
provided 'org.glassfish:javax.annotation:10.0-b28'
5755

5856
testCompile 'junit:junit:4.12'
57+
testCompile 'org.mockito:mockito-core:2.0.43-beta'
58+
59+
androidTestCompile "com.crittercism.dexmaker:dexmaker:1.4"
60+
androidTestCompile "com.crittercism.dexmaker:dexmaker-dx:1.4"
61+
androidTestCompile "com.crittercism.dexmaker:dexmaker-mockito:1.4"
5962
}
Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,70 @@
11
package 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
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/repo/AccountRepoTest.java

Lines changed: 0 additions & 51 deletions
This file was deleted.

0 commit comments

Comments
 (0)