[concurrency-interest] LinkedBlockingQueue does not throw ClassCastException

Szabolcs Ferenczi szabolcs.ferenczi at gmail.com
Mon Apr 16 15:00:09 EDT 2007

I am trying to test LinkedBlockingQueue and I cannot get the class
cast test for method add through:

public class lbqTest {

    LinkedBlockingQueue q;

    public void setUp() {
	q = new LinkedBlockingQueue<Integer>(3);

    @Test (expected=ClassCastException.class)
    public void seqAddNonmatchingArg() {
	q.add(new String("x"));

What I receive is this:

There was 1 failure:
1) seqAddNonmatchingArg(lbqTest.lbqTest)
java.lang.AssertionError: Expected exception: java.lang.ClassCastException

I would expect a successful test according to the documentation of the

What is wrong? How can I get the test pass?

Best Regards,

More information about the Concurrency-interest mailing list