Skip to content

Commit

Permalink
change Selector#value() and Selector#get() to respect Selector#offset()
Browse files Browse the repository at this point in the history
  • Loading branch information
k-kagurazaka committed May 18, 2017
1 parent e8f006a commit a6410a2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ public Model value() throws NoValueException {
@Nullable
public Model getOrNull(@IntRange(from = 0) long position) {
return conn.querySingle(getSchema(), getSchema().getDefaultResultColumns(),
getWhereClause(), getBindArgs(), groupBy, having, orderBy, position);
getWhereClause(), getBindArgs(), groupBy, having, orderBy, position + Math.max(offset, 0));
}

@NonNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,14 @@ public void valueOrNull() throws Exception {
assertThat(book, is(nullValue()));
}

@Test
public void valueWithOffset() throws Exception {
Book book = db.selectFromBook().offset(1).value();

assertThat(book.title, is("friday"));
assertThat(book.content, is("apple"));
}

@Test(expected = NoValueException.class)
public void valueIfNull() throws Exception {
db.deleteFromBook().execute();
Expand Down Expand Up @@ -191,6 +199,14 @@ public void testGetOrNull() throws Exception {
assertThat(db.selectFromBook().get(10), is(nullValue()));
}

@Test
public void testGetWithOffset() throws Exception {
Book book = db.selectFromBook().offset(1).get(0);

assertThat(book.title, is("friday"));
assertThat(book.content, is("apple"));
}

@Test
public void pluck() throws Exception {
assertThat(db.selectFromBook().orderByTitleAsc().pluck(Book_Schema.INSTANCE.title),
Expand Down

0 comments on commit a6410a2

Please sign in to comment.