mlinhard / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

Convenience OngoingStubbing.thenThrow method in mockito for JVM 1.4 #259

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Hello,

first of all thanks for this great product! I am just getting into unit testing 
with mockito, and it appeals to me very much.

Unfortunately I am bound to writing 1.4-compatible Java code, therefore I 
decided to also go with 1.4-compatible unit tests. Luckily, there is the 
mockito for JVM 1.4 library, thanks a lot to James Carr.

In this library, the OngoingStubbing.thenThrow method is defined like this:
public OngoingStubbing thenThrow(Throwable[] paramArrayOfThrowable);

This leads to slightly more verbose test code:
when(mockRef.doSomething()).thenThrow(new Throwable[] { new RuntimeException() 
});

I would appreciate it if you could add a shorthand convenience method like this:
public OngoingStubbing thenThrow(Throwable paramThrowable);

such that the test code becomes easier as if running a 1.6 test:
when(mockRef.doSomething()).thenThrow(new RuntimeException());

Is this actually possible or is the downport an automatic compilation where all 
varargs are converted into array arguments?

Thanks for support,
Björn

What version of the product are you using? On what operating system?
mockito-all-jvm14-1.8.0.jar

Original issue reported on code.google.com by bjoern.g...@gmail.com on 3 May 2011 at 7:29

GoogleCodeExporter commented 9 years ago
Hm,

was the type automatically set to "defect" and the priority to "medium"? This 
should of course be an "enhancement" of "low" priority.

Original comment by bjoern.g...@gmail.com on 3 May 2011 at 7:31

GoogleCodeExporter commented 9 years ago

Original comment by brice.du...@gmail.com on 5 May 2011 at 12:46

GoogleCodeExporter commented 9 years ago
Ask James to tweak it for you :) He should be lingering on the users' mailing 
list.

Original comment by szcze...@gmail.com on 5 May 2011 at 7:55

GoogleCodeExporter commented 9 years ago
Eh, I'll tweak it for you. That really is something that I should host on a 
special branch or as a separate project on github so that the code is 
available. :) 

Original comment by james.r....@gmail.com on 6 May 2011 at 1:52

GoogleCodeExporter commented 9 years ago
Actually, I responded too quick. I didn't touch the source code of Mockito for 
this and the array is a result of backporting varargs to Array for JDK 1.4. The 
most I could recommend is a convenience method like

when(mockRef.doSomething()).thenThrow(exception(new RuntimeException()))

to wrap it in a new Throwable[]{}. 

Original comment by james.r....@gmail.com on 6 May 2011 at 1:55

GoogleCodeExporter commented 9 years ago
James, if you want to maintain 1.4 I can pull to you to the team, give you 
commit rights, etc. Let me know if you're interested. Cheers ;)

Original comment by szcze...@gmail.com on 6 May 2011 at 2:49

GoogleCodeExporter commented 9 years ago
Hello,

I will follow James' advice to provide a method like Throwable[] 
oneException(Throwable t) 

Thanks for the replies. I suppose the issue can then be closed.

Björn

Original comment by bjoern.g...@gmail.com on 13 May 2011 at 6:55