Skip to content

Commit e1abedf

Browse files
author
Grzegorz Piwowarek
committed
Refactor RandomListElementTest
1 parent 6eaf0f7 commit e1abedf

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

core-java-8/src/test/java/com/baeldung/RandomListElementTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ public class RandomListElementTest {
1010

1111
@Test
1212
public void givenList_whenRandomIndexChosen_shouldReturnARandomElementUsingRandom() {
13-
List<Integer> givenList = Arrays.asList(1, 2, 3);
13+
List<Integer> givenList = Lists.newArrayList(1, 2, 3);
1414
Random rand = new Random();
1515

1616
givenList.get(rand.nextInt(givenList.size()));
1717
}
1818

1919
@Test
2020
public void givenList_whenRandomIndexChosen_shouldReturnARandomElementUsingMathRandom() {
21-
List<Integer> givenList = Arrays.asList(1, 2, 3);
21+
List<Integer> givenList = Lists.newArrayList(1, 2, 3);
2222

2323
givenList.get((int)(Math.random() * givenList.size()));
2424
}
2525

2626
@Test
2727
public void givenList_whenNumberElementsChosen_shouldReturnRandomElementsRepeat() {
2828
Random rand = new Random();
29-
List<String> givenList = Arrays.asList("one", "two", "three", "four");
29+
List<String> givenList = Lists.newArrayList("one", "two", "three", "four");
3030

3131
int numberOfElements = 2;
3232

@@ -52,7 +52,7 @@ public void givenList_whenNumberElementsChosen_shouldReturnRandomElementsNoRepea
5252

5353
@Test
5454
public void givenList_whenSeriesLengthChosen_shouldReturnRandomSeries() {
55-
List<Integer> givenList = Arrays.asList(1, 2, 3, 4, 5, 6);
55+
List<Integer> givenList = Lists.newArrayList(1, 2, 3, 4, 5, 6);
5656
Collections.shuffle(givenList);
5757

5858
int randomSeriesLength = 3;
@@ -62,7 +62,7 @@ public void givenList_whenSeriesLengthChosen_shouldReturnRandomSeries() {
6262

6363
@Test
6464
public void givenList_whenRandomIndexChosen_shouldReturnElementThreadSafely() {
65-
List<Integer> givenList = Arrays.asList(1, 2, 3, 4, 5, 6);
65+
List<Integer> givenList = Lists.newArrayList(1, 2, 3, 4, 5, 6);
6666
int randomIndex = ThreadLocalRandom.current().nextInt(10) % givenList.size();
6767

6868
givenList.get(randomIndex);

0 commit comments

Comments
 (0)