mercredi 22 juin 2016

Strange behaviour while Testing using Mockito and JUnit

here i am testing a method from TestedClass with signature:

public static boolean getBoolean(ClassA classA);

Here is my mock object configuration.

@Mock
private ClassA mockedCLass;  //I try to mock ClassA behaviour

.....

when(mockedClass.getValues()).thenReturn(null,emptyList,oneElementList,defaultList);

getBoolean() methods uses mocked object. Unfortunately it seems that mock is behaving completely wrong when i use this approach.

boolean res1 = TestedClass.getBoolean(mockedClass);
boolean res2 = TestedClass.getBoolean(mockedClass);
boolean res3 = TestedClass.getBoolean(mockedClass);
boolean res4 = TestedClass.getBoolean(mockedClass);

However when I split things like that:

when(mockedClass.getValues()).thenReturn(null);
boolean res1 = TestedClass.getBoolean(mockedClass);

when(mockedClass.getValues()).thenReturn(emptyList);
boolean res2 = TestedClass.getBoolean(mockedClass);

and so on, everything is fine. What is happening here? I would be grateful for any help.

Aucun commentaire:

Enregistrer un commentaire