1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.version.internal

File DefaultVersionTest.java

 

Code metrics

0
22
5
1
82
53
5
0.23
4.4
5
1

Classes

Class Line # Actions
DefaultVersionTest 32 22 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 4 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 org.xwiki.extension.version.internal;
21   
22    import java.io.ByteArrayInputStream;
23    import java.io.ByteArrayOutputStream;
24    import java.io.IOException;
25    import java.io.ObjectInputStream;
26    import java.io.ObjectOutputStream;
27   
28    import org.junit.Assert;
29    import org.junit.Test;
30    import org.xwiki.extension.version.Version;
31   
 
32    public class DefaultVersionTest
33    {
 
34  2 toggle private void validateSerialize(Version version) throws IOException, ClassNotFoundException
35    {
36  2 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
37  2 ObjectOutputStream out = new ObjectOutputStream(outputStream);
38  2 out.writeObject(version);
39  2 out.close();
40  2 outputStream.close();
41   
42  2 ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
43  2 ObjectInputStream in = new ObjectInputStream(inputStream);
44  2 Assert.assertEquals(version, in.readObject());
45  2 in.close();
46  2 inputStream.close();
47    }
48   
 
49  1 toggle @Test
50    public void testCompareTo()
51    {
52  1 Assert.assertTrue(new DefaultVersion("1.1").compareTo(new DefaultVersion("1.1")) == 0);
53  1 Assert.assertTrue(new DefaultVersion("1.2").compareTo(new DefaultVersion("1.1")) > 0);
54  1 Assert.assertTrue(new DefaultVersion("1.1").compareTo(new DefaultVersion("1.2")) < 0);
55   
56  1 Assert.assertTrue(new DefaultVersion("1.1").compareTo(new DefaultVersion("1.1w")) < 0);
57   
58  1 Assert.assertTrue(new DefaultVersion("1.1").compareTo(new DefaultVersion("1.1-milestone-1")) > 0);
59  1 Assert.assertTrue(new DefaultVersion("1.1.1").compareTo(new DefaultVersion("1.1-milestone-1")) > 0);
60    }
61   
 
62  1 toggle @Test
63    public void testType()
64    {
65  1 Assert.assertEquals(Version.Type.SNAPSHOT, new DefaultVersion("1.1-SNAPSHOT").getType());
66  1 Assert.assertEquals(Version.Type.BETA, new DefaultVersion("1.1-milestone-1").getType());
67  1 Assert.assertEquals(Version.Type.STABLE, new DefaultVersion("1.1").getType());
68    }
69   
 
70  1 toggle @Test
71    public void testSerialize() throws IOException, ClassNotFoundException
72    {
73  1 validateSerialize(new DefaultVersion("1.1"));
74  1 validateSerialize(new DefaultVersion("1.1-milestone-1"));
75    }
76   
 
77  1 toggle @Test
78    public void testBigInteger()
79    {
80  1 new DefaultVersion("1.2147483648").getType();
81    }
82    }