Skip to content

Commit

Permalink
Added test for findAll searching for String and Long (issue #16).
Browse files Browse the repository at this point in the history
  • Loading branch information
nmihajlovski committed May 23, 2012
1 parent 66e7d0b commit a0ace99
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/tightdb/lib/AbstractColumn.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ protected Query query(TableQuery tableQuery) {
}

protected Cursor cursor(long position) {
return position >= 0 ? AbstractCursor.createCursor(types.getCursorClass(), rowset, position) : null;
return (position >= 0 && position < rowset.size()) ? AbstractCursor.createCursor(types.getCursorClass(), rowset, position) : null;
}

protected View view(TableViewBase viewBase) {
Expand Down
24 changes: 21 additions & 3 deletions src/test/java/com/tightdb/lib/TableTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tightdb.lib;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;

import java.util.Date;

Expand All @@ -9,6 +10,7 @@

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

public class TableTest {

Expand All @@ -23,7 +25,7 @@ public void init() {
employees = new EmployeeTable();

employees.add(NAME0, "Doe", 10000, true, new byte[] { 1, 2, 3 }, new Date(), "extra");
employees.add(NAME2, "B. Good", 20000, true, new byte[] { 1, 2, 3 }, new Date(), true);
employees.add(NAME2, "B. Good", 10000, true, new byte[] { 1, 2, 3 }, new Date(), true);
employees.insert(1, NAME1, "Mihajlovski", 30000, false, new byte[] { 4, 5 }, new Date(), 1234);
}

Expand Down Expand Up @@ -69,9 +71,25 @@ public void shouldAllowMixedValues() throws IllegalAccessException {
public void shouldFindFirstRecordByColumnValue() throws IllegalAccessException {
Employee record1 = employees.firstName.findFirst(NAME1);
assertEquals(1, record1.getPosition());

Employee record2 = employees.salary.findFirst(10000);
assertEquals(0, record2.getPosition());

Employee record3 = employees.salary.findFirst(12345);
assertNull(record3);
}

@Test
public void shouldFindAllRecordsByColumnValue() throws IllegalAccessException {
EmployeeView view1 = employees.firstName.findAll(NAME1);
assertEquals(1, view1.size());

EmployeeView view2 = employees.salary.findAll(10000);
assertEquals(2, view2.size());

EmployeeView view3 = employees.salary.findAll(12345);
assertEquals(0, view3.size());

Employee record2 = employees.salary.findFirst(20000);
assertEquals(2, record2.getPosition());
}

}

0 comments on commit a0ace99

Please sign in to comment.