Jmockit has worked well for both mocking and stubbing for me. My problem was System.currentTimeMillis and if you can patch that you can patch most anything.
Sent from my iPhone On Feb 22, 2012, at 9:23 AM, Ted Yu <yuzhih...@gmail.com> wrote: > Benoit's comment is directly related to our practice, especially when we > add new methods which are only called by unit tests. > > FYI > > ---------- Forwarded message ---------- > From: tsuna <tsuna...@gmail.com> > Date: Wed, Feb 22, 2012 at 9:13 AM > Subject: Re: asynchbase-1.2.0-rc1 is available for download > To: Jim Scott <j...@13ways.com> > Cc: AsyncHBase <asynchb...@googlegroups.com> > > > On Wed, Feb 22, 2012 at 8:50 AM, Jim Scott <j...@13ways.com> wrote: >> I ask because I am writing some unit tests to make sure that my code is >> working properly and I cannot mock the HBaseClient because it is final. I >> completely understand the rationale to make it final, but without it >> implement an interface or being non-final I cannot mock the object. > > Hi Jim, > OpenTSDB has unit tests that are mocking out HBaseClient just fine > [1]. You can mock out pretty much anything on the JVM: final, > private, JDK stuff, etc. All you need is the right tools. I've been > very happy with PowerMock. It supports Mockito and EasyMock. > > I've never been keen on mutilating public interfaces for the sake of > testing. With tools like PowerMock, we can keep the public APIs tidy > while mocking and overriding anything, even in the most private guts > of the classes. > > [1] > https://github.com/stumbleupon/opentsdb/blob/master/src/uid/TestUniqueId.java#L66 > > -- > Benoit "tsuna" Sigoure > Software Engineer @ www.StumbleUpon.com