ItEr18S09CUCreacionProxectoPlanificacionItEr17S10: Avoiding throwing of exception when adding an empty list at MutableTreeModel

This commit is contained in:
Óscar González Fernández 2009-07-28 20:17:49 +02:00 committed by Javier Moran Rua
parent e594171ba0
commit ecb8f09c0b
2 changed files with 17 additions and 0 deletions

View file

@ -172,6 +172,8 @@ public class MutableTreeModel<T> extends AbstractTreeModel {
}
private void add(Node<T> parent, Integer position, List<Node<T>> children) {
if (children.isEmpty())
return;
int indexFrom = position == null ? parent.children.size() : position;
int indexTo = indexFrom + children.size() - 1;
parent.addAll(position, children);

View file

@ -236,6 +236,21 @@ public class MutableTreeModelTest {
assertThat(model.getChildCount(model.getRoot()), equalTo(2));
}
@Test
public void addingAnEmptyListOfElementsDontDoNothing() {
MutableTreeModel<Prueba> model = MutableTreeModel.create(Prueba.class);
final List<TreeDataEvent> events = new ArrayList<TreeDataEvent>();
model.addTreeDataListener(new TreeDataListener() {
@Override
public void onChange(TreeDataEvent event) {
events.add(event);
}
});
model.add(model.getRoot(), new ArrayList<Prueba>());
assertThat(events.size(), equalTo(0));
}
@Test
public void aNodeCanBeRemoved() {
MutableTreeModel<Prueba> model = MutableTreeModel.create(Prueba.class);