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

File AbstractExtensionTest.java

 

Code metrics

0
24
6
2
107
65
6
0.25
4
3
1

Classes

Class Line # Actions
AbstractExtensionTest 33 21 0% 5 0
1.0100%
AbstractExtensionTest.TestExtension 43 3 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 2 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 org.junit.Before;
23    import org.junit.Test;
24    import org.xwiki.extension.repository.ExtensionRepository;
25   
26    import static org.junit.Assert.assertEquals;
27    import static org.junit.Assert.assertSame;
28    import static org.mockito.Mockito.mock;
29   
30    /**
31    * @version $Id: 253f639f72624feb756a38189d8f76b941bfc55e $
32    */
 
33    public class AbstractExtensionTest
34    {
35    private AbstractExtension extension;
36   
37    private ExtensionRepository repository;
38   
39    private ExtensionId id;
40   
41    private String type;
42   
 
43    private static class TestExtension extends AbstractExtension
44    {
 
45  21 toggle public TestExtension(ExtensionId id, String type, ExtensionId... features)
46    {
47  21 super(null, id, type);
48   
49  21 for (ExtensionId feature : features) {
50  6 addExtensionFeature(feature);
51    }
52    }
53    }
54   
 
55  21 toggle private AbstractExtension toExtension(String id, String version, ExtensionId... features)
56    {
57  21 return new TestExtension(new ExtensionId(id, version), "test", features);
58    }
59   
 
60  11 toggle private void assertCompareTo(int comparizon, Extension e1, Extension e2)
61    {
62  11 assertEquals(comparizon, e1.compareTo(e2));
63    }
64   
65    // Tests
66   
 
67  2 toggle @Before
68    public void before()
69    {
70  2 this.repository = mock(ExtensionRepository.class);
71  2 this.id = new ExtensionId("extesionid", "extensionversion");
72  2 this.type = "extensiontype";
73   
74  2 this.extension = new AbstractExtension(this.repository, this.id, this.type)
75    {
76    };
77    }
78   
 
79  1 toggle @Test
80    public void testGet()
81    {
82  1 assertSame(this.repository, this.extension.get("repository"));
83  1 assertEquals(this.id.getId(), this.extension.get("id"));
84  1 assertEquals(this.id.getVersion(), this.extension.get("version"));
85  1 assertEquals(this.type, this.extension.get("type"));
86    }
87   
 
88  1 toggle @Test
89    public void testCompareTo()
90    {
91  1 assertCompareTo(0, toExtension("id", "2.0"), toExtension("id", "2.0"));
92  1 assertCompareTo(-1, toExtension("id", "2.0"), toExtension("id", "3.0"));
93  1 assertCompareTo(1, toExtension("id", "2.0"), toExtension("id", "1.0"));
94   
95  1 assertCompareTo(0, toExtension("feature", "2.0"), toExtension("id", "2.0", new ExtensionId("feature", "2.0")));
96  1 assertCompareTo(-1, toExtension("feature", "2.0"), toExtension("id", "2.0", new ExtensionId("feature", "3.0")));
97  1 assertCompareTo(1, toExtension("feature", "2.0"), toExtension("id", "2.0", new ExtensionId("feature", "1.0")));
98   
99  1 assertCompareTo(0, toExtension("id", "2.0", new ExtensionId("feature", "2.0")), toExtension("feature", "2.0"));
100  1 assertCompareTo(-1, toExtension("id", "2.0", new ExtensionId("feature", "2.0")), toExtension("feature", "3.0"));
101  1 assertCompareTo(1, toExtension("id", "2.0", new ExtensionId("feature", "2.0")), toExtension("feature", "1.0"));
102   
103  1 assertCompareTo(-1, toExtension("id", "1.0"), toExtension("id2", "1.0"));
104   
105  1 assertCompareTo(-1, toExtension("id", "1.0"), null);
106    }
107    }