Search in sources :

Example 1 with DoubleProperty

use of com.xpn.xwiki.objects.DoubleProperty in project xwiki-platform by xwiki.

the class PropertyConverterTest method doubleToInteger.

/**
 * @see XWIKI-8649: Error when changing the number type of a field from an application
 */
@Test
public void doubleToInteger() throws Exception {
    // The number property whose type has changed from Double to Integer.
    NumberClass numberClass = mock(NumberClass.class);
    IntegerProperty integerProperty = mock(IntegerProperty.class);
    when(numberClass.newProperty()).thenReturn(integerProperty);
    when(numberClass.getNumberType()).thenReturn("integer");
    DoubleProperty doubleProperty = mock(DoubleProperty.class);
    when(doubleProperty.getValue()).thenReturn(3.5);
    assertEquals(integerProperty, this.mocker.getComponentUnderTest().convertProperty(doubleProperty, numberClass));
    verify(integerProperty).setValue(3);
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) NumberClass(com.xpn.xwiki.objects.classes.NumberClass) DoubleProperty(com.xpn.xwiki.objects.DoubleProperty) Test(org.junit.Test)

Example 2 with DoubleProperty

use of com.xpn.xwiki.objects.DoubleProperty in project xwiki-platform by xwiki.

the class PropertyConverterTest method unsetDoubleToInteger.

@Test
public void unsetDoubleToInteger() throws Exception {
    NumberClass numberClass = mock(NumberClass.class);
    DoubleProperty unsetDoubleProperty = mock(DoubleProperty.class, "unset");
    assertNull(this.mocker.getComponentUnderTest().convertProperty(unsetDoubleProperty, numberClass));
}
Also used : NumberClass(com.xpn.xwiki.objects.classes.NumberClass) DoubleProperty(com.xpn.xwiki.objects.DoubleProperty) Test(org.junit.Test)

Example 3 with DoubleProperty

use of com.xpn.xwiki.objects.DoubleProperty in project xwiki-platform by xwiki.

the class NumberClass method newProperty.

@Override
public BaseProperty newProperty() {
    String ntype = getNumberType();
    BaseProperty property;
    if (ntype.equals("integer")) {
        property = new IntegerProperty();
    } else if (ntype.equals("float")) {
        property = new FloatProperty();
    } else if (ntype.equals("double")) {
        property = new DoubleProperty();
    } else {
        property = new LongProperty();
    }
    property.setName(getName());
    return property;
}
Also used : IntegerProperty(com.xpn.xwiki.objects.IntegerProperty) LongProperty(com.xpn.xwiki.objects.LongProperty) BaseProperty(com.xpn.xwiki.objects.BaseProperty) FloatProperty(com.xpn.xwiki.objects.FloatProperty) DoubleProperty(com.xpn.xwiki.objects.DoubleProperty)

Aggregations

DoubleProperty (com.xpn.xwiki.objects.DoubleProperty)3 IntegerProperty (com.xpn.xwiki.objects.IntegerProperty)2 NumberClass (com.xpn.xwiki.objects.classes.NumberClass)2 Test (org.junit.Test)2 BaseProperty (com.xpn.xwiki.objects.BaseProperty)1 FloatProperty (com.xpn.xwiki.objects.FloatProperty)1 LongProperty (com.xpn.xwiki.objects.LongProperty)1