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);
}
use of com.android.tools.idea.ui.properties.BindingsManager in project android by JetBrains.
the class AdapterPropertiesTest method bindingStringToDoubleAdapterWorks.
@Test
public void bindingStringToDoubleAdapterWorks() throws Exception {
BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
StringProperty doubleString = new StringValueProperty("0");
DoubleProperty doubleValue = new DoubleValueProperty(20.0);
// Defaults to 1 decimal point of precision
StringToDoubleAdapterProperty adapterProperty = new StringToDoubleAdapterProperty(doubleString);
bindings.bindTwoWay(adapterProperty, doubleValue);
assertThat(doubleString.get()).isEqualTo("20.0");
assertThat(adapterProperty.inSync().get()).isTrue();
doubleString.set("100.5");
assertThat(doubleValue.get()).isWithin(0.01).of(100.5);
assertThat(adapterProperty.inSync().get()).isTrue();
doubleString.set("not a double");
assertThat(doubleValue.get()).isWithin(0.01).of(100.5);
assertThat(adapterProperty.inSync().get()).isFalse();
}
use of com.android.tools.idea.ui.properties.BindingsManager in project android by JetBrains.
the class AdapterPropertiesTest method bindingStringToDoubleAdapterWithPrecisionWorks.
@Test
public void bindingStringToDoubleAdapterWithPrecisionWorks() throws Exception {
BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
StringProperty doubleString = new StringValueProperty("0");
DoubleProperty doubleValue = new DoubleValueProperty(0.1234);
bindings.bindTwoWay(new StringToDoubleAdapterProperty(doubleString, 3), doubleValue);
assertThat(doubleString.get()).isEqualTo("0.123");
}
use of com.android.tools.idea.ui.properties.BindingsManager in project android by JetBrains.
the class AdapterPropertiesTest method bindingStringToDoubleAdapterWithLocale.
@Test
public void bindingStringToDoubleAdapterWithLocale() throws Exception {
Locale.setDefault(Locale.ITALIAN);
BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
StringProperty doubleString = new StringValueProperty("0");
DoubleProperty doubleValue = new DoubleValueProperty(0.9876);
bindings.bindTwoWay(new StringToDoubleAdapterProperty(doubleString, 2, 3), doubleValue);
assertThat(doubleString.get()).isEqualTo("0,988");
doubleValue.set(0.3);
assertThat(doubleString.get()).isEqualTo("0,30");
doubleValue.set(0.299);
assertThat(doubleString.get()).isEqualTo("0,299");
}
use of com.android.tools.idea.ui.properties.BindingsManager in project android by JetBrains.
the class IntExpressionsTest method testLessThanEqualValueExpression.
@Test
public void testLessThanEqualValueExpression() {
BoolValueProperty result = new BoolValueProperty();
IntValueProperty lhs = new IntValueProperty();
BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
bindings.bind(result, lhs.isLessThanEqualTo(10));
assertThat(result.get()).isTrue();
lhs.set(10);
assertThat(result.get()).isTrue();
lhs.set(20);
assertThat(result.get()).isFalse();
}
Aggregations