Alex
unread,Sep 22, 2010, 8:56:34 AM9/22/10Sign 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,
what about adding a method reset(Class<?>... classes) to PowerMockito?
There is a reset method in the original Mockito but it only takes mock
objects and it's not possible to use it for classes that were mocked
using mockStatic.
I know that reset is generally considered bad practice but I don't
think there's another solution to my problem.
I want to do the following:
1) At set up the test needs to instantiate an object. During the
constructor several static methods on another class
are invoked
2) Now I want to test a specific method called print() of the
instantiated object. The method print() calls some of the static
methods that were also called by the constructor
3) Now I need to say verifyStatic(times(2)) in my test which I think
is really bad because I want to specify only what the method print()
does
If you wonder how bad my code must be if a constructor invokes the
same static methods that a method called print() invokes ... well I
think it sounds really ugly indeed ^ ^ But it's because I'm
programming OpenGL. In the constructor the object is initialized
calling GL11.glBindTexture(...) to load a texture into OpenGL. In the
print method this is again called to bind the texture to the current
OpenGL state.
@Test
public void print() throws Exception {
mockOpenGL();
mockGlGenBuffers(new IntGenerator());
BitmapFont bitmapFont = new BitmapFont(...);
bitmapFont.print("A", new Point(33.42f, 21.04f), new Color(0, 1, 2,
3));
// @formatter:off
verifyStatic(); GL11.glPushAttrib(GL11.GL_CURRENT_BIT);
verifyStatic(); GL11.glColor4f(0, 1, 2, 3);
verifyStatic(Mockito.times(2));
GL11.glBindTexture(eq(GL11.GL_TEXTURE_2D), anyInt()); <-- SEE THIS
LINE
....