Skip to content

Commit

Permalink
Wrote unit test for cursor navigation (issue #26).
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed May 21, 2012
1 parent 15b71ea commit 5229964
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
0.7.0
</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.10</version>
</dependency>
</dependencies>

<build>
Expand Down
65 changes: 65 additions & 0 deletions src/test/java/com/tightdb/lib/AbstractNavigationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.tightdb.lib;

import static org.junit.Assert.*;

import org.junit.Test;

import com.tightdb.generated.Employee;
import com.tightdb.generated.EmployeeQuery;
import com.tightdb.generated.EmployeeView;

public abstract class AbstractNavigationTest {

protected abstract AbstractRowset<Employee, EmployeeView, EmployeeQuery> getTableOrView();

@Test
public void shouldNavigateToFirstRecord() {
Employee first = getTableOrView().first();

assertEquals(0, first.getPosition());
}

@Test
public void shouldNavigateToLastRecord() {
Employee last = getTableOrView().last();

assertEquals(getTableOrView().size() - 1, last.getPosition());
}

@Test
public void shouldNavigateToNextRecord() {
Employee e = getTableOrView().at(0).next();

assertEquals(1, e.getPosition());
}

@Test
public void shouldNavigateToPreviousRecord() {
Employee e = getTableOrView().at(1).previous();

assertEquals(0, e.getPosition());
}

@Test
public void shouldNavigateAfterSpecifiedRecords() {
Employee e = getTableOrView().at(0).after(2);

assertEquals(2, e.getPosition());
}

@Test
public void shouldNavigateBeforeSpecifiedRecords() {
Employee e = getTableOrView().at(2).before(2);

assertEquals(0, e.getPosition());
}

@Test
public void shouldReturnNullOnInvalidPosition() {
assertNull(getTableOrView().at(0).previous());
assertNull(getTableOrView().last().next());
assertNull(getTableOrView().at(1).before(2));
assertNull(getTableOrView().at(2).after(1000));
}

}
27 changes: 27 additions & 0 deletions src/test/java/com/tightdb/lib/TableNavigationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.tightdb.lib;

import java.util.Date;

import com.tightdb.generated.Employee;
import com.tightdb.generated.EmployeeQuery;
import com.tightdb.generated.EmployeeTable;
import com.tightdb.generated.EmployeeView;

public class TableNavigationTest extends AbstractNavigationTest {

private EmployeeTable employees;

public TableNavigationTest() {
employees = new EmployeeTable();

employees.add("John", "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra");
employees.add("Johny", "B. Good", 20000, true, new byte[] { 1, 2, 3 }, new Date(), true);
employees.insert(1, "Nikolche", "Mihajlovski", 30000, false, new byte[] { 4, 5 }, new Date(), 1234.56);
}

@Override
protected AbstractRowset<Employee, EmployeeView, EmployeeQuery> getTableOrView() {
return employees;
}

}
29 changes: 29 additions & 0 deletions src/test/java/com/tightdb/lib/ViewNavigationTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.tightdb.lib;

import java.util.Date;

import com.tightdb.generated.Employee;
import com.tightdb.generated.EmployeeQuery;
import com.tightdb.generated.EmployeeTable;
import com.tightdb.generated.EmployeeView;

public class ViewNavigationTest extends AbstractNavigationTest {

private EmployeeView view;

public ViewNavigationTest() {
EmployeeTable employees = new EmployeeTable();

employees.add("John", "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra");
employees.add("Johny", "B. Good", 20000, true, new byte[] { 1, 2, 3 }, new Date(), true);
employees.insert(1, "Nikolche", "Mihajlovski", 30000, false, new byte[] { 4, 5 }, new Date(), 1234.56);

view = employees.firstName.startsWith("").findAll();
}

@Override
protected AbstractRowset<Employee, EmployeeView, EmployeeQuery> getTableOrView() {
return view;
}

}

0 comments on commit 5229964

Please sign in to comment.