Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ android:

script:
- ./gradlew test --stacktrace

after_success:
- ./gradlew cobertura coveralls
10 changes: 7 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ buildscript {
}
}

plugins {
id 'net.saliman.cobertura' version '2.3.1'
id 'com.github.kt3k.coveralls' version '2.8.2'
}

cobertura.coverageFormats = ['html', 'xml'] // coveralls plugin depends on xml format report

allprojects {
repositories {
jcenter()
}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ public boolean save() {
*/
public boolean delete() {
long dbDelete = _db.getWritableDatabase().delete(getTableName(), _ID + " = " + this.getId(), null);

return dbDelete == 1;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ public class Employee extends SQLiteModel {

private static Map<String, Integer> dbColumns = null;

private String name;
private String name,
surname;

@Override
public Map<String, Integer> getDbColumns() {
if (dbColumns == null) {
dbColumns = new HashMap<>();

dbColumns.put("name", TYPE_TEXT);
dbColumns.put("surname", TYPE_TEXT);

SQLiteModel.setDBColumns(dbColumns);
}
Expand All @@ -39,4 +41,12 @@ public String getName() {
public void setName(String name) {
this.name = name;
}

public String getSurname() {
return surname;
}

public void setSurname(String surname) {
this.surname = surname;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
package ie.mavon.sqlitemodel;

import android.util.Pair;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;

import java.util.LinkedHashMap;

import ie.mavon.sqlitemodel.Models.Employee;

import static org.junit.Assert.*;
Expand All @@ -21,7 +26,16 @@ public void setUp() {
SQLiteModel.setDB(new TestDBHelper(RuntimeEnvironment.application, "testDb", null, 1));

SQLiteModel.getDbHandler().getWritableDatabase().execSQL("DROP TABLE IF EXISTS employees");
SQLiteModel.getDbHandler().getWritableDatabase().execSQL("CREATE TABLE employees (_id INTEGER PRIMARY KEY, name TEXT)");
SQLiteModel.getDbHandler().getWritableDatabase().execSQL(
"CREATE TABLE employees (_id INTEGER PRIMARY KEY, " +
"name TEXT, " +
"surname TEXT)");

SQLiteModel.getDbHandler().getWritableDatabase().execSQL("INSERT INTO employees ('name', 'surname') VALUES ('John', 'Smith')");
SQLiteModel.getDbHandler().getWritableDatabase().execSQL("INSERT INTO employees ('name', 'surname') VALUES ('Joe', 'Blogs')");
SQLiteModel.getDbHandler().getWritableDatabase().execSQL("INSERT INTO employees ('name', 'surname') VALUES ('Matt', 'Brau')");
SQLiteModel.getDbHandler().getWritableDatabase().execSQL("INSERT INTO employees ('name', 'surname') VALUES ('Niamh', 'Wager')");
SQLiteModel.getDbHandler().getWritableDatabase().execSQL("INSERT INTO employees ('name', 'surname') VALUES ('Grant', 'Walsh')");
}

@Test
Expand All @@ -33,10 +47,60 @@ public void getDatabaseName() throws Exception {
public void testExists()
{
Employee employee = new Employee();
employee.setName("Joe Blogs");
employee.setName("Joe");
assertTrue(employee.save());

assertTrue(employee.exists());
}

@Test
public void testCount()
{
Assert.assertEquals(5, new Employee().count());
}

@Test
public void testNextAutoIncrement()
{
Assert.assertEquals(6, new Employee().getNextAutoIncrement());
}

@Test
public void testGetOneById()
{
Employee matt = (Employee) new Employee().getOneById(3);
Assert.assertEquals("Matt", matt.getName());
Assert.assertEquals("Brau", matt.getSurname());
Assert.assertEquals(3, matt.getId());
}

@Test
public void testGetItemsForSelect()
{
LinkedHashMap items = new Employee().getItemsForSelect("name");

Assert.assertEquals(5, items.size());

//TODO test each item/ordering etc..
}

@Test
public void testGetItem()
{
Employee niamh = (Employee) new Employee().getItem(new Pair<String, String>("name", "Niamh"));

Assert.assertEquals(4, niamh.getId());
Assert.assertEquals("Niamh", niamh.getName());
Assert.assertEquals("Wager", niamh.getSurname());
}

@Test
public void testDelete()
{
Employee first = (Employee) new Employee().getOneById(1);
Assert.assertEquals(true, first.delete());
Assert.assertEquals(4, new Employee().count());
Assert.assertEquals(6, new Employee().getNextAutoIncrement());
Assert.assertEquals(null, new Employee().getOneById(1));
}
}