From 8ec4c8c265d7c67a5ea5748de2d916a5e463f39a Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 5 Oct 2016 07:50:21 +0200 Subject: [PATCH] Refactor --- .../src/test/java/com/baeldung/RandomListElementTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 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 540a8c0af9..c6d4ded104 100644 --- a/core-java-8/src/test/java/com/baeldung/RandomListElementTest.java +++ b/core-java-8/src/test/java/com/baeldung/RandomListElementTest.java @@ -1,5 +1,6 @@ package com.baeldung; +import com.google.common.collect.Lists; import org.junit.Test; import java.util.*; @@ -38,7 +39,7 @@ public class RandomListElementTest { @Test public void givenList_whenNumberElementsChosen_shouldReturnRandomElementsNoRepeat() { Random rand = new Random(); - List givenList = new LinkedList<>(Arrays.asList("one", "two", "three", "four")); + List givenList = Lists.newArrayList("one", "two", "three", "four"); int numberOfElements = 2; @@ -62,7 +63,7 @@ public class RandomListElementTest { @Test public void givenList_whenRandomIndexChosen_shouldReturnElementThreadSafely() { List givenList = Arrays.asList(1, 2, 3, 4, 5, 6); - int randomIndex = ThreadLocalRandom.current().nextInt(10); + int randomIndex = ThreadLocalRandom.current().nextInt(10) % givenList.size(); givenList.get(randomIndex); }