[concurrency-interest] LinkedBlockingQueue does not throw ClassCastException

Hanson Char hanson.char at gmail.com
Mon Apr 16 19:42:03 EDT 2007


Ever considered the use of Collections.checkedCollection(Collection<E>,
Class<E>) ?  That will provide you with runtime type checking.

Hanson Char

On 4/16/07, Szabolcs Ferenczi <szabolcs.ferenczi at gmail.com> wrote:
>
> I am trying to test LinkedBlockingQueue and I cannot get the class
> cast test for method add through:
>
> public class lbqTest {
>
>     LinkedBlockingQueue q;
>
>     @Before
>     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
> method.
>
> What is wrong? How can I get the test pass?
>
> Best Regards,
> Szabolcs
> _______________________________________________
> Concurrency-interest mailing list
> Concurrency-interest at altair.cs.oswego.edu
> http://altair.cs.oswego.edu/mailman/listinfo/concurrency-interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: /pipermail/attachments/20070416/5f2eff3c/attachment.html 


More information about the Concurrency-interest mailing list