| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
@link |
| 37 |
|
|
| 38 |
|
@version |
| 39 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (74) |
Complexity: 1 |
Complexity Density: 0.01 |
|
| 40 |
|
public class BooleanClassTest |
| 41 |
|
{ |
| 42 |
|
@Rule |
| 43 |
|
public MockitoOldcoreRule mocker = new MockitoOldcoreRule(); |
| 44 |
|
|
| 45 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (73) |
Complexity: 1 |
Complexity Density: 0.01 |
1PASS
|
|
| 46 |
1 |
@Test... |
| 47 |
|
public void testLocalization() throws Exception |
| 48 |
|
{ |
| 49 |
|
|
| 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 |
|
|
| 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 |
|
|
| 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 |
|
|
| 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 |
|
|
| 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 |
|
|
| 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 |
|
} |