1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.extension

File DefaultExtensionDependencyTest.java

 

Code metrics

0
40
5
1
146
93
5
0.12
8
5
1

Classes

Class Line # Actions
DefaultExtensionDependencyTest 41 40 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 5 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;
21   
22    import java.util.Arrays;
23    import java.util.HashMap;
24    import java.util.Map;
25   
26    import org.junit.jupiter.api.Test;
27    import org.xwiki.extension.version.internal.DefaultVersionConstraint;
28   
29    import static org.junit.jupiter.api.Assertions.assertEquals;
30    import static org.junit.jupiter.api.Assertions.assertFalse;
31    import static org.junit.jupiter.api.Assertions.assertNotEquals;
32    import static org.junit.jupiter.api.Assertions.assertNotSame;
33    import static org.junit.jupiter.api.Assertions.assertNull;
34    import static org.junit.jupiter.api.Assertions.assertTrue;
35   
36    /**
37    * Validate {@link DefaultExtensionDependency}.
38    *
39    * @version $Id: b2cb59f49f47bae57c9e09eb77d6e48a8d89ea07 $
40    */
 
41    public class DefaultExtensionDependencyTest
42    {
 
43  1 toggle @Test
44    public void properties()
45    {
46  1 DefaultExtensionDependency dependency =
47    new DefaultExtensionDependency("id", new DefaultVersionConstraint("version"));
48   
49  1 Map<String, Object> properties = new HashMap<>();
50   
51  1 properties.put("key1", "value1");
52   
53  1 dependency.setProperties(properties);
54   
55  1 assertNotSame(properties, dependency.getProperties());
56  1 assertEquals(properties, dependency.getProperties());
57  1 assertEquals("value1", dependency.getProperty("key1"));
58  1 assertNull(dependency.getProperty("nokey"));
59  1 assertEquals("default", dependency.getProperty("nokey", "default"));
60   
61  1 dependency.putProperty("key2", "value2");
62   
63  1 assertNotEquals(properties, dependency.getProperties());
64   
65  1 properties.put("key2", "value2");
66   
67  1 assertEquals(properties, dependency.getProperties());
68    }
69   
 
70  1 toggle @Test
71    public void equals()
72    {
73  1 assertEquals(new DefaultExtensionDependency("id", new DefaultVersionConstraint("version")),
74    new DefaultExtensionDependency("id", new DefaultVersionConstraint("version")));
75   
76  1 assertNotEquals(new DefaultExtensionDependency("id", new DefaultVersionConstraint("version")),
77    new DefaultExtensionDependency("id2", new DefaultVersionConstraint("version")));
78   
79  1 assertNotEquals(new DefaultExtensionDependency("id", new DefaultVersionConstraint("version")),
80    new DefaultExtensionDependency("id", new DefaultVersionConstraint("version2")));
81    }
82   
 
83  1 toggle @Test
84    public void isCompatibleWithExtensionId()
85    {
86  1 DefaultExtensionDependency dependency =
87    new DefaultExtensionDependency("id", new DefaultVersionConstraint("[1.0, 2.0]"));
88   
89  1 assertTrue(dependency.isCompatible(new ExtensionId("id", "1.0")));
90  1 assertTrue(dependency.isCompatible(new ExtensionId("id", "1.1")));
91  1 assertTrue(dependency.isCompatible(new ExtensionId("id", "2.0")));
92   
93  1 assertFalse(dependency.isCompatible(new ExtensionId("id2", "1.0")));
94  1 assertFalse(dependency.isCompatible(new ExtensionId("id", "0.9")));
95  1 assertFalse(dependency.isCompatible(new ExtensionId("id", "3.0")));
96    }
97   
 
98  1 toggle @Test
99    public void isCompatibleWithExtension()
100    {
101  1 DefaultExtensionDependency dependency =
102    new DefaultExtensionDependency("id", new DefaultVersionConstraint("[1.0, 2.0]"));
103   
104  1 assertTrue(
105    dependency.isCompatible(new AbstractExtensionTest.TestExtension(new ExtensionId("id", "1.0"), "type")));
106  1 assertTrue(
107    dependency.isCompatible(new AbstractExtensionTest.TestExtension(new ExtensionId("id", "1.1"), "type")));
108  1 assertTrue(
109    dependency.isCompatible(new AbstractExtensionTest.TestExtension(new ExtensionId("id", "2.0"), "type")));
110   
111  1 assertFalse(
112    dependency.isCompatible(new AbstractExtensionTest.TestExtension(new ExtensionId("id", "0.9"), "type")));
113  1 assertFalse(
114    dependency.isCompatible(new AbstractExtensionTest.TestExtension(new ExtensionId("id", "3.0"), "type")));
115   
116  1 assertTrue(dependency.isCompatible(new AbstractExtensionTest.TestExtension(new ExtensionId("id2", "1.0"),
117    "type", new ExtensionId("id", "1.0"))));
118  1 assertTrue(dependency.isCompatible(new AbstractExtensionTest.TestExtension(new ExtensionId("id2", "1.0"),
119    "type", new ExtensionId("id", "1.1"))));
120  1 assertTrue(dependency.isCompatible(new AbstractExtensionTest.TestExtension(new ExtensionId("id2", "1.0"),
121    "type", new ExtensionId("id", "2.0"))));
122   
123  1 assertFalse(dependency.isCompatible(new AbstractExtensionTest.TestExtension(new ExtensionId("id2", "1.0"),
124    "type", new ExtensionId("id", "0.9"))));
125  1 assertFalse(dependency.isCompatible(new AbstractExtensionTest.TestExtension(new ExtensionId("id2", "1.0"),
126    "type", new ExtensionId("id", "3.0"))));
127    }
128   
 
129  1 toggle @Test
130    public void repositories()
131    {
132  1 DefaultExtensionDependency dependency =
133    new DefaultExtensionDependency("id", new DefaultVersionConstraint("version"));
134   
135  1 assertTrue(dependency.getRepositories().isEmpty());
136   
137  1 dependency.setRepositories(Arrays.asList(AbstractExtensionTest.DESCRIPTOR1));
138   
139  1 assertEquals(Arrays.asList(AbstractExtensionTest.DESCRIPTOR1), dependency.getRepositories());
140   
141  1 dependency.addRepository(AbstractExtensionTest.DESCRIPTOR2);
142   
143  1 assertEquals(Arrays.asList(AbstractExtensionTest.DESCRIPTOR1, AbstractExtensionTest.DESCRIPTOR2),
144    dependency.getRepositories());
145    }
146    }