[concurrency-interest] LinkedBlockingQueue does not throw ClassCastException

David Holmes dcholmes at optusnet.com.au
Mon Apr 16 19:04:34 EDT 2007

You cannot test an unknown concrete implementation against optional parts of
the specification.

For non-optional functionality you can write a generic test to test any

But for optional behaviour you must write the tests against a specific known
concrete implementation. ie if I write a class ListInteger that implements
Collection and only accepts Integer objects, then I can write the tests that
verify that, based on the specification. Now even this can be generalized in
that you can write a test for a type-constrained collection given the
expected type it is constrained to. But the knowledge that you actually have
a type-constrained collections is not evident in the program itself (it
isn't part of the type system, there is no method to query the collection


> -----Original Message-----
> From: Szabolcs Ferenczi [mailto:szabolcs.ferenczi at gmail.com]
> Sent: Tuesday, 17 April 2007 8:58 AM
> To: dholmes at ieee.org
> Cc: Concurrency-interest at cs.oswego.edu
> Subject: Re: [concurrency-interest] LinkedBlockingQueue does not throw
> ClassCastException
> On 17/04/07, David Holmes <dcholmes at optusnet.com.au> wrote:
> > You can't write a test for "optional" behaviour without some
> way of knowing
> > whether the implementation you are testing is trying to support that
> > optional behaviour.
> Strange. If you cannot test it, how can you use it? If it is so
> optional that it can behave any way it likes, what can you use it for?
> I was trying to test it according the documentation.
> "ClassCastException - if the class of the specified element prevents
> it from being added to this queue" I thought, if it is documented, it
> could be tested as well. Sorry.
> Szabolcs

More information about the Concurrency-interest mailing list