vendredi 15 avril 2016

Return custom value(String) from method if this method is void using Mokito testing

tried

doAnswer(new Answer<String>() {
                @Override
                public String answer(InvocationOnMock invocation) throws Throwable {               
                    return "String";
                }
            }).when(object).voidMethod();
            Assert.assertEquals("String",object.voidMethod()); 

and

doReturn("String").when(object.voidMethod())

but this not works because voidMethod() is void. Is any variants not to use doThrow()?

Aucun commentaire:

Enregistrer un commentaire