Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tepi committed Aug 23, 2024
1 parent 158e743 commit c79b79f
Showing 1 changed file with 68 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ public void update_bound_propertyIsUpdated() throws ValidationException {
}

@Test
public void update_to_initial_value_removes_binding_from_changedBindings()
public void update_to_initial_value_removes_binding_from_changedBindings_with_set_predicates()
throws ValidationException {
Person person = new Person();
String initialName = "Foo";
Expand Down Expand Up @@ -563,6 +563,73 @@ public void update_to_initial_value_removes_binding_from_changedBindings()
assertTrue(binder.getChangedBindings().isEmpty());
}

@Test
public void update_to_initial_value_removes_binding_from_changedBindings_with_default_predicates()
throws ValidationException {
Person person = new Person();
String initialName = "Foo";
person.setFirstName(initialName);
person.setAge(20);

Binder<Person> binder = new Binder<>();
binder.setChangeDetectionEnabled(true);
Binding<Person, String> nameBinding = binder.forField(nameField)
.bind(Person::getFirstName, Person::setFirstName);
Binding<Person, Integer> ageBinding = binder.forField(ageField)
.withConverter(new StringToIntegerConverter(""))
.bind(Person::getAge, Person::setAge);

binder.readBean(person);
nameField.setValue("Bar");

assertEquals(1, binder.getChangedBindings().size());
assertTrue(binder.getChangedBindings().contains(nameBinding));

ageField.setValue("21");
assertEquals(2, binder.getChangedBindings().size());

nameField.setValue(initialName);

assertEquals(1, binder.getChangedBindings().size());
assertTrue(binder.getChangedBindings().contains(ageBinding));

ageField.setValue("20");
assertTrue(binder.getChangedBindings().isEmpty());
}

@Test
public void update_to_initial_value_does_not_remove_binding_from_changedBindings_by_default()
throws ValidationException {
Person person = new Person();
String initialName = "Foo";
person.setFirstName(initialName);
person.setAge(20);

Binder<Person> binder = new Binder<>();
Binding<Person, String> nameBinding = binder.forField(nameField)
.bind(Person::getFirstName, Person::setFirstName);
Binding<Person, Integer> ageBinding = binder.forField(ageField)
.withConverter(new StringToIntegerConverter(""))
.bind(Person::getAge, Person::setAge);

binder.readBean(person);
nameField.setValue("Bar");

assertEquals(1, binder.getChangedBindings().size());
assertTrue(binder.getChangedBindings().contains(nameBinding));

ageField.setValue("21");
assertEquals(2, binder.getChangedBindings().size());
assertTrue(binder.getChangedBindings().contains(ageBinding));

nameField.setValue(initialName);

assertEquals(2, binder.getChangedBindings().size());

ageField.setValue("20");
assertEquals(2, binder.getChangedBindings().size());
}

@Test
public void save_bound_beanAsDraft() {
do_test_save_bound_beanAsDraft(false);
Expand Down

0 comments on commit c79b79f

Please sign in to comment.