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

File PropertyClassTest.java

 

Code metrics

4
20
1
1
70
34
3
0.15
20
1
3

Classes

Class Line # Actions
PropertyClassTest 33 20 0% 3 3
0.8888%
 

Contributing tests

This file is covered by 1 test. .

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.objects.classes;
21   
22    import java.util.Random;
23   
24    import org.junit.Assert;
25    import org.junit.Test;
26   
27    /**
28    * Unit tests for the base {@link PropertyClass} class.
29    *
30    * @version $Id: 29f283a4a3602e1290a7ee62ba42ccf039132771 $
31    * @since 2.4M2
32    */
 
33    public class PropertyClassTest
34    {
35    /** Test the {@link PropertyClass#compareTo(PropertyClass)} method. */
 
36  1 toggle @Test
37    public void testCompareTo()
38    {
39  1 PropertyClass one = new PropertyClass();
40  1 PropertyClass two = new PropertyClass();
41    // Random numbers to be used as property indexes.
42  1 int n1, n2;
43   
44  1 one.setName("first");
45  1 two.setName("second");
46   
47    // Since the test might randomly succeed, run it several times to be safer.
48  1 Random random = new Random();
49  21 for (int i = 0; i < 20; ++i) {
50  20 n1 = random.nextInt();
51  20 n2 = random.nextInt();
52  20 one.setNumber(n1);
53  20 two.setNumber(n2);
54   
55  20 if (n1 == n2) {
56  0 Assert.assertEquals(Math.signum(one.compareTo(two)), -1.0, 0);
57  0 Assert.assertEquals(Math.signum(two.compareTo(one)), 1.0, 0);
58    } else {
59  20 Assert.assertEquals(0, Float.compare(Math.signum(one.compareTo(two)), Math.signum(n1 - n2)));
60  20 Assert.assertEquals(0, Float.compare(Math.signum(two.compareTo(one)), Math.signum(n2 - n1)));
61    }
62    }
63   
64    // Also test that the comparison takes into account the name in case the two numbers are identical
65  1 one.setNumber(42);
66  1 two.setNumber(42);
67  1 Assert.assertEquals(Math.signum(one.compareTo(two)), -1.0, 0);
68  1 Assert.assertEquals(Math.signum(two.compareTo(one)), 1.0, 0);
69    }
70    }