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

File DurationFactoryTest.java

 

Code metrics

0
29
15
1
148
82
15
0.52
1.93
15
1

Classes

Class Line # Actions
DurationFactoryTest 30 29 0% 15 0
1.0100%
 

Contributing tests

This file is covered by 9 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   
21    package com.xpn.xwiki.criteria.impl;
22   
23    import junit.framework.TestCase;
24    import com.xpn.xwiki.criteria.impl.Duration;
25    import com.xpn.xwiki.criteria.impl.DurationFactory;
26   
27    /**
28    * Unit tests for the {@link DurationFactory} class.
29    */
 
30    public class DurationFactoryTest extends TestCase
31    {
32    /**
33    * Test for {@link DurationFactory#DAY}
34    */
 
35  1 toggle public void testDay()
36    {
37  1 doDurationTest(DurationFactory.DAY, 0, 0, 0, 1);
38    }
39   
40    /**
41    * Test for {@link DurationFactory#WEEK}
42    */
 
43  1 toggle public void testWeek()
44    {
45  1 doDurationTest(DurationFactory.WEEK, 0, 0, 1, 0);
46    }
47   
48    /**
49    * Test for {@link DurationFactory#MONTH}
50    */
 
51  1 toggle public void testMonth()
52    {
53  1 doDurationTest(DurationFactory.MONTH, 0, 1, 0, 0);
54    }
55   
56    /**
57    * Test for {@link DurationFactory#YEAR}
58    */
 
59  1 toggle public void testYear()
60    {
61  1 doDurationTest(DurationFactory.YEAR, 1, 0, 0, 0);
62    }
63   
64    /**
65    * Test for {@link DurationFactory#createDuration(int, int, int, int)}
66    */
 
67  1 toggle public void testCreateDuration()
68    {
69  1 doCreateDurationTest(0, 0, 0, 0);
70  1 doCreateDurationTest(1, 2, 5, 4);
71  1 doCreateDurationTest(-1, -2, -3, -14);
72  1 doCreateDurationTest(0, -2, 3, 0);
73    }
74   
 
75  4 toggle private void doCreateDurationTest(int years, int months, int weeks, int days)
76    {
77  4 doDurationTest(DurationFactory.createDuration(years, months, weeks, days), years, months,
78    weeks, days);
79    }
80   
81    /**
82    * Test for {@link DurationFactory#createDays(int)}
83    */
 
84  1 toggle public void testCreateDays()
85    {
86  1 doCreateDaysTest(0);
87  1 doCreateDaysTest(-3);
88  1 doCreateDaysTest(15);
89    }
90   
 
91  3 toggle private void doCreateDaysTest(int days)
92    {
93  3 doDurationTest(DurationFactory.createDays(days), 0, 0, 0, days);
94    }
95   
96    /**
97    * Test for {@link DurationFactory#createWeeks(int)}
98    */
 
99  1 toggle public void testCreateWeeks()
100    {
101  1 doCreateWeeksTest(0);
102  1 doCreateWeeksTest(-1);
103  1 doCreateWeeksTest(5);
104    }
105   
 
106  3 toggle private void doCreateWeeksTest(int weeks)
107    {
108  3 doDurationTest(DurationFactory.createWeeks(weeks), 0, 0, weeks, 0);
109    }
110   
111    /**
112    * Test for {@link DurationFactory#createMonths(int)}
113    */
 
114  1 toggle public void testCreateMonths()
115    {
116  1 doCreateMonthsTest(0);
117  1 doCreateMonthsTest(-13);
118  1 doCreateMonthsTest(1);
119    }
120   
 
121  3 toggle private void doCreateMonthsTest(int months)
122    {
123  3 doDurationTest(DurationFactory.createMonths(months), 0, months, 0, 0);
124    }
125   
126    /**
127    * Test for {@link DurationFactory#createYears(int)}
128    */
 
129  1 toggle public void testCreateYears()
130    {
131  1 doCreateYearsTest(0);
132  1 doCreateYearsTest(-2);
133  1 doCreateYearsTest(103);
134    }
135   
 
136  3 toggle private void doCreateYearsTest(int years)
137    {
138  3 doDurationTest(DurationFactory.createYears(years), years, 0, 0, 0);
139    }
140   
 
141  20 toggle private void doDurationTest(Duration d, int years, int months, int weeks, int days)
142    {
143  20 assertEquals(d.getDays(), days);
144  20 assertEquals(d.getWeeks(), weeks);
145  20 assertEquals(d.getMonths(), months);
146  20 assertEquals(d.getYears(), years);
147    }
148    }