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

File BooleanClassTest.java

 

Code metrics

0
73
1
1
149
96
1
0.01
73
1
1

Classes

Class Line # Actions
BooleanClassTest 40 73 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.localization.ContextualLocalizationManager;
25    import org.xwiki.model.reference.DocumentReference;
26    import org.xwiki.model.reference.EntityReferenceSerializer;
27   
28    import com.xpn.xwiki.objects.BaseObject;
29    import com.xpn.xwiki.objects.IntegerProperty;
30    import com.xpn.xwiki.test.MockitoOldcoreRule;
31   
32    import static org.junit.Assert.assertEquals;
33    import static org.mockito.Mockito.when;
34   
35    /**
36    * Unit tests for the {@link BooleanClass} class.
37    *
38    * @version $Id: bbfbf73db7b9e38b933437d87a7844feadcea379 $
39    */
 
40    public class BooleanClassTest
41    {
42    @Rule
43    public MockitoOldcoreRule mocker = new MockitoOldcoreRule();
44   
45    /** Test localization. */
 
46  1 toggle @Test
47    public void testLocalization() throws Exception
48    {
49    // Setup
50  1 ContextualLocalizationManager contextualLocalizationManager =
51    this.mocker.getMocker().registerMockComponent(ContextualLocalizationManager.class);
52  1 when(contextualLocalizationManager.getTranslationPlain("Some.Class_prop_0")).thenReturn("Nay");
53  1 when(contextualLocalizationManager.getTranslationPlain("Some.Class_prop_1")).thenReturn("Aye");
54  1 when(contextualLocalizationManager.getTranslationPlain("Some.Class_prop_2")).thenReturn("Dunno");
55  1 when(contextualLocalizationManager.getTranslationPlain("yesno_0")).thenReturn("No");
56  1 when(contextualLocalizationManager.getTranslationPlain("yesno_1")).thenReturn("Yes");
57  1 when(contextualLocalizationManager.getTranslationPlain("truefalse_0")).thenReturn("False");
58  1 when(contextualLocalizationManager.getTranslationPlain("truefalse_1")).thenReturn("True");
59  1 when(contextualLocalizationManager.getTranslationPlain("active_0")).thenReturn("Inactive");
60  1 when(contextualLocalizationManager.getTranslationPlain("active_1")).thenReturn("Active");
61  1 when(contextualLocalizationManager.getTranslationPlain("allow_0")).thenReturn("Deny");
62  1 when(contextualLocalizationManager.getTranslationPlain("allow_1")).thenReturn("Allow");
63   
64   
65  1 DocumentReference classReference =
66    new DocumentReference(this.mocker.getXWikiContext().getWikiId(), "Some", "Class");
67   
68  1 EntityReferenceSerializer<String> entityReferenceSerializer =
69    this.mocker.getMocker().registerMockComponent(EntityReferenceSerializer.TYPE_STRING, "local");
70  1 when(entityReferenceSerializer.serialize(classReference)).thenReturn("Some.Class");
71   
72    // Create a Boolean meta-property and an associated object with a property instance
73  1 BooleanClass metaProperty = new BooleanClass();
74  1 BaseClass cls = new BaseClass();
75  1 BaseObject obj = new BaseObject();
76  1 IntegerProperty prop = new IntegerProperty();
77  1 prop.setValue(0);
78  1 obj.safeput("prop", prop);
79  1 cls.setDocumentReference(classReference);
80  1 metaProperty.setObject(cls);
81   
82  1 StringBuffer out = new StringBuffer();
83   
84    // Test the default translations, should be the default "yesno" display type
85  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
86  1 assertEquals("No", out.toString());
87   
88  1 out.setLength(0);
89  1 prop.setValue(1);
90  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
91  1 assertEquals("Yes", out.toString());
92   
93  1 out.setLength(0);
94  1 prop.setValue(2);
95  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
96  1 assertEquals("---", out.toString());
97   
98    // Test translations when display type is "active"
99  1 metaProperty.setDisplayType("active");
100  1 out.setLength(0);
101  1 prop.setValue(0);
102  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
103  1 assertEquals("Inactive", out.toString());
104   
105  1 out.setLength(0);
106  1 prop.setValue(1);
107  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
108  1 assertEquals("Active", out.toString());
109   
110  1 out.setLength(0);
111  1 prop.setValue(2);
112  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
113  1 assertEquals("---", out.toString());
114   
115    // Test translations when display type is the non-existing "blacktive"
116  1 metaProperty.setDisplayType("blacktive");
117  1 out.setLength(0);
118  1 prop.setValue(0);
119  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
120  1 assertEquals("0", out.toString());
121   
122  1 out.setLength(0);
123  1 prop.setValue(1);
124  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
125  1 assertEquals("1", out.toString());
126   
127  1 out.setLength(0);
128  1 prop.setValue(2);
129  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
130  1 assertEquals("---", out.toString());
131   
132    // Test translations with the full classname_prop_value format
133  1 metaProperty.setName("prop");
134  1 out.setLength(0);
135  1 prop.setValue(0);
136  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
137  1 assertEquals("Nay", out.toString());
138   
139  1 out.setLength(0);
140  1 prop.setValue(1);
141  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
142  1 assertEquals("Aye", out.toString());
143   
144  1 out.setLength(0);
145  1 prop.setValue(2);
146  1 metaProperty.displayView(out, "prop", "", obj, this.mocker.getXWikiContext());
147  1 assertEquals("Dunno", out.toString());
148    }
149    }