From 52299646fa9c462e4a4ec9a57b7f80dd465ea402 Mon Sep 17 00:00:00 2001 From: nikuco Date: Mon, 21 May 2012 17:18:09 +0200 Subject: [PATCH] Wrote unit test for cursor navigation (issue #26). --- pom.xml | 5 ++ .../tightdb/lib/AbstractNavigationTest.java | 65 +++++++++++++++++++ .../com/tightdb/lib/TableNavigationTest.java | 27 ++++++++ .../com/tightdb/lib/ViewNavigationTest.java | 29 +++++++++ 4 files changed, 126 insertions(+) create mode 100644 src/test/java/com/tightdb/lib/AbstractNavigationTest.java create mode 100644 src/test/java/com/tightdb/lib/TableNavigationTest.java create mode 100644 src/test/java/com/tightdb/lib/ViewNavigationTest.java diff --git a/pom.xml b/pom.xml index c0eb0aec92..418264291f 100644 --- a/pom.xml +++ b/pom.xml @@ -19,6 +19,11 @@ 0.7.0 + + junit + junit + 4.10 + diff --git a/src/test/java/com/tightdb/lib/AbstractNavigationTest.java b/src/test/java/com/tightdb/lib/AbstractNavigationTest.java new file mode 100644 index 0000000000..143cf19890 --- /dev/null +++ b/src/test/java/com/tightdb/lib/AbstractNavigationTest.java @@ -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 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)); + } + +} diff --git a/src/test/java/com/tightdb/lib/TableNavigationTest.java b/src/test/java/com/tightdb/lib/TableNavigationTest.java new file mode 100644 index 0000000000..d2768b6ad0 --- /dev/null +++ b/src/test/java/com/tightdb/lib/TableNavigationTest.java @@ -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 getTableOrView() { + return employees; + } + +} diff --git a/src/test/java/com/tightdb/lib/ViewNavigationTest.java b/src/test/java/com/tightdb/lib/ViewNavigationTest.java new file mode 100644 index 0000000000..61f7c65557 --- /dev/null +++ b/src/test/java/com/tightdb/lib/ViewNavigationTest.java @@ -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 getTableOrView() { + return view; + } + +}