From e1abedf15e2b82d14795903e5f5c26fbeaea141a Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Fri, 7 Oct 2016 12:03:53 +0200 Subject: [PATCH] Refactor RandomListElementTest --- .../test/java/com/baeldung/RandomListElementTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/core-java-8/src/test/java/com/baeldung/RandomListElementTest.java b/core-java-8/src/test/java/com/baeldung/RandomListElementTest.java index c6d4ded104..1918c801dc 100644 --- a/core-java-8/src/test/java/com/baeldung/RandomListElementTest.java +++ b/core-java-8/src/test/java/com/baeldung/RandomListElementTest.java @@ -10,7 +10,7 @@ public class RandomListElementTest { @Test public void givenList_whenRandomIndexChosen_shouldReturnARandomElementUsingRandom() { - List givenList = Arrays.asList(1, 2, 3); + List givenList = Lists.newArrayList(1, 2, 3); Random rand = new Random(); givenList.get(rand.nextInt(givenList.size())); @@ -18,7 +18,7 @@ public class RandomListElementTest { @Test public void givenList_whenRandomIndexChosen_shouldReturnARandomElementUsingMathRandom() { - List givenList = Arrays.asList(1, 2, 3); + List givenList = Lists.newArrayList(1, 2, 3); givenList.get((int)(Math.random() * givenList.size())); } @@ -26,7 +26,7 @@ public class RandomListElementTest { @Test public void givenList_whenNumberElementsChosen_shouldReturnRandomElementsRepeat() { Random rand = new Random(); - List givenList = Arrays.asList("one", "two", "three", "four"); + List givenList = Lists.newArrayList("one", "two", "three", "four"); int numberOfElements = 2; @@ -52,7 +52,7 @@ public class RandomListElementTest { @Test public void givenList_whenSeriesLengthChosen_shouldReturnRandomSeries() { - List givenList = Arrays.asList(1, 2, 3, 4, 5, 6); + List givenList = Lists.newArrayList(1, 2, 3, 4, 5, 6); Collections.shuffle(givenList); int randomSeriesLength = 3; @@ -62,7 +62,7 @@ public class RandomListElementTest { @Test public void givenList_whenRandomIndexChosen_shouldReturnElementThreadSafely() { - List givenList = Arrays.asList(1, 2, 3, 4, 5, 6); + List givenList = Lists.newArrayList(1, 2, 3, 4, 5, 6); int randomIndex = ThreadLocalRandom.current().nextInt(10) % givenList.size(); givenList.get(randomIndex);