Skip to content

Commit

Permalink
Fix #167 query/deletebulk -m 0 throws exception
Browse files Browse the repository at this point in the history
  • Loading branch information
gschueler committed Apr 27, 2018
1 parent 7588960 commit adb561a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/main/java/org/rundeck/client/api/model/Paging.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void setOffset(int offset) {
@Override
public String toString() {
return String.format(
"Page [%d/%d] results %d - %d (of %d by %d).",
"Page [%d/%d] results %d - %d (of %d by %d)",
pagenum(),
maxPagenum(),
offset + 1,
Expand Down Expand Up @@ -93,13 +93,18 @@ public String moreResults(final String offsetArg, final String extra) {
}

public int pagenum() {
if (max < 1) {
return 1;
}

int oflow = offset % max;
return 1 + (offset - oflow) / max + (oflow > 0 ? 1 : 0);
}

public int maxPagenum() {

if (max < 1) {
return 1;
}
int oflow = total % max;
return (total - oflow) / max + (oflow > 0 ? 1 : 0);

Expand Down
15 changes: 15 additions & 0 deletions src/test/groovy/org/rundeck/client/api/model/PagingSpec.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.rundeck.client.api.model

import spock.lang.Specification

class PagingSpec extends Specification {
def "tostring"() {
expect:
expect == new Paging(max: max, total: total, count: count, offset: offset).toString()
where:
max | total | count | offset | expect
20 | 0 | 0 | 0 | 'Page [1/0] results 1 - 0 (of 0 by 20)'
20 | 1 | 1 | 0 | 'Page [1/1] results 1 - 1 (of 1 by 20)'
0 | 1 | 1 | 0 | 'Page [1/1] results 1 - 1 (of 1 by 0)'
}
}

0 comments on commit adb561a

Please sign in to comment.