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

File NumberClassTest.java

 

Code metrics

0
16
1
1
78
35
1
0.06
16
1
1

Classes

Class Line # Actions
NumberClassTest 39 16 0% 1 0
1.0100%
 

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 org.junit.Rule;
23    import org.junit.Test;
24   
25    import com.xpn.xwiki.objects.BaseProperty;
26    import com.xpn.xwiki.test.MockitoOldcoreRule;
27    import com.xpn.xwiki.test.reference.ReferenceComponentList;
28   
29    import static org.junit.Assert.assertEquals;
30    import static org.junit.Assert.assertNotNull;
31    import static org.junit.Assert.assertNull;
32   
33    /**
34    * Unit tests for the {@link NumberClass} class.
35    *
36    * @version $Id: e28bf1853401ae64a301d9566188f6a49ddd94e1 $
37    */
38    @ReferenceComponentList
 
39    public class NumberClassTest
40    {
41    @Rule
42    public MockitoOldcoreRule oldcore = new MockitoOldcoreRule();
43   
44    /** Test the fromString method. */
 
45  1 toggle @Test
46    public void testFromString()
47    {
48    // Create a default Number property
49  1 NumberClass nc = new NumberClass();
50  1 BaseClass bc = new BaseClass();
51  1 bc.setName("Some.Class");
52  1 nc.setObject(bc);
53   
54    // A String value containing non-numeric caracters can not be respresented as a numeric value, so this sould
55    // return null
56  1 assertNull(nc.fromString("asd"));
57   
58    // A much too long number cannot be represented as a long value, so this should also return null
59  1 assertNull(nc.fromString("1111111111111111111111111111111111"));
60   
61  1 BaseProperty p;
62   
63    // A null value should lead to creating an object with an empty value
64  1 p = nc.fromString(null);
65  1 assertNotNull(p);
66  1 assertNull(p.getValue());
67   
68    // An empty String should lead to creating an object with an empty value
69  1 p = nc.fromString("");
70  1 assertNotNull(p);
71  1 assertNull(p.getValue());
72   
73    // An integer value should lead to creating an object containing that integer as value
74  1 p = nc.fromString("4");
75  1 assertNotNull(p);
76  1 assertEquals(4, Integer.parseInt(p.getValue().toString()));
77    }
78    }