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

File BaseClassTest.java

 

Code metrics

0
46
5
1
133
83
5
0.11
9.2
5
1

Classes

Class Line # Actions
BaseClassTest 37 46 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 com.xpn.xwiki.objects.classes;
21   
22    import org.junit.Rule;
23    import org.junit.Test;
24    import org.xwiki.model.reference.DocumentReference;
25   
26    import com.xpn.xwiki.test.MockitoOldcoreRule;
27    import com.xpn.xwiki.test.reference.ReferenceComponentList;
28   
29    import static org.junit.Assert.*;
30   
31    /**
32    * Unit tests for the {@link BaseClass} class.
33    *
34    * @version $Id: cc5bd424e6d09e652acc724f17d4f253591ab854 $
35    */
36    @ReferenceComponentList
 
37    public class BaseClassTest
38    {
39    @Rule
40    public MockitoOldcoreRule oldcore = new MockitoOldcoreRule();
41   
 
42  1 toggle @Test
43    public void setDocumentReference() throws Exception
44    {
45  1 BaseClass baseClass = new BaseClass();
46   
47  1 DocumentReference reference = new DocumentReference("wiki", "space", "page");
48  1 baseClass.setDocumentReference(reference);
49   
50  1 assertEquals(reference, baseClass.getDocumentReference());
51    }
52   
 
53  1 toggle @Test
54    public void setNameSetWiki() throws Exception
55    {
56  1 String database = this.oldcore.getXWikiContext().getWikiId();
57  1 BaseClass baseClass = new BaseClass();
58   
59  1 baseClass.setName("space.page");
60   
61  1 assertEquals(database, baseClass.getDocumentReference().getWikiReference().getName());
62  1 assertEquals("space", baseClass.getDocumentReference().getLastSpaceReference().getName());
63  1 assertEquals("page", baseClass.getDocumentReference().getName());
64    }
65   
 
66  1 toggle @Test
67    public void setNameAloneWithChangingContext() throws Exception
68    {
69  1 String database = this.oldcore.getXWikiContext().getWikiId();
70  1 BaseClass baseClass = new BaseClass();
71   
72  1 baseClass.setName("space.page");
73   
74  1 try {
75  1 this.oldcore.getXWikiContext().setWikiId("otherwiki");
76   
77  1 assertEquals(database, baseClass.getDocumentReference().getWikiReference().getName());
78  1 assertEquals("space", baseClass.getDocumentReference().getLastSpaceReference().getName());
79  1 assertEquals("page", baseClass.getDocumentReference().getName());
80   
81  1 baseClass.setName("otherspace.otherpage");
82    } finally {
83  1 this.oldcore.getXWikiContext().setWikiId(database);
84    }
85   
86  1 assertEquals(database, baseClass.getDocumentReference().getWikiReference().getName());
87  1 assertEquals("otherspace", baseClass.getDocumentReference().getLastSpaceReference().getName());
88  1 assertEquals("otherpage", baseClass.getDocumentReference().getName());
89   
90  1 baseClass = new BaseClass();
91  1 try {
92  1 this.oldcore.getXWikiContext().setWikiId("otherwiki");
93  1 baseClass.setName("space.page");
94    } finally {
95  1 this.oldcore.getXWikiContext().setWikiId(database);
96    }
97   
98  1 assertEquals("otherwiki", baseClass.getDocumentReference().getWikiReference().getName());
99  1 assertEquals("space", baseClass.getDocumentReference().getLastSpaceReference().getName());
100  1 assertEquals("page", baseClass.getDocumentReference().getName());
101   
102  1 baseClass.setName("otherspace.otherpage");
103   
104  1 assertEquals("otherwiki", baseClass.getDocumentReference().getWikiReference().getName());
105  1 assertEquals("otherspace", baseClass.getDocumentReference().getLastSpaceReference().getName());
106  1 assertEquals("otherpage", baseClass.getDocumentReference().getName());
107    }
108   
 
109  1 toggle @Test
110    public void addTextAreaFieldWhenNullContentType() throws Exception
111    {
112  1 BaseClass baseClass = new BaseClass();
113   
114  1 TextAreaClass textAreaClass = new TextAreaClass();
115  1 textAreaClass.setName("field");
116  1 textAreaClass.setPrettyName("pretty name");
117  1 textAreaClass.setSize(55);
118  1 textAreaClass.setRows(33);
119  1 baseClass.put("field", textAreaClass);
120   
121  1 assertFalse(baseClass.addTextAreaField("field", "pretty name", 55, 33));
122    }
123   
 
124  1 toggle @Test
125    public void addTextAreaFieldWhenExistingNumberField() throws Exception
126    {
127  1 BaseClass baseClass = new BaseClass();
128   
129  1 baseClass.addNumberField("field", "int pretty name", 30, "int");
130   
131  1 assertTrue(baseClass.addTextAreaField("field", "pretty name", 55, 33));
132    }
133    }