Refactor PriorityBlockingQueue examples
package com.baeldung.concurrent.priorityblockingqueue;
-import org.assertj.core.api.Assertions;
import org.junit.Test;
import java.util.ArrayList;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.TimeUnit;
-import java.util.stream.IntStream;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.util.Lists.newArrayList;
@@ -24,11 +22,7 @@ public class PriorityBlockingQueueUnitTest {
queue.add(3);
queue.add(4);
- polledElements.add(queue.poll());
- polledElements.add(queue.poll());
- polledElements.add(queue.poll());
- polledElements.add(queue.poll());
- polledElements.add(queue.poll());
+ queue.drainTo(polledElements);
assertThat(polledElements).containsExactly(1, 2, 3, 4, 5);
}
