mockito answers with method with more than one argument

218 views
Skip to first unread message

benj...@needstyping.com

unread,
Apr 27, 2015, 8:18:47 AM4/27/15
to specs2...@googlegroups.com
Hi

I am struggling to get specs2 to use mockito answers with a method that has 2 arguments.  According to the specs2 documentation this should provide a function taking an object array with the method argument values.


I have attached a sample Spec.  The first one example with a single argument works but the second one with two arguments gives me a ClassCastException.

Any ideas or examples greatly appreciated.

Cheers

Ben


AnswersSpec.scala

etorreborre

unread,
Apr 27, 2015, 6:32:34 PM4/27/15
to specs2...@googlegroups.com
Hi Ben,

You have a typo in your code:

  private def toArray(a: Any) = 
    a.asInstanceOf[Array[Object]]

You wrote "p" instead of "a", but "p" is a specs2 formatting fragment to start a paragraph. This is why you get a classcast exception saying that

   org.specs2.specification.core.Fragments cannot be cast to [Ljava.lang.Object;

If you fix your method your test should pass ok.

Eric.

Benjamin Parker

unread,
May 7, 2015, 1:50:14 AM5/7/15
to specs2...@googlegroups.com
Hi Eric

Thanks for that. So it was the choice of p as a variable name that was the problem!

I wonder if the signature of answers could be a little more friendly? Is it possible to have an Array[Any] then the initial cast wouldn't be required, only conversions for each argument in the array. 

Ben Parker
(sent from my iPhone)
--
You received this message because you are subscribed to a topic in the Google Groups "specs2-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/specs2-users/3AugIXMFxl4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to specs2-users...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages