bdusauso
unread,Oct 21, 2011, 10:23:25 AM10/21/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to PowerMock
Hi,
Nearly everything is in the title.
I've already search the documentation and the web but, as you've
guessed it, found nothing.
That's why I'm asking here.
I'm trying to mock a final class having a static method (which is
called).
I'm using PowerMock 1.4.10 with Mockito and TestNG.
Here's the kind of things I'm trying to do.
It's not the real project but it reproduces exactly what I'm trying to
do :
@ContextConfiguration(locations = {"classpath:application-context-
test.xml"})
@PrepareForTest(Misc.class)
public class UserDaoImplTest extends AbstractTestNGSpringContextTests
{
@Autowired
private UserDao userDao;
@Test
public void testPersist() {
mockStatic(Misc.class);
when(Misc.dummyMethod()).thenReturn(true);
User user = new User();
user.setFirstName("Bruno");
user.setLastName("Dusausoy");
userDao.persist(user);
}
}
My UserDao calls Misc.dummyMethod() and thus it is what I'm trying to
mock.
I've found the way to do it with JUnit, thanks to the rule, but
unfortunately I'm stuck with TestNG, at least on a bunch of specific
projects.
Any pointers ?
Regards.