lundi 5 septembre 2016

PowerMockito: stub any new object of given type

I have a method implementing an authentification process with a server. If connecntion fails, the code will wait some time and then try again. I want to test this method now, but I do not want to wait several minutes, so I think I have to stub the array, in which the waiting durations are stored. Now the problem is that this array is a local variable somewhere deep down in my code and stubbing local variables doesn't work with Mockito/PowerMockito as far as I could find out. Also extracting the definition of the array to an own method does not work without things getting extremly messy. My idea was now to just replace any newly created int array with a predfined array with shorter waiting times. Is there any possibility to do this?

Aucun commentaire:

Enregistrer un commentaire