use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.
the class ConstraintsTest method testNegative.
@Test
public void testNegative() throws Exception {
IntValueProperty negativeValue = new IntValueProperty(5);
negativeValue.addConstraint(value -> Math.min(0, value));
assertThat(negativeValue.get()).isEqualTo(0);
negativeValue.set(-5);
assertThat(negativeValue.get()).isEqualTo(-5);
negativeValue.set(105);
assertThat(negativeValue.get()).isEqualTo(0);
}
use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.
the class BindingsManagerTest method twoWayBindingsAffectEachOther.
@Test
public void twoWayBindingsAffectEachOther() throws Exception {
BindingsManager bindings = new BindingsManager(INVOKE_IMMEDIATELY_STRATEGY);
IntValueProperty property1 = new IntValueProperty(10);
IntValueProperty property2 = new IntValueProperty(20);
bindings.bindTwoWay(property1, property2);
assertThat(property1.get()).isEqualTo(20);
property1.set(30);
assertThat(property2.get()).isEqualTo(30);
property2.set(40);
assertThat(property1.get()).isEqualTo(40);
}
use of com.android.tools.idea.ui.properties.core.IntValueProperty in project android by JetBrains.
the class ServiceContextTest method dataModelCanRegisterActionsAndObservableValues.
@Test
public void dataModelCanRegisterActionsAndObservableValues() throws Exception {
ServiceContext context = new ServiceContext("Gradle");
{
final IntValueProperty count = new IntValueProperty();
Runnable incCount = new Runnable() {
@Override
public void run() {
count.increment();
}
};
final StringValueProperty title = new StringValueProperty("Title");
final BoolValueProperty enabled = new BoolValueProperty(true);
Runnable toggleEnabled = new Runnable() {
@Override
public void run() {
enabled.invert();
}
};
context.putValue("count", count);
context.putValue("title", title);
context.putValue("enabled", enabled);
context.putAction("incCount", incCount);
context.putAction("toggleEnabled", toggleEnabled);
}
IntValueProperty count = (IntValueProperty) context.getValue("count");
StringValueProperty title = (StringValueProperty) context.getValue("title");
BoolValueProperty enabled = (BoolValueProperty) context.getValue("enabled");
assertThat(title.get()).isEqualTo("Title");
assertThat(count.get()).isEqualTo(0);
context.getAction("incCount").run();
assertThat(count.get()).isEqualTo(1);
assertThat(enabled.get()).isTrue();
context.getAction("toggleEnabled").run();
assertThat(enabled.get()).isFalse();
}
Aggregations