From 0066ced8c824ff2c8b4b73ee5a6750bc42709106 Mon Sep 17 00:00:00 2001 From: Vartika Nigam <63852792+vnigam2702@users.noreply.github.com> Date: Sat, 13 May 2023 21:02:14 +0530 Subject: [PATCH] =?UTF-8?q?BAEL-6264=20added=20class=20to=20show=20how=20t?= =?UTF-8?q?o=20instantiate=20ArrayBlockingQueue=20a=E2=80=A6=20(#13851)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- .../queue/BlockingQueueUnitTest.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 core-java-modules/core-java-concurrency-collections-2/src/test/java/com/baeldung/concurrent/queue/BlockingQueueUnitTest.java diff --git a/core-java-modules/core-java-concurrency-collections-2/src/test/java/com/baeldung/concurrent/queue/BlockingQueueUnitTest.java b/core-java-modules/core-java-concurrency-collections-2/src/test/java/com/baeldung/concurrent/queue/BlockingQueueUnitTest.java new file mode 100644 index 0000000000..e913747f2d --- /dev/null +++ b/core-java-modules/core-java-concurrency-collections-2/src/test/java/com/baeldung/concurrent/queue/BlockingQueueUnitTest.java @@ -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 arrayBlockingQueue = new ArrayBlockingQueue<>(10); + arrayBlockingQueue.add("TestString1"); + arrayBlockingQueue.add("TestString2"); + assertEquals(8, arrayBlockingQueue.remainingCapacity()); + } + + @Test + public void givenLinkedBlockingQueue_whenAddedElements_thenReturnQueueRemainingCapacity() { + BlockingQueue linkedBlockingQueue = new LinkedBlockingQueue<>(10); + linkedBlockingQueue.add("TestString1"); + assertEquals(9, linkedBlockingQueue.remainingCapacity()); + } +} \ No newline at end of file