File tree Expand file tree Collapse file tree 2 files changed +22
-0
lines changed
main/java/org/kohsuke/stapler/export
test/java/org/kohsuke/stapler/export Expand file tree Collapse file tree 2 files changed +22
-0
lines changed Original file line number Diff line number Diff line change 22
33import java .util .Arrays ;
44import java .util .Collection ;
5+ import java .util .Collections ;
56import java .util .Iterator ;
67import java .util .List ;
78
@@ -28,6 +29,9 @@ public <T> List<T> apply(List<T> s) {
2829 s = s .subList (0 , max );
2930 }
3031 if (min > 0 ) {
32+ if (min >= s .size ()) {
33+ return Collections .emptyList ();
34+ }
3135 s = s .subList (min , s .size ());
3236 }
3337 return s ;
Original file line number Diff line number Diff line change 22
33import static org .hamcrest .MatcherAssert .assertThat ;
44import static org .hamcrest .Matchers .contains ;
5+ import static org .hamcrest .Matchers .empty ;
6+ import static org .hamcrest .Matchers .emptyIterable ;
57
68import java .util .Arrays ;
79import java .util .LinkedHashSet ;
@@ -38,4 +40,20 @@ void minOnlyRange() {
3840 assertThat (r .apply (list ), contains ("e" , "f" ));
3941 assertThat (r .apply (set ), contains ("e" , "f" ));
4042 }
43+
44+ @ Test
45+ void rangeBeyondListSizeReturnsEmpty () {
46+ Range r = new Range (10 , 20 );
47+ assertThat (r .apply (array ), empty ());
48+ assertThat (r .apply (list ), empty ());
49+ assertThat (r .apply (set ), emptyIterable ());
50+ }
51+
52+ @ Test
53+ void rangeExactlyAtBoundaryReturnsEmpty () {
54+ Range r = new Range (6 , 10 );
55+ assertThat (r .apply (array ), empty ());
56+ assertThat (r .apply (list ), empty ());
57+ assertThat (r .apply (set ), emptyIterable ());
58+ }
4159}
You can’t perform that action at this time.
0 commit comments