Search in sources :

Example 31 with BindingsManager

use of com.android.tools.idea.ui.properties.BindingsManager in project android by JetBrains.

the class DoubleExpressionsTest method testIsEqualExpression.

@Test
public void testIsEqualExpression() {
    BoolValueProperty result = new BoolValueProperty();
    DoubleValueProperty lhs = new DoubleValueProperty();
    DoubleValueProperty rhs = new DoubleValueProperty();
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    bindings.bind(result, lhs.isEqualTo(rhs));
    assertThat(result.get()).isTrue();
    lhs.set(10.0);
    assertThat(result.get()).isFalse();
    rhs.set(10.0);
    assertThat(result.get()).isTrue();
    rhs.set(20.0);
    assertThat(result.get()).isFalse();
}
Also used : DoubleValueProperty(com.android.tools.idea.ui.properties.core.DoubleValueProperty) BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) BoolValueProperty(com.android.tools.idea.ui.properties.core.BoolValueProperty) Test(org.junit.Test)

Example 32 with BindingsManager

use of com.android.tools.idea.ui.properties.BindingsManager in project android by JetBrains.

the class IntExpressionsTest method testGreaterThanValueExpression.

@Test
public void testGreaterThanValueExpression() {
    BoolValueProperty result = new BoolValueProperty();
    IntValueProperty lhs = new IntValueProperty();
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    bindings.bind(result, lhs.isGreaterThan(10));
    assertThat(result.get()).isFalse();
    lhs.set(10);
    assertThat(result.get()).isFalse();
    lhs.set(20);
    assertThat(result.get()).isTrue();
}
Also used : IntValueProperty(com.android.tools.idea.ui.properties.core.IntValueProperty) BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) BoolValueProperty(com.android.tools.idea.ui.properties.core.BoolValueProperty) Test(org.junit.Test)

Example 33 with BindingsManager

use of com.android.tools.idea.ui.properties.BindingsManager in project android by JetBrains.

the class DoubleExpressionsTest method testGreaterThanExpression.

@Test
public void testGreaterThanExpression() {
    BoolValueProperty result = new BoolValueProperty();
    DoubleValueProperty lhs = new DoubleValueProperty();
    DoubleValueProperty rhs = new DoubleValueProperty();
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    bindings.bind(result, lhs.isGreaterThan(rhs));
    assertThat(result.get()).isFalse();
    lhs.set(10.0);
    assertThat(result.get()).isTrue();
    rhs.set(10.0);
    assertThat(result.get()).isFalse();
}
Also used : DoubleValueProperty(com.android.tools.idea.ui.properties.core.DoubleValueProperty) BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) BoolValueProperty(com.android.tools.idea.ui.properties.core.BoolValueProperty) Test(org.junit.Test)

Example 34 with BindingsManager

use of com.android.tools.idea.ui.properties.BindingsManager in project android by JetBrains.

the class AdapterPropertiesTest method bindingStringToDoubleWithBadParameters.

@Test
public void bindingStringToDoubleWithBadParameters() throws Exception {
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    StringProperty doubleString = new StringValueProperty("0");
    DoubleProperty doubleValue = new DoubleValueProperty(0.9876);
    //noinspection EmptyCatchBlock
    try {
        bindings.bindTwoWay(new StringToDoubleAdapterProperty(doubleString, 4, 3), doubleValue);
        fail("Expect an exception because maxDecimals is specified smaller than num decimals");
    } catch (IllegalArgumentException unused) {
    }
}
Also used : BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) Test(org.junit.Test)

Example 35 with BindingsManager

use of com.android.tools.idea.ui.properties.BindingsManager in project android by JetBrains.

the class AdapterPropertiesTest method bindingStringToIntAdapterWorks.

@Test
public void bindingStringToIntAdapterWorks() throws Exception {
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    StringProperty intString = new StringValueProperty("0");
    IntProperty intValue = new IntValueProperty(1);
    bindings.bindTwoWay(new StringToIntAdapterProperty(intString), intValue);
    assertThat(intString.get()).isEqualTo("1");
    intString.set("-99");
    assertThat(intValue.get()).isEqualTo(-99);
    intString.set("not an int");
    assertThat(intValue.get()).isEqualTo(-99);
}
Also used : BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) Test(org.junit.Test)

Aggregations

BindingsManager (com.android.tools.idea.ui.properties.BindingsManager)38 Test (org.junit.Test)38 BoolValueProperty (com.android.tools.idea.ui.properties.core.BoolValueProperty)27 IntValueProperty (com.android.tools.idea.ui.properties.core.IntValueProperty)12 DoubleValueProperty (com.android.tools.idea.ui.properties.core.DoubleValueProperty)11 StringValueProperty (com.android.tools.idea.ui.properties.core.StringValueProperty)4