Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
#17[1h]. Add tests for AccountRepo.
  • Loading branch information
Evgenii Kanivets committed Mar 1, 2016
commit 6c8329f40bad5bea6a5a8ce29f0d3b518c7827bc
11 changes: 7 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,19 @@ android {
}

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:appcompat-v7:23.0.0'
compile 'junit:junit:4.12'
compile 'org.mockito:mockito-core:2.0.2-beta'
compile 'com.jakewharton:butterknife:7.0.1'

compile 'com.google.dagger:dagger:2.0.1'

apt 'com.google.dagger:dagger-compiler:2.0.1'
provided 'org.glassfish:javax.annotation:10.0-b28'

testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.0.43-beta'

androidTestCompile "com.crittercism.dexmaker:dexmaker:1.4"
androidTestCompile "com.crittercism.dexmaker:dexmaker-dx:1.4"
androidTestCompile "com.crittercism.dexmaker:dexmaker-mockito:1.4"
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,70 @@
package com.blogspot.e_kanivets.moneytracker.repo;

import org.junit.Test;
import android.content.ContentValues;
import android.database.Cursor;

import static org.junit.Assert.*;
import com.blogspot.e_kanivets.moneytracker.DbHelper;
import com.blogspot.e_kanivets.moneytracker.model.Account;

import junit.framework.TestCase;

import org.mockito.Mockito;

import java.util.ArrayList;
import java.util.List;

/**
* Created by evgenii_kanivets on 2/17/16.
* Android Test case.
* Created on 3/1/16.
*
* @author Evgenii Kanivets
*/
public class AccountRepoTest {
public class AccountRepoTest extends TestCase {
private AccountRepo repo;

public void setUp() throws Exception {
DbHelper mock = Mockito.mock(DbHelper.class);
repo = new AccountRepo(mock);
}

public void tearDown() throws Exception {
repo = null;
}

@Test
public void testGetTable() throws Exception {
assertEquals(DbHelper.TABLE_ACCOUNTS, repo.getTable());
}

public void testContentValues() throws Exception {
Account account = new Account(-1, "title1", 100, "NON");

ContentValues expected = new ContentValues();
expected.put(DbHelper.TITLE_COLUMN, "title1");
expected.put(DbHelper.CUR_SUM_COLUMN, 100);
expected.put(DbHelper.CURRENCY_COLUMN, "NON");

ContentValues actual = repo.contentValues(account);

assertEquals(expected, actual);
}

public void testGetListFromCursor() throws Exception {
assertEquals(new ArrayList<Account>(), repo.getListFromCursor(Mockito.mock(Cursor.class)));

Cursor mockCursor = Mockito.mock(Cursor.class);
Mockito.when(mockCursor.moveToFirst()).thenReturn(true);
Mockito.when(mockCursor.getColumnIndex(DbHelper.ID_COLUMN)).thenReturn(1);
Mockito.when(mockCursor.getColumnIndex(DbHelper.TITLE_COLUMN)).thenReturn(2);
Mockito.when(mockCursor.getColumnIndex(DbHelper.CUR_SUM_COLUMN)).thenReturn(3);
Mockito.when(mockCursor.getColumnIndex(DbHelper.CURRENCY_COLUMN)).thenReturn(4);
Mockito.when(mockCursor.getLong(1)).thenReturn(1L);
Mockito.when(mockCursor.getString(2)).thenReturn("title");
Mockito.when(mockCursor.getInt(3)).thenReturn(100);
Mockito.when(mockCursor.getString(4)).thenReturn("NON");

List<Account> expected = new ArrayList<>();
expected.add(new Account(1, "title", 100, "NON"));

assertEquals(expected, repo.getListFromCursor(mockCursor));
}
}

This file was deleted.