1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.criteria.impl

File RangeTest.java

 

Code metrics

0
36
11
1
119
78
11
0.31
3.27
11
1

Classes

Class Line # Actions
RangeTest 32 36 0% 11 0
1.0100%
 

Contributing tests

This file is covered by 10 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package com.xpn.xwiki.criteria.impl;
21   
22    import junit.framework.TestCase;
23   
24    import java.util.List;
25    import java.util.Arrays;
26   
27    /**
28    * Unit tests for {@link com.xpn.xwiki.criteria.impl.Range}.
29    *
30    * @version $Id: 5b401a9d996490ab4e6e7a87900559aadfc6abf7 $
31    */
 
32    public class RangeTest extends TestCase
33    {
34    /**
35    * Test for {@link com.xpn.xwiki.criteria.impl.Range#Range(int, int)}
36    */
 
37  1 toggle public void testConstructor()
38    {
39  1 doConstructorTest(0, 0);
40  1 doConstructorTest(0, 5);
41  1 doConstructorTest(0, -7);
42  1 doConstructorTest(-10, 0);
43  1 doConstructorTest(-10, 4);
44  1 doConstructorTest(-10, -1);
45    }
46   
 
47  6 toggle private void doConstructorTest(int start, int size)
48    {
49  6 Range i = new Range(start, size);
50  6 assertEquals(i.getStart(), start);
51  6 assertEquals(i.getSize(), size);
52  6 assertEquals(i.getAbsoluteStart(), Math.abs(start));
53  6 assertEquals(i.getAbsoluteSize(), Math.abs(size));
54    }
55   
56    public static final List<String> zeroToHeight =
57    Arrays.asList(new String[]{"0", "1", "2", "3", "4", "5", "6", "7", "8"});
58   
 
59  1 toggle public void testSubListWithStartZeroAndSizeZero()
60    {
61  1 Range range = new Range(0, 0);
62  1 assertEquals(range.subList(zeroToHeight), zeroToHeight);
63    }
64   
 
65  1 toggle public void testSubListWithStartZeroAndSizeOneThousand()
66    {
67  1 Range range = new Range(0, 1000);
68  1 assertEquals(range.subList(zeroToHeight), zeroToHeight);
69    }
70   
 
71  1 toggle public void testSubListWithHeadIntervalOne()
72    {
73  1 Range range = RangeFactory.createHeadRange(1);
74  1 List<String> zero = Arrays.asList(new String[]{"0"});
75  1 assertEquals(range.subList(zeroToHeight), zero);
76    }
77   
 
78  1 toggle public void testSubListWithTailIntervalOne()
79    {
80  1 Range range = RangeFactory.createTailRange(1);
81  1 List<String> height = Arrays.asList(new String[]{"8"});
82  1 assertEquals(range.subList(zeroToHeight), height);
83    }
84   
 
85  1 toggle public void testSubListWithStartZeroAndPositiveSize()
86    {
87  1 Range range = new Range(0, 4);
88  1 List<String> zeroToThree = Arrays.asList(new String[]{"0", "1", "2", "3"});
89  1 assertEquals(range.subList(zeroToHeight), zeroToThree);
90    }
91   
 
92  1 toggle public void testSubListWithStartZeroAndNegativeSize()
93    {
94  1 Range range = new Range(0, -4);
95  1 List<String> fiveToHeight = Arrays.asList(new String[]{"5", "6", "7", "8"});
96  1 assertEquals(range.subList(zeroToHeight), fiveToHeight);
97    }
98   
 
99  1 toggle public void testSubListWithStartMinusTwoAndSizeFour()
100    {
101  1 Range range = new Range(-2, 4);
102  1 List<String> sevenToHeight = Arrays.asList(new String[]{"7", "8"});
103  1 assertEquals(range.subList(zeroToHeight), sevenToHeight);
104    }
105   
 
106  1 toggle public void testSubListWithStartMinusTwoAndSizeMinusFour()
107    {
108  1 Range range = new Range(-2, -4);
109  1 List<String> threeToSix = Arrays.asList(new String[]{"3", "4", "5", "6"});
110  1 assertEquals(range.subList(zeroToHeight), threeToSix);
111    }
112   
 
113  1 toggle public void testSubListWithStartTwoAndSizeMinusFour()
114    {
115  1 Range range = new Range(2, -4);
116  1 List<String> zeroToOne = Arrays.asList(new String[]{"0", "1"});
117  1 assertEquals(range.subList(zeroToHeight), zeroToOne);
118    }
119    }