From 19798c4bd600d05178a58391dd9aa4e6c84d78e8 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Thu, 22 Sep 2016 18:16:22 +0200 Subject: [PATCH] Refactor ArrayListTest --- .../java/collections/ArrayListTest.java | 54 +++++++++---------- 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/core-java/src/test/java/org/baeldung/java/collections/ArrayListTest.java b/core-java/src/test/java/org/baeldung/java/collections/ArrayListTest.java index 9cafa179ab..30b0111555 100644 --- a/core-java/src/test/java/org/baeldung/java/collections/ArrayListTest.java +++ b/core-java/src/test/java/org/baeldung/java/collections/ArrayListTest.java @@ -18,18 +18,18 @@ public class ArrayListTest { @Before public void setUp() { - List xs = LongStream.range(0, 16) + List list = LongStream.range(0, 16) .boxed() .map(Long::toHexString) .collect(toCollection(ArrayList::new)); - stringsToSearch = new ArrayList<>(xs); - stringsToSearch.addAll(xs); + stringsToSearch = new ArrayList<>(list); + stringsToSearch.addAll(list); } @Test public void givenNewArrayList_whenCheckCapacity_thenDefaultValue() { - List xs = new ArrayList<>(); - assertTrue(xs.isEmpty()); + List list = new ArrayList<>(); + assertTrue(list.isEmpty()); } @Test @@ -37,29 +37,29 @@ public class ArrayListTest { Collection numbers = IntStream.range(0, 10).boxed().collect(toSet()); - List xs = new ArrayList<>(numbers); - assertEquals(10, xs.size()); - assertTrue(numbers.containsAll(xs)); + List list = new ArrayList<>(numbers); + assertEquals(10, list.size()); + assertTrue(numbers.containsAll(list)); } @Test public void givenElement_whenAddToArrayList_thenIsAdded() { - List xs = new ArrayList<>(); + List list = new ArrayList<>(); - xs.add(1L); - xs.add(2L); - xs.add(1, 3L); + list.add(1L); + list.add(2L); + list.add(1, 3L); - assertThat(Arrays.asList(1L, 3L, 2L), equalTo(xs)); + assertThat(Arrays.asList(1L, 3L, 2L), equalTo(list)); } @Test public void givenCollection_whenAddToArrayList_thenIsAdded() { - List xs = new ArrayList<>(Arrays.asList(1L, 2L, 3L)); + List list = new ArrayList<>(Arrays.asList(1L, 2L, 3L)); LongStream.range(4, 10).boxed() - .collect(collectingAndThen(toCollection(ArrayList::new), ys -> xs.addAll(0, ys))); + .collect(collectingAndThen(toCollection(ArrayList::new), ys -> list.addAll(0, ys))); - assertThat(Arrays.asList(4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L), equalTo(xs)); + assertThat(Arrays.asList(4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L), equalTo(list)); } @Test @@ -106,27 +106,27 @@ public class ArrayListTest { @Test public void givenIndex_whenRemove_thenCorrectElementRemoved() { - List xs = IntStream.range(0, 10).boxed().collect(toCollection(ArrayList::new)); - Collections.reverse(xs); + List list = IntStream.range(0, 10).boxed().collect(toCollection(ArrayList::new)); + Collections.reverse(list); - xs.remove(0); - assertThat(xs.get(0), equalTo(8)); + list.remove(0); + assertThat(list.get(0), equalTo(8)); - xs.remove(Integer.valueOf(0)); - assertFalse(xs.contains(0)); + list.remove(Integer.valueOf(0)); + assertFalse(list.contains(0)); } @Test public void givenListIterator_whenReverseTraversal_thenRetrieveElementsInOppositeOrder() { - List xs = IntStream.range(0, 10).boxed().collect(toCollection(ArrayList::new)); - ListIterator it = xs.listIterator(xs.size()); - List result = new ArrayList<>(xs.size()); + List list = IntStream.range(0, 10).boxed().collect(toCollection(ArrayList::new)); + ListIterator it = list.listIterator(list.size()); + List result = new ArrayList<>(list.size()); while (it.hasPrevious()) { result.add(it.previous()); } - Collections.reverse(xs); - assertThat(result, equalTo(xs)); + Collections.reverse(list); + assertThat(result, equalTo(list)); } @Test