Java Mailing List Archive

http://www.gg3721.com/

Home » user.jmock »

Re: [jmock-user] Mocking Static Methods using JMock

Steve Freeman

2009-12-01

Replies: Find Java Web Hosting

Author LoginPost Reply
We don't support mocking of static methods since there is almost
always a better way. That might mean testing it directly in an
integration test or writing a thin layer above the static method and
testing against /that/.

If your method is as simple as getName() it might be better to just
call the method.
S.

On 1 Dec 2009, at 03:37, Siddhi B <borkar.siddhi@(protected):
> Hi,
>
> I need a way of mocking a static class using JMock. Consider the
> following
> code snippet.
>
> public class A {
>  void functionX() {
>     String name = ClassB.getName(); // Static function
>  }
> }
>
> public class ClassB {
>   static String getName() {
>     return 'ABC'
>   }
> }
>
> I need a way of mocking the static function 'getName'.Please note
> that I do
> not have rights to modify the legacy code.
>
> Any help would be highly appreciated.
>
> Thanks,
> Siddhi
> --
> View this message in context: http://old.nabble.com/Mocking-Static-Methods-using-JMock-tp26585954p26585954.html
> Sent from the jMock - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

  http://xircles.codehaus.org/manage_email


©2008 gg3721.com - Jax Systems, LLC, U.S.A.