Search in sources :

Example 1 with BindingsManager

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

the class AdapterPropertiesTest method bindingOptionalToValueAdapterWithDefaultValueWorks.

@Test
public void bindingOptionalToValueAdapterWithDefaultValueWorks() throws Exception {
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    OptionalProperty<String> optionalValue = new OptionalValueProperty<>();
    StringProperty stringValue = new StringValueProperty();
    bindings.bindTwoWay(stringValue, new OptionalToValuePropertyAdapter<>(optionalValue, "Initial"));
    assertThat(stringValue.get()).isEqualTo("Initial");
    stringValue.set("Modified");
    assertThat(optionalValue.getValue()).isEqualTo("Modified");
    optionalValue.clear();
    assertThat(stringValue.get()).isEqualTo("Modified");
}
Also used : BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) Test(org.junit.Test)

Example 2 with BindingsManager

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

the class AdapterPropertiesTest method bindingOptionalToValueAdapterWorks.

@Test
public void bindingOptionalToValueAdapterWorks() throws Exception {
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    OptionalProperty<String> optionalValue = new OptionalValueProperty<>("Initial");
    StringProperty stringValue = new StringValueProperty();
    OptionalToValuePropertyAdapter<String> adapterProperty = new OptionalToValuePropertyAdapter<>(optionalValue);
    bindings.bindTwoWay(stringValue, adapterProperty);
    assertThat(stringValue.get()).isEqualTo("Initial");
    assertThat(adapterProperty.inSync().get()).isTrue();
    stringValue.set("Modified");
    assertThat(optionalValue.getValue()).isEqualTo("Modified");
    assertThat(adapterProperty.inSync().get()).isTrue();
    optionalValue.clear();
    assertThat(stringValue.get()).isEqualTo("Modified");
    assertThat(adapterProperty.inSync().get()).isFalse();
}
Also used : BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) Test(org.junit.Test)

Example 3 with BindingsManager

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

the class BooleanExpressionsTest method testOrExpression.

@Test
public void testOrExpression() throws Exception {
    BoolValueProperty srcValue1 = new BoolValueProperty();
    BoolValueProperty srcValue2 = new BoolValueProperty();
    BoolValueProperty destValue = new BoolValueProperty();
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    bindings.bind(destValue, srcValue1.or(srcValue2));
    assertThat(srcValue1.get()).isFalse();
    assertThat(srcValue2.get()).isFalse();
    assertThat(destValue.get()).isFalse();
    srcValue1.set(true);
    srcValue2.set(false);
    assertThat(srcValue1.get()).isTrue();
    assertThat(srcValue2.get()).isFalse();
    assertThat(destValue.get()).isTrue();
    srcValue1.set(false);
    srcValue2.set(true);
    assertThat(srcValue1.get()).isFalse();
    assertThat(srcValue2.get()).isTrue();
    assertThat(destValue.get()).isTrue();
    srcValue1.set(true);
    srcValue2.set(true);
    assertThat(srcValue1.get()).isTrue();
    assertThat(srcValue2.get()).isTrue();
    assertThat(destValue.get()).isTrue();
}
Also used : BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) BoolValueProperty(com.android.tools.idea.ui.properties.core.BoolValueProperty) Test(org.junit.Test)

Example 4 with BindingsManager

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

the class BooleanExpressionsTest method testAndExpression.

@Test
public void testAndExpression() throws Exception {
    BoolValueProperty srcValue1 = new BoolValueProperty();
    BoolValueProperty srcValue2 = new BoolValueProperty();
    BoolValueProperty destValue = new BoolValueProperty();
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    bindings.bind(destValue, srcValue1.and(srcValue2));
    assertThat(srcValue1.get()).isFalse();
    assertThat(srcValue2.get()).isFalse();
    assertThat(destValue.get()).isFalse();
    srcValue1.set(true);
    srcValue2.set(false);
    assertThat(srcValue1.get()).isTrue();
    assertThat(srcValue2.get()).isFalse();
    assertThat(destValue.get()).isFalse();
    srcValue1.set(false);
    srcValue2.set(true);
    assertThat(srcValue1.get()).isFalse();
    assertThat(srcValue2.get()).isTrue();
    assertThat(destValue.get()).isFalse();
    srcValue1.set(true);
    srcValue2.set(true);
    assertThat(srcValue1.get()).isTrue();
    assertThat(srcValue2.get()).isTrue();
    assertThat(destValue.get()).isTrue();
}
Also used : BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) BoolValueProperty(com.android.tools.idea.ui.properties.core.BoolValueProperty) Test(org.junit.Test)

Example 5 with BindingsManager

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

the class BooleanExpressionsTest method testAnyExpression.

@Test
public void testAnyExpression() throws Exception {
    BoolValueProperty srcValue1 = new BoolValueProperty();
    BoolValueProperty srcValue2 = new BoolValueProperty();
    BoolValueProperty srcValue3 = new BoolValueProperty();
    BoolValueProperty destValue = new BoolValueProperty();
    BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
    bindings.bind(destValue, BooleanExpressions.any(srcValue1, srcValue2, srcValue3));
    assertThat(srcValue1.get()).isFalse();
    assertThat(srcValue2.get()).isFalse();
    assertThat(srcValue3.get()).isFalse();
    assertThat(destValue.get()).isFalse();
    srcValue1.set(true);
    srcValue2.set(false);
    srcValue3.set(false);
    assertThat(srcValue1.get()).isTrue();
    assertThat(srcValue2.get()).isFalse();
    assertThat(srcValue3.get()).isFalse();
    assertThat(destValue.get()).isTrue();
    srcValue1.set(false);
    srcValue2.set(true);
    srcValue3.set(false);
    assertThat(srcValue1.get()).isFalse();
    assertThat(srcValue2.get()).isTrue();
    assertThat(srcValue3.get()).isFalse();
    assertThat(destValue.get()).isTrue();
    srcValue1.set(true);
    srcValue2.set(false);
    srcValue3.set(true);
    assertThat(srcValue1.get()).isTrue();
    assertThat(srcValue2.get()).isFalse();
    assertThat(srcValue3.get()).isTrue();
    assertThat(destValue.get()).isTrue();
    srcValue1.set(true);
    srcValue2.set(true);
    srcValue3.set(true);
    assertThat(srcValue1.get()).isTrue();
    assertThat(srcValue2.get()).isTrue();
    assertThat(srcValue3.get()).isTrue();
    assertThat(destValue.get()).isTrue();
    srcValue1.set(false);
    srcValue2.set(false);
    srcValue3.set(false);
    assertThat(srcValue1.get()).isFalse();
    assertThat(srcValue2.get()).isFalse();
    assertThat(srcValue3.get()).isFalse();
    assertThat(destValue.get()).isFalse();
}
Also used : BindingsManager(com.android.tools.idea.ui.properties.BindingsManager) BoolValueProperty(com.android.tools.idea.ui.properties.core.BoolValueProperty) 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