-
Notifications
You must be signed in to change notification settings - Fork 54.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Queue to list conversion * Queue to list conversion * Queue to list conversion * Queue to list conversion * Queue to list conversion * Queue to list conversion --------- Co-authored-by: Neetika Khandelwal <kwal.neetika2398@gmail.com>
- Loading branch information
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
...ions-conversions-3/src/test/java/com/baeldung/queuetolist/QueueToListConvertUnitTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.baeldung.queuetolist; | ||
|
||
import com.google.common.collect.Lists; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.*; | ||
import java.util.stream.Collectors; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class QueueToListConvertUnitTest { | ||
|
||
private Queue<String> queue; | ||
|
||
@BeforeEach | ||
public void beforeEach() { | ||
queue = new LinkedList<>(); | ||
queue.add("AA"); | ||
queue.add("BB"); | ||
queue.add("CC"); | ||
} | ||
|
||
@Test | ||
public void givenAQueue_whenConvertUsingConstructor_thenReturnArrayList() { | ||
List<String> list = new ArrayList<>(queue); | ||
|
||
assertNotNull(list); | ||
assertEquals(queue.size(), list.size()); | ||
assertTrue(list.containsAll(queue)); | ||
} | ||
|
||
@Test | ||
public void givenAQueue_whenConvertUsingAddAllMethod_thenReturnList() { | ||
List<String> list = new ArrayList<>(); | ||
list.addAll(queue); | ||
|
||
assertNotNull(list); | ||
assertEquals(queue.size(), list.size()); | ||
assertTrue(list.containsAll(queue)); | ||
} | ||
|
||
@Test | ||
public void givenAQueue_whenConvertUsingConstructor_thenReturnLinkedList() { | ||
LinkedList<String> list = new LinkedList<>(queue); | ||
|
||
assertNotNull(list); | ||
assertEquals(queue.size(), list.size()); | ||
assertTrue(list.containsAll(queue)); | ||
} | ||
|
||
@Test | ||
public void givenAQueue_whenConvertUsingStream_thenReturnList() { | ||
List<String> list = queue.stream() | ||
.collect(Collectors.toList()); | ||
|
||
assertNotNull(list); | ||
assertEquals(queue.size(), list.size()); | ||
assertTrue(list.containsAll(queue)); | ||
} | ||
|
||
@Test | ||
public void givenAQueue_whenConvertUsingGuava_thenReturnList() { | ||
List<String> list = Lists.newArrayList(queue); | ||
|
||
assertNotNull(list); | ||
assertEquals(queue.size(), list.size()); | ||
assertTrue(list.containsAll(queue)); | ||
} | ||
} |