| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.internal.store; |
| 21 |
|
|
| 22 |
|
import java.util.Arrays; |
| 23 |
|
|
| 24 |
|
import org.junit.Rule; |
| 25 |
|
import org.junit.Test; |
| 26 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 27 |
|
|
| 28 |
|
import com.xpn.xwiki.objects.DoubleProperty; |
| 29 |
|
import com.xpn.xwiki.objects.IntegerProperty; |
| 30 |
|
import com.xpn.xwiki.objects.LongProperty; |
| 31 |
|
import com.xpn.xwiki.objects.StringListProperty; |
| 32 |
|
import com.xpn.xwiki.objects.StringProperty; |
| 33 |
|
import com.xpn.xwiki.objects.classes.DBListClass; |
| 34 |
|
import com.xpn.xwiki.objects.classes.NumberClass; |
| 35 |
|
import com.xpn.xwiki.objects.classes.StringClass; |
| 36 |
|
|
| 37 |
|
import static org.junit.Assert.*; |
| 38 |
|
import static org.mockito.Mockito.*; |
| 39 |
|
|
| 40 |
|
|
| 41 |
|
@link |
| 42 |
|
|
| 43 |
|
@version |
| 44 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (61) |
Complexity: 8 |
Complexity Density: 0.15 |
|
| 45 |
|
public class PropertyConverterTest |
| 46 |
|
{ |
| 47 |
|
@Rule |
| 48 |
|
public MockitoComponentMockingRule<PropertyConverter> mocker = new MockitoComponentMockingRule<PropertyConverter>( |
| 49 |
|
PropertyConverter.class); |
| 50 |
|
|
| 51 |
|
|
| 52 |
|
@see |
| 53 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 54 |
1 |
@Test... |
| 55 |
|
public void doubleToInteger() throws Exception |
| 56 |
|
{ |
| 57 |
|
|
| 58 |
1 |
NumberClass numberClass = mock(NumberClass.class); |
| 59 |
1 |
IntegerProperty integerProperty = mock(IntegerProperty.class); |
| 60 |
1 |
when(numberClass.newProperty()).thenReturn(integerProperty); |
| 61 |
1 |
when(numberClass.getNumberType()).thenReturn("integer"); |
| 62 |
|
|
| 63 |
1 |
DoubleProperty doubleProperty = mock(DoubleProperty.class); |
| 64 |
1 |
when(doubleProperty.getValue()).thenReturn(3.5); |
| 65 |
|
|
| 66 |
1 |
assertEquals(integerProperty, this.mocker.getComponentUnderTest().convertProperty(doubleProperty, numberClass)); |
| 67 |
1 |
verify(integerProperty).setValue(3); |
| 68 |
|
} |
| 69 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
| 70 |
1 |
@Test... |
| 71 |
|
public void unsetDoubleToInteger() throws Exception |
| 72 |
|
{ |
| 73 |
1 |
NumberClass numberClass = mock(NumberClass.class); |
| 74 |
1 |
DoubleProperty unsetDoubleProperty = mock(DoubleProperty.class, "unset"); |
| 75 |
1 |
assertNull(this.mocker.getComponentUnderTest().convertProperty(unsetDoubleProperty, numberClass)); |
| 76 |
|
} |
| 77 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 78 |
1 |
@Test... |
| 79 |
|
public void multipleToSingleSelectOnDBList() throws Exception |
| 80 |
|
{ |
| 81 |
|
|
| 82 |
1 |
DBListClass dbListClass = mock(DBListClass.class); |
| 83 |
1 |
when(dbListClass.isMultiSelect()).thenReturn(false); |
| 84 |
1 |
StringProperty stringProperty = mock(StringProperty.class); |
| 85 |
1 |
when(dbListClass.newProperty()).thenReturn(stringProperty); |
| 86 |
|
|
| 87 |
1 |
StringListProperty stringListProperty = mock(StringListProperty.class); |
| 88 |
1 |
when(stringListProperty.getValue()).thenReturn(Arrays.asList("one", "two")); |
| 89 |
|
|
| 90 |
1 |
assertEquals(stringProperty, |
| 91 |
|
this.mocker.getComponentUnderTest().convertProperty(stringListProperty, dbListClass)); |
| 92 |
1 |
verify(stringProperty).setValue("one"); |
| 93 |
|
} |
| 94 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 95 |
1 |
@Test... |
| 96 |
|
public void multipleToSingleSelectOnEmptyDBList() throws Exception |
| 97 |
|
{ |
| 98 |
|
|
| 99 |
1 |
DBListClass dbListClass = mock(DBListClass.class); |
| 100 |
1 |
when(dbListClass.isMultiSelect()).thenReturn(false); |
| 101 |
|
|
| 102 |
1 |
StringListProperty emptyListProperty = mock(StringListProperty.class); |
| 103 |
1 |
when(emptyListProperty.getValue()).thenReturn(Arrays.asList()); |
| 104 |
|
|
| 105 |
1 |
assertNull(this.mocker.getComponentUnderTest().convertProperty(emptyListProperty, dbListClass)); |
| 106 |
|
} |
| 107 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (8) |
Complexity: 1 |
Complexity Density: 0.12 |
1PASS
|
|
| 108 |
1 |
@Test... |
| 109 |
|
public void singleToMultipleSelectOnDBList() throws Exception |
| 110 |
|
{ |
| 111 |
|
|
| 112 |
1 |
DBListClass dbListClass = mock(DBListClass.class); |
| 113 |
1 |
when(dbListClass.isMultiSelect()).thenReturn(true); |
| 114 |
1 |
StringListProperty stringListProperty = mock(StringListProperty.class); |
| 115 |
1 |
when(dbListClass.newProperty()).thenReturn(stringListProperty); |
| 116 |
|
|
| 117 |
1 |
StringProperty stringProperty = mock(StringProperty.class); |
| 118 |
1 |
when(stringProperty.getValue()).thenReturn("one"); |
| 119 |
|
|
| 120 |
1 |
assertEquals(stringListProperty, |
| 121 |
|
this.mocker.getComponentUnderTest().convertProperty(stringProperty, dbListClass)); |
| 122 |
1 |
verify(stringListProperty).setValue(Arrays.asList("one")); |
| 123 |
|
} |
| 124 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
| 125 |
1 |
@Test... |
| 126 |
|
public void singleToMultipleSelectOnUnsetDBList() throws Exception |
| 127 |
|
{ |
| 128 |
|
|
| 129 |
1 |
DBListClass dbListClass = mock(DBListClass.class); |
| 130 |
1 |
when(dbListClass.isMultiSelect()).thenReturn(true); |
| 131 |
|
|
| 132 |
1 |
StringProperty stringProperty = mock(StringProperty.class); |
| 133 |
1 |
when(stringProperty.getValue()).thenReturn(null); |
| 134 |
|
|
| 135 |
1 |
assertNull(this.mocker.getComponentUnderTest().convertProperty(stringProperty, dbListClass)); |
| 136 |
|
} |
| 137 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
| 138 |
1 |
@Test... |
| 139 |
|
public void longToString() throws Exception |
| 140 |
|
{ |
| 141 |
1 |
LongProperty longProperty = new LongProperty(); |
| 142 |
1 |
longProperty.setValue(Long.MAX_VALUE); |
| 143 |
|
|
| 144 |
1 |
StringClass stringClass = mock(StringClass.class); |
| 145 |
1 |
when(stringClass.newProperty()).thenReturn(new StringProperty()); |
| 146 |
1 |
StringProperty stringProperty = new StringProperty(); |
| 147 |
1 |
when(stringClass.fromString(longProperty.toText())).thenReturn(stringProperty); |
| 148 |
|
|
| 149 |
1 |
assertEquals(stringProperty, this.mocker.getComponentUnderTest().convertProperty(longProperty, stringClass)); |
| 150 |
|
} |
| 151 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (9) |
Complexity: 1 |
Complexity Density: 0.11 |
1PASS
|
|
| 152 |
1 |
@Test... |
| 153 |
|
public void stringToNumber() throws Exception |
| 154 |
|
{ |
| 155 |
1 |
StringProperty stringProperty = new StringProperty(); |
| 156 |
1 |
stringProperty.setValue("one"); |
| 157 |
|
|
| 158 |
1 |
NumberClass numberClass = mock(NumberClass.class); |
| 159 |
1 |
when(numberClass.newProperty()).thenReturn(new IntegerProperty()); |
| 160 |
1 |
when(numberClass.fromString(stringProperty.toText())).thenReturn(null); |
| 161 |
1 |
when(numberClass.getName()).thenReturn("age"); |
| 162 |
1 |
when(numberClass.getClassName()).thenReturn("Some.Class"); |
| 163 |
|
|
| 164 |
1 |
assertNull(this.mocker.getComponentUnderTest().convertProperty(stringProperty, numberClass)); |
| 165 |
1 |
verify(this.mocker.getMockedLogger()).warn( |
| 166 |
|
"Incompatible data migration when changing field [{}] of class [{}]", "age", "Some.Class"); |
| 167 |
|
} |
| 168 |
|
} |