Necronet Necronet - 7 months ago 60
Java Question

Test login three times with mockito throws an Exception!

I have a test but i am not quite good with it, i want to verify that when the methods login is called three times with wrong username and password it throws an exception is this test correct:

public void testLogin_WrongUser_More_Than_Three_Times() {

System.out.println("Testing login With Wrong User More than three Times Method");

Login mock=mock(Login.class);

when(mock.login(username, password)).thenThrow(new TooManyLoginException("Ha intentado entrar demasiadas veces el programa se cerrara"));

for(int i=0;i<4;i++)
mock.login(username, password);


An example might be nice!!


In fact i found a clear explanation here

Now i do understand Mock objects.