BAEL-6264 added class to show how to instantiate ArrayBlockingQueue a… (#13851)

* BAEL-6264 added class to show how to instantiate ArrayBlockingQueue and LinkedBlockingQueue

* BAEL-6264 added unit test case

* modified test case

* BAEL-6264 deleted BlockingQueueImplExample file not needed anymore

* BAEL-6264 code review changes moved class file to different module

---------

Co-authored-by: Vartika_Nigam <Vartika_Nigam@DellTeam.com>
This commit is contained in:
Vartika Nigam 2023-05-13 21:02:14 +05:30 committed by GitHub
parent 535d967fd9
commit e1272ca8fe
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
package com.baeldung.concurrent.queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class BlockingQueueUnitTest {
@Test
public void givenArrayBlockingQueue_whenAddedElements_thenReturnQueueRemainingCapacity() {
BlockingQueue<String> arrayBlockingQueue = new ArrayBlockingQueue<>(10);
arrayBlockingQueue.add("TestString1");
arrayBlockingQueue.add("TestString2");
assertEquals(8, arrayBlockingQueue.remainingCapacity());
}
@Test
public void givenLinkedBlockingQueue_whenAddedElements_thenReturnQueueRemainingCapacity() {
BlockingQueue<String> linkedBlockingQueue = new LinkedBlockingQueue<>(10);
linkedBlockingQueue.add("TestString1");
assertEquals(9, linkedBlockingQueue.remainingCapacity());
}
}