Java Code Examples for java.util.Collections#checkedQueue()

The following examples show how to use java.util.Collections#checkedQueue() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/**
 * This test tests the CheckedQueue.offer method.
 */
@Test
public void testOffer() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    try {
        q.offer(null);
        fail("should throw NullPointerException.");
    } catch (NullPointerException npe) {
        // Do nothing
    }

    try {
        q.offer(0);
        fail("should throw ClassCastException.");
    } catch (ClassCastException cce) {
        // Do nothing
    }

    assertTrue(q.offer("0"), "queue should have room");

    // no room at the inn!
    assertFalse(q.offer("1"), "queue should be full");
}
 
Example 2
/**
 * This test adds items to a queue.
 */
@Test
public void testAdd() {
    int arrayLength = 10;
    Queue<String> abq = Collections.checkedQueue(new ArrayBlockingQueue<>(arrayLength), String.class);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    try {
        abq.add("full");
    } catch (IllegalStateException full) {

    }
}
 
Example 3
/**
 * This test tests the CheckedQueue.offer method.
 */
@Test
public void testOffer() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    try {
        q.offer(null);
        fail("should throw NullPointerException.");
    } catch (NullPointerException npe) {
        // Do nothing
    }

    try {
        q.offer(0);
        fail("should throw ClassCastException.");
    } catch (ClassCastException cce) {
        // Do nothing
    }

    assertTrue(q.offer("0"), "queue should have room");

    // no room at the inn!
    assertFalse(q.offer("1"), "queue should be full");
}
 
Example 4
/**
 * This test adds items to a queue.
 */
@Test
public void testAdd() {
    int arrayLength = 10;
    Queue<String> abq = Collections.checkedQueue(new ArrayBlockingQueue<>(arrayLength), String.class);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    try {
        abq.add("full");
    } catch (IllegalStateException full) {

    }
}
 
Example 5
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of
 * {@code String}s gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
private void test01() throws Exception {
    int arrayLength = 10;
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(arrayLength + 1);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(new String(Integer.toString(i)));
    }

    Queue q = Collections.checkedQueue(abq, String.class);

    try {
        q.add(new Integer(0));
        throw new Exception(this.getClass().getName() + "." + "test01 test"
                + " failed, should throw ClassCastException.");
    } catch(ClassCastException cce) {
        // Do nothing.
    }
}
 
Example 6
/**
 * This test adds items to a queue.
 */
@Test
public void testAdd() {
    int arrayLength = 10;
    Queue<String> abq = Collections.checkedQueue(new ArrayBlockingQueue<>(arrayLength), String.class);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    try {
        abq.add("full");
    } catch (IllegalStateException full) {

    }
}
 
Example 7
/**
 * This test tests the CheckedQueue.offer method.
 */
@Test
public void testOffer() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    try {
        q.offer(null);
        fail("should throw NullPointerException.");
    } catch (NullPointerException npe) {
        // Do nothing
    }

    try {
        q.offer(0);
        fail("should throw ClassCastException.");
    } catch (ClassCastException cce) {
        // Do nothing
    }

    assertTrue(q.offer("0"), "queue should have room");

    // no room at the inn!
    assertFalse(q.offer("1"), "queue should be full");
}
 
Example 8
/**
 * This test tests the CheckedQueue.offer method.
 */
@Test
public void testOffer() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    try {
        q.offer(null);
        fail("should throw NullPointerException.");
    } catch (NullPointerException npe) {
        // Do nothing
    }

    try {
        q.offer(0);
        fail("should throw ClassCastException.");
    } catch (ClassCastException cce) {
        // Do nothing
    }

    assertTrue(q.offer("0"), "queue should have room");

    // no room at the inn!
    assertFalse(q.offer("1"), "queue should be full");
}
 
Example 9
/**
 * This test adds items to a queue.
 */
@Test
public void testAdd() {
    int arrayLength = 10;
    Queue<String> abq = Collections.checkedQueue(new ArrayBlockingQueue<>(arrayLength), String.class);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    try {
        abq.add("full");
    } catch (IllegalStateException full) {

    }
}
 
Example 10
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of
 * {@code String}s gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail1() {
    int arrayLength = 10;
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(arrayLength + 1);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    Queue q = Collections.checkedQueue(abq, String.class);
    q.add(0);
}
 
Example 11
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of
 * {@code String}s gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail1() {
    int arrayLength = 10;
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(arrayLength + 1);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    Queue q = Collections.checkedQueue(abq, String.class);
    q.add(0);
}
 
Example 12
/**
 * This test tests the CheckedQueue.offer method.
 */
private void test04() throws Exception {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    try {
        q.offer(null);
        throw new Exception(this.getClass().getName() + "." + "test04 test"
                + " failed, should throw NullPointerException.");
    } catch (NullPointerException npe) {
        // Do nothing
    }

    try {
        q.offer(new Integer(0));
        throw new Exception(this.getClass().getName() + "." + "test04 test"
                + " failed, should throw ClassCastException.");
    } catch (ClassCastException cce) {
        // Do nothing
    }

    q.offer(new String("0"));

    try {
        q.offer(new String("1"));
        throw new Exception(this.getClass().getName() + "." + "test04 test"
                + " failed, should throw IllegalStateException.");
    } catch(IllegalStateException ise) {
        // Do nothing
    }
}
 
Example 13
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of one
 * {@code String}, gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
private void test02() throws Exception {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    try {
        q.add(new Integer(0));
        throw new Exception(this.getClass().getName() + "." + "test02 test"
                + " failed, should throw ClassCastException.");
    } catch(ClassCastException e) {
        // Do nothing.
    }
}
 
Example 14
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of one
 * {@code String}, gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail2() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    q.add(0);
}
 
Example 15
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of
 * {@code String}s gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail1() {
    int arrayLength = 10;
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(arrayLength + 1);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    Queue q = Collections.checkedQueue(abq, String.class);
    q.add(0);
}
 
Example 16
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of one
 * {@code String}, gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail2() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    q.add(0);
}
 
Example 17
/**
 * This test tests the CheckedQueue.offer method.
 */
private void test04() throws Exception {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    try {
        q.offer(null);
        throw new Exception(this.getClass().getName() + "." + "test04 test"
                + " failed, should throw NullPointerException.");
    } catch (NullPointerException npe) {
        // Do nothing
    }

    try {
        q.offer(new Integer(0));
        throw new Exception(this.getClass().getName() + "." + "test04 test"
                + " failed, should throw ClassCastException.");
    } catch (ClassCastException cce) {
        // Do nothing
    }

    q.offer(new String("0"));

    try {
        q.offer(new String("1"));
        throw new Exception(this.getClass().getName() + "." + "test04 test"
                + " failed, should throw IllegalStateException.");
    } catch(IllegalStateException ise) {
        // Do nothing
    }
}
 
Example 18
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of
 * {@code String}s gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail1() {
    int arrayLength = 10;
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(arrayLength + 1);

    for (int i = 0; i < arrayLength; i++) {
        abq.add(Integer.toString(i));
    }

    Queue q = Collections.checkedQueue(abq, String.class);
    q.add(0);
}
 
Example 19
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of one
 * {@code String}, gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail2() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    q.add(0);
}
 
Example 20
/**
 * This test tests the CheckedQueue.add method.  It creates a queue of one
 * {@code String}, gets the checked queue, and attempt to add an Integer to
 * the checked queue.
 */
@Test(expectedExceptions = ClassCastException.class)
public void testAddFail2() {
    ArrayBlockingQueue<String> abq = new ArrayBlockingQueue(1);
    Queue q = Collections.checkedQueue(abq, String.class);

    q.add(0);
}