import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import java.util.Collection;
charQueue = new BufferedBlockingQueue<>(15, 15);
}
+ /**
+ * Test with chunkSize = 1 and buffer queueSize = 1
+ */
+ public void testValidConstructor1() {
+ assertNotNull(new BufferedBlockingQueue<>(1, 1));
+ }
+
+ /**
+ * Test with chunkSize = 0 and buffer queueSize = 0
+ * <p>
+ * Should fail with an {@link IllegalArgumentException}
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidConstructor1() {
+ assertNotNull(new BufferedBlockingQueue<>(0, 0));
+ }
+
+ /**
+ * Test with chunkSize = 0 and buffer queueSize = 1
+ * <p>
+ * Should fail with an {@link IllegalArgumentException}
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidConstructor2() {
+ assertNotNull(new BufferedBlockingQueue<>(1, 0));
+ }
+
+ /**
+ * Test with chunkSize = 1 and buffer queueSize = 0
+ */
+ public void testInvalidConstructor3() {
+ assertNotNull(new BufferedBlockingQueue<>(0, 1));
+ }
+
+ /**
+ * Test with chunkSize = 1 and buffer queueSize =-1
+ * <p>
+ * Should fail with an {@link IllegalArgumentException}
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidConstructor4() {
+ assertNotNull(new BufferedBlockingQueue<>(-1, 1));
+ }
+
+ /**
+ * Test with chunkSize = -1 and buffer queueSize = 1
+ * <p>
+ * Should fail with an {@link IllegalArgumentException}
+ */
+ @Test(expected = IllegalArgumentException.class)
+ public void testInvalidConstructor5() {
+ assertNotNull(new BufferedBlockingQueue<>(1, -1));
+ }
+
/**
* Test inserting one element and removing it.
*/
*
* @param queueSize
* The size of the actual blocking queue. This is the number of
- * *chunks* that will go in the queue.
+ * additional *chunks* that will go in the queue. The value must
+ * be larger or equal to 0.
* @param chunkSize
- * The size of an individual chunk.
+ * The size of an individual chunk. The value must be larger than
+ * 0.
*/
public BufferedBlockingQueue(int queueSize, int chunkSize) {
+ if (queueSize < 0) {
+ throw new IllegalArgumentException("queueSize must be >= 0"); //$NON-NLS-1$
+ }
+ if (chunkSize <= 0) {
+ throw new IllegalArgumentException("chunkSize must be > 0"); //$NON-NLS-1$
+ }
/* Add one to the queue size for the output buffer */
fInnerQueue = new LinkedBlockingDeque<>(queueSize + 1);
fChunkSize = chunkSize;