#1035 tests for - FIX: deleting and adding same bean in beanCollection leads to deletion in DB

This commit is contained in:
rob bygrave
2017-06-19 23:32:58 +12:00
parent 7b8a85106c
commit dbf4e99187
@@ -5,6 +5,8 @@ import org.jetbrains.annotations.NotNull;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
@@ -12,9 +14,9 @@ import static org.assertj.core.api.Assertions.assertThat;
public class BeanListTest {
Object object1 = new Object();
Object object2 = new Object();
Object object3 = new Object();
private Object object1 = new Object();
private Object object2 = new Object();
private Object object3 = new Object();
@NotNull
private List<Object> all() {
@@ -33,6 +35,30 @@ public class BeanListTest {
return some;
}
@Test
public void test_setModifyListening_null() throws Exception {
BeanList<Object> list = new BeanList<>();
list.setModifyListening(null);
// act
list.addAll(all());
assertThat(list.getModifyAdditions()).isNull();
}
@Test
public void test_setModifyListening_none() throws Exception {
BeanList<Object> list = new BeanList<>();
list.setModifyListening(BeanCollection.ModifyListenMode.NONE);
// act
list.addAll(all());
assertThat(list.getModifyAdditions()).isNull();
}
@Test
public void testAdd() throws Exception {
@@ -67,6 +93,47 @@ public class BeanListTest {
assertThat(list.getModifyRemovals()).isEmpty();
}
@Test
public void test_removals_DeleteThenAddBack_expect_noChange() throws Exception {
BeanList<Object> list = new BeanList<>(some());
list.setModifyListening(BeanCollection.ModifyListenMode.REMOVALS);
// act
list.remove(object2);
assertThat(list.getModifyRemovals()).isNotEmpty();
list.add(object2);
assertThat(list.getModifyRemovals()).isEmpty();
assertThat(list.getModifyAdditions()).isEmpty();
}
@Test
public void test_sort_whenAll_expect_noChange() throws Exception {
BeanList<Object> list = new BeanList<>(all());
list.setModifyListening(BeanCollection.ModifyListenMode.ALL);
// act
Collections.sort(list, Comparator.comparingInt(Object::hashCode));
assertThat(list.getModifyRemovals()).isEmpty();
assertThat(list.getModifyAdditions()).isEmpty();
}
@Test
public void test_sort_whenRemovals_expect_noChange() throws Exception {
BeanList<Object> list = new BeanList<>(all());
list.setModifyListening(BeanCollection.ModifyListenMode.REMOVALS);
// act
Collections.sort(list, Comparator.comparingInt(Object::hashCode));
assertThat(list.getModifyRemovals()).isEmpty();
assertThat(list.getModifyAdditions()).isEmpty();
}
@Test
public void testAdd_given_someAlreadyIn() throws Exception {