junit - Is there a type parameter matcher in hamcrest? -


I want to test a method like this

  public list & lt; String & gt; GiveStrings ();  

I can test for the returned type using the Hamrocast, for example

  assertThat (giveStrings (), instanceOf (ArrayList.class) );  

But I want to know whether it is a list of strings.

So simple answer is not because it runs on runtime Type-error so that all generators are converted to objects . Then your list at runtime & lt; String & gt; In fact only one list or list & lt; Object & gt; . Type information of string is lost.

Consider using

  IsIterableContainingInOrder.containsInOrder (CoreMatchers.instanceOf (String.class), ...)  

Per comment, use

  assertThat (myList, Every.everyItem (instanceOf (String.class));  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -