1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.objects

File NumberPropertyTest.java

 

Code metrics

0
38
7
1
150
81
7
0.18
5.43
7
1

Classes

Class Line # Actions
NumberPropertyTest 39 38 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 6 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.objects;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Rule;
25    import org.junit.Test;
26    import org.xwiki.model.internal.reference.LocalStringEntityReferenceSerializer;
27    import org.xwiki.test.ComponentManagerRule;
28    import org.xwiki.test.annotation.ComponentList;
29   
30    import com.xpn.xwiki.web.Utils;
31   
32    /**
33    * Unit tests for {@link NumberProperty}.
34    *
35    * @version $Id: 6863e617356acc015f25e7658cbc8a2c89c0eba7 $
36    * @since 5.2M1
37    */
38    @ComponentList({LocalStringEntityReferenceSerializer.class})
 
39    public class NumberPropertyTest
40    {
41    @Rule
42    public ComponentManagerRule componentManager = new ComponentManagerRule();
43   
 
44  6 toggle @Before
45    public void setup()
46    {
47  6 Utils.setComponentManager(this.componentManager);
48    }
49   
50    /**
51    * Verify that we can compare a null valued number property with a non-null valued number property without having a
52    * NPE (<a href="https://jira.xwiki.org/browse/XWIKI-9326">XWIKI-9326</a>).
53    */
 
54  1 toggle @Test
55    public void nullValueEqualsWithOtherNumberProperty()
56    {
57  1 NumberProperty nullValueProperty = new IntegerProperty();
58  1 nullValueProperty.setValue(null);
59  1 Assert.assertNull(nullValueProperty.getValue());
60   
61  1 NumberProperty notNullValueProperty = new IntegerProperty();
62  1 notNullValueProperty.setValue(1);
63  1 Assert.assertNotNull(notNullValueProperty.getValue());
64   
65    // Should not throw a NPE.
66  1 Assert.assertFalse(nullValueProperty.equals(notNullValueProperty));
67    }
68   
69    /**
70    * Verify that we can compare a not-null valued number property with a null valued number property without having a
71    * NPE (<a href="https://jira.xwiki.org/browse/XWIKI-9326">XWIKI-9326</a>).
72    */
 
73  1 toggle @Test
74    public void notNullValueEqualsWithOtherNullNumberProperty()
75    {
76  1 NumberProperty nullValueProperty = new IntegerProperty();
77  1 nullValueProperty.setValue(1);
78  1 Assert.assertNotNull(nullValueProperty.getValue());
79   
80  1 NumberProperty notNullValueProperty = new IntegerProperty();
81  1 notNullValueProperty.setValue(null);
82  1 Assert.assertNull(notNullValueProperty.getValue());
83   
84    // Should not throw a NPE.
85  1 Assert.assertFalse(nullValueProperty.equals(notNullValueProperty));
86    }
87   
88    /**
89    * Verify that we can compare two null valued number properties without having a NPE (<a
90    * href="https://jira.xwiki.org/browse/XWIKI-9326">XWIKI-9326</a>).
91    */
 
92  1 toggle @Test
93    public void equalNullValueEquals()
94    {
95  1 NumberProperty nullValueProperty1 = new IntegerProperty();
96  1 nullValueProperty1.setValue(null);
97  1 Assert.assertNull(nullValueProperty1.getValue());
98   
99  1 NumberProperty nullValueProperty2 = new IntegerProperty();
100  1 nullValueProperty2.setValue(null);
101  1 Assert.assertNull(nullValueProperty2.getValue());
102   
103    // Should not throw a NPE.
104  1 Assert.assertTrue(nullValueProperty1.equals(nullValueProperty2));
105    }
106   
107    /**
108    * Two equal non-null values.
109    */
 
110  1 toggle @Test
111    public void equalNotNullValues()
112    {
113  1 NumberProperty nullValueProperty = new IntegerProperty();
114  1 nullValueProperty.setValue(1);
115   
116  1 NumberProperty notNullValueProperty = new IntegerProperty();
117  1 notNullValueProperty.setValue(1);
118   
119  1 Assert.assertTrue(nullValueProperty.equals(notNullValueProperty));
120    }
121   
122    /**
123    * Two not equal non-null values.
124    */
 
125  1 toggle @Test
126    public void notEqualNonNullValues()
127    {
128  1 NumberProperty nullValueProperty = new IntegerProperty();
129  1 nullValueProperty.setValue(0);
130   
131  1 NumberProperty notNullValueProperty = new IntegerProperty();
132  1 notNullValueProperty.setValue(1);
133   
134  1 Assert.assertFalse(nullValueProperty.equals(notNullValueProperty));
135    }
136   
 
137  1 toggle @Test
138    public void testHashCode()
139    {
140  1 final Number value = 101;
141   
142  1 NumberProperty n1 = new IntegerProperty();
143  1 NumberProperty n2 = new IntegerProperty();
144   
145  1 n1.setValue(value);
146  1 n2.setValue(value);
147   
148  1 Assert.assertEquals(n1.hashCode(), n2.hashCode());
149    }
150    }