Necronet Necronet - 23 days ago 15
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:

@Test(expected=Login.TooManyLoginException.class)
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!!

Answer

In fact i found a clear explanation here

http://schuchert.wikispaces.com/Mockito.LoginServiceExample

Now i do understand Mock objects.