-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Wrote unit test for cursor navigation (issue #26).
- Loading branch information
1 parent
15b71ea
commit 5229964
Showing
4 changed files
with
126 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |