View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.juneau.objecttools;
18  
19  import static org.apache.juneau.TestUtils.*;
20  import static org.junit.jupiter.api.Assertions.*;
21  
22  import org.apache.juneau.*;
23  import org.junit.jupiter.api.*;
24  
25  /**
26   * Tests the PojoPaginator class.
27   */
28  class ObjectPaginator_Test extends TestBase {
29  
30  	ObjectPaginator op = ObjectPaginator.create();
31  	BeanSession bs = BeanContext.DEFAULT_SESSION;
32  
33  	//-----------------------------------------------------------------------------------------------------------------
34  	// Null input
35  	//-----------------------------------------------------------------------------------------------------------------
36  
37  	@Test void a01_nullInput() {
38  		assertNull(op.run(bs, null, null));
39  	}
40  
41  	@Test void a02_nonCollectionInput() {
42  		assertEquals("foo", op.run(bs, "foo", PageArgs.create(1, 3)));
43  	}
44  
45  	//-----------------------------------------------------------------------------------------------------------------
46  	// Arrays
47  	//-----------------------------------------------------------------------------------------------------------------
48  
49  	@Test void b01_arrays_basic() {
50  		var in = new int[]{1,2,3};
51  		assertList(op.run(in, 0, 3), 1,2,3);
52  		assertList(op.run(in, 1, 3), 2,3);
53  		assertList(op.run(in, 1, 1), 2);
54  		assertList(op.run(in, 4, 1));
55  		assertList(op.run(in, 0, 0));
56  
57  		var in2 = a("1","2","3");
58  		assertList(op.run(in2, 1, 1), "2");
59  
60  		var in3 = new boolean[]{false,true,false};
61  		assertList(op.run(in3, 1, 1), true);
62  
63  		var in4 = new byte[]{1,2,3};
64  		assertList(op.run(in4, 1, 1), (byte)2);
65  
66  		var in5 = new char[]{'1','2','3'};
67  		assertList(op.run(in5, 1, 1), '2');
68  
69  		var in6 = new double[]{1,2,3};
70  		assertList(op.run(in6, 1, 1), (double)2);
71  
72  		var in7 = new float[]{1,2,3};
73  		assertList(op.run(in7, 1, 1), (float)2);
74  
75  		var in8 = new long[]{1,2,3};
76  		assertList(op.run(in8, 1, 1), (long)2);
77  
78  		var in9 = new short[]{1,2,3};
79  		assertList(op.run(in9, 1, 1), (short)2);
80  	}
81  
82  	//-----------------------------------------------------------------------------------------------------------------
83  	// Collections
84  	//-----------------------------------------------------------------------------------------------------------------
85  
86  	@Test void c01_collections_basic() {
87  		var in = list(1,2,3);
88  		assertList(op.run(in, 0, 3), 1,2,3);
89  		assertList(op.run(in, 1, 3), 2,3);
90  		assertList(op.run(in, 1, 1), 2);
91  		assertList(op.run(in, 4, 1));
92  		assertList(op.run(in, 0, 0));
93  
94  		var in2 = set(1,2,3);
95  		assertList(op.run(in2, 0, 3), 1,2,3);
96  		assertList(op.run(in2, 1, 3), 2,3);
97  		assertList(op.run(in2, 1, 1), 2);
98  		assertList(op.run(in2, 4, 1));
99  		assertList(op.run(in2, 0, 0));
100 	}
101 }