ItEr24S01Coordinacion: Renaming method, adding javadoc and adding test to reflect intended behaviour

This commit is contained in:
Óscar González Fernández 2009-09-01 13:22:18 +02:00
parent dbb46d3194
commit 287629064e
2 changed files with 19 additions and 6 deletions

View file

@ -50,7 +50,12 @@ public class ListSorter<T> {
Collections.sort(this.list, this.comparator);
}
public List<T> toList() {
/**
* Called to retrieve a view to a list that will be kept sorted and updated
* with modifications
* @return an unmodifiable view of the list. It's sorted
*/
public List<T> toListView() {
return Collections.unmodifiableList(list);
}

View file

@ -39,7 +39,7 @@ public class ListSorterTest {
@Test
public void itSortsInitialElements() {
givenSortedList();
assertThat(listSorter.toList(), equalTo(containers("A", "B", "C")));
assertThat(listSorter.toListView(), equalTo(containers("A", "B", "C")));
}
private static List<DumbContainer> containers(String... strings) {
@ -53,7 +53,15 @@ public class ListSorterTest {
@Test(expected = UnsupportedOperationException.class)
public void theListReturnedCannotBeModified() {
givenSortedList();
listSorter.toList().clear();
listSorter.toListView().clear();
}
@Test
public void theListKeepsTrackOfChanges() {
givenSortedList();
List<DumbContainer> listView = listSorter.toListView();
listSorter.add(new DumbContainer("D"));
assertThat(listView, equalTo(containers("A", "B", "C", "D")));
}
@Test
@ -62,7 +70,7 @@ public class ListSorterTest {
DumbContainer first = initialElements.get(0);
first.setData("D");
listSorter.modified(first);
assertThat(listSorter.toList(), equalTo(containers("B", "C", "D")));
assertThat(listSorter.toListView(), equalTo(containers("B", "C", "D")));
}
@Test(expected = NoSuchElementException.class)
@ -87,7 +95,7 @@ public class ListSorterTest {
public void addInsertsAtRightPosition() {
givenSortedList();
listSorter.add(new DumbContainer("0"));
assertThat(listSorter.toList(), equalTo(containers("0", "A", "B", "C")));
assertThat(listSorter.toListView(), equalTo(containers("0", "A", "B", "C")));
}
@Test(expected = NoSuchElementException.class)
@ -100,7 +108,7 @@ public class ListSorterTest {
public void removingExistent() {
givenSortedList();
listSorter.remove(initialElements.get(0));
assertThat(listSorter.toList(), equalTo(containers("B", "C")));
assertThat(listSorter.toListView(), equalTo(containers("B", "C")));
}
}