Search in sources :

Example 1 with IntValueProperty

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

the class BindingsManagerTest method oneWayBindingsCanBeEnabledConditionally.

@Test
public void oneWayBindingsCanBeEnabledConditionally() {
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    IntValueProperty srcProperty = new IntValueProperty(10);
    IntValueProperty destProperty = new IntValueProperty(-5);
    BoolValueProperty bindingEnabled = new BoolValueProperty(true);
    bindings.bind(destProperty, srcProperty, bindingEnabled);
    assertThat(destProperty.get()).isEqualTo(10);
    srcProperty.set(20);
    assertThat(destProperty.get()).isEqualTo(20);
    bindingEnabled.set(false);
    assertThat(destProperty.get()).isEqualTo(20);
    srcProperty.set(30);
    assertThat(destProperty.get()).isEqualTo(20);
    srcProperty.set(40);
    assertThat(destProperty.get()).isEqualTo(20);
    bindingEnabled.set(true);
    assertThat(destProperty.get()).isEqualTo(40);
    srcProperty.set(50);
    assertThat(destProperty.get()).isEqualTo(50);
}
Also used : IntValueProperty(com.android.tools.idea.ui.properties.core.IntValueProperty) BoolValueProperty(com.android.tools.idea.ui.properties.core.BoolValueProperty) Test(org.junit.Test)

Example 2 with IntValueProperty

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

the class ExpressionTest method testSimpleExpression.

@Test
public void testSimpleExpression() throws Exception {
    final IntProperty intValue = new IntValueProperty(13);
    final Expression<String> intToString = new Expression<String>(intValue) {

        @NotNull
        @Override
        public String get() {
            return intValue.get().toString();
        }
    };
    assertThat(intToString.get()).isEqualTo("13");
    intValue.set(-13);
    assertThat(intToString.get()).isEqualTo("-13");
}
Also used : IntValueProperty(com.android.tools.idea.ui.properties.core.IntValueProperty) IntProperty(com.android.tools.idea.ui.properties.core.IntProperty) StringExpression(com.android.tools.idea.ui.properties.expressions.string.StringExpression) Test(org.junit.Test)

Example 3 with IntValueProperty

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

the class IntExpressionsTest method testIsEqualWithValueExpression.

@Test
public void testIsEqualWithValueExpression() {
    BoolValueProperty result = new BoolValueProperty();
    IntValueProperty lhs = new IntValueProperty();
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    bindings.bind(result, lhs.isEqualTo(10));
    assertThat(result.get()).isFalse();
    lhs.set(10);
    assertThat(result.get()).isTrue();
    lhs.set(20);
    assertThat(result.get()).isFalse();
}
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 4 with IntValueProperty

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

the class IntExpressionsTest method testIsEqualExpression.

@Test
public void testIsEqualExpression() {
    BoolValueProperty result = new BoolValueProperty();
    IntValueProperty lhs = new IntValueProperty();
    IntValueProperty rhs = new IntValueProperty();
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    bindings.bind(result, lhs.isEqualTo(rhs));
    assertThat(result.get()).isTrue();
    lhs.set(10);
    assertThat(result.get()).isFalse();
    rhs.set(10);
    assertThat(result.get()).isTrue();
    rhs.set(20);
    assertThat(result.get()).isFalse();
}
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 5 with IntValueProperty

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

the class IntExpressionsTest method testGreaterThanEqualValueExpression.

@Test
public void testGreaterThanEqualValueExpression() {
    BoolValueProperty result = new BoolValueProperty();
    IntValueProperty lhs = new IntValueProperty();
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    bindings.bind(result, lhs.isGreaterThanEqualTo(10));
    assertThat(result.get()).isFalse();
    lhs.set(10);
    assertThat(result.get()).isTrue();
    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)

Aggregations

IntValueProperty (com.android.tools.idea.ui.properties.core.IntValueProperty)23 Test (org.junit.Test)22 BoolValueProperty (com.android.tools.idea.ui.properties.core.BoolValueProperty)13 BindingsManager (com.android.tools.idea.ui.properties.BindingsManager)12 StringValueProperty (com.android.tools.idea.ui.properties.core.StringValueProperty)3 IntProperty (com.android.tools.idea.ui.properties.core.IntProperty)2 AndroidVersion (com.android.sdklib.AndroidVersion)1 TemplateMetadata.getBuildApiString (com.android.tools.idea.templates.TemplateMetadata.getBuildApiString)1 StringExpression (com.android.tools.idea.ui.properties.expressions.string.StringExpression)1 AndroidPlatform (org.jetbrains.android.sdk.AndroidPlatform)1 NotNull (org.jetbrains.annotations.NotNull)1