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

File DefaultVersionConstraintTest.java

 

Code metrics

0
18
4
1
88
54
6
0.33
4.5
4
1.5

Classes

Class Line # Actions
DefaultVersionConstraintTest 29 18 0% 6 2
0.9090909490.9%
 

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.util.Arrays;
23   
24    import org.junit.Assert;
25    import org.junit.Test;
26    import org.xwiki.extension.version.IncompatibleVersionConstraintException;
27    import org.xwiki.extension.version.InvalidVersionRangeException;
28   
 
29    public class DefaultVersionConstraintTest
30    {
 
31  1 toggle @Test
32    public void testMerge() throws IncompatibleVersionConstraintException
33    {
34  1 Assert.assertEquals("2.0", new DefaultVersionConstraint("1.0").merge(new DefaultVersionConstraint("2.0"))
35    .getValue());
36  1 Assert.assertEquals("{[1.0,2.0]},{[2.0]}",
37    new DefaultVersionConstraint("[1.0,2.0]").merge(new DefaultVersionConstraint("[2.0]")).getValue());
38  1 Assert.assertEquals("2.0", new DefaultVersionConstraint("[1.0,2.0]").merge(new DefaultVersionConstraint("2.0"))
39    .getValue());
40   
41    // Invalid
42   
43  1 try {
44  1 new DefaultVersionConstraint("[1.0]").merge(new DefaultVersionConstraint("[2.0]")).getValue();
45  0 Assert.fail("Should have failed");
46    } catch (IncompatibleVersionConstraintException expected) {
47    // expected
48    }
49   
50  1 try {
51  1 new DefaultVersionConstraint("1.0").merge(new DefaultVersionConstraint("[2.0]")).getValue();
52  0 Assert.fail("Should have failed");
53    } catch (IncompatibleVersionConstraintException expected) {
54    // expected
55    }
56    }
57   
 
58  1 toggle @Test
59    public void testParse() throws InvalidVersionRangeException
60    {
61  1 Assert.assertEquals("1.0", new DefaultVersionConstraint("1.0").getVersion().getValue());
62  1 Assert.assertEquals(Arrays.asList(new DefaultVersionRangeCollection("[1.0]")), new DefaultVersionConstraint(
63    "[1.0]").getRanges());
64  1 Assert.assertEquals(Arrays.asList(new DefaultVersionRangeCollection("[1.0]")), new DefaultVersionConstraint(
65    "{[1.0]}").getRanges());
66  1 Assert.assertEquals(Arrays.asList(new DefaultVersionRangeCollection("[1.0]"),
67    new DefaultVersionRangeCollection("[1.0,2.0],[1.0]")), new DefaultVersionConstraint(
68    "{[1.0]},{[1.0,2.0],[1.0]}").getRanges());
69   
70    // Invalid goes to version
71   
72  1 Assert.assertEquals("[1.0", new DefaultVersionConstraint("[1.0").getVersion().getValue());
73    }
74   
 
75  1 toggle @Test
76    public void testContainsVersion()
77    {
78  1 Assert.assertTrue(new DefaultVersionConstraint("1.0").containsVersion(new DefaultVersion("1.0")));
79  1 Assert.assertFalse(new DefaultVersionConstraint("1.0").containsVersion(new DefaultVersion("2.0")));
80    }
81   
 
82  1 toggle @Test
83    public void testIsCompatible()
84    {
85  1 Assert.assertTrue(new DefaultVersionConstraint("1.0").isCompatible(new DefaultVersion("1.0")));
86  1 Assert.assertTrue(new DefaultVersionConstraint("1.0").isCompatible(new DefaultVersion("2.0")));
87    }
88    }