the below posted method in the code section returns void. I want to know how to test a method that returns void. I checked some answers but the use "doThrow()" with passing an exception, but in my case the method does not throw any exception
please let me know how can I test a method returns void?
code
public void setImageOnImageView(RequestCreator requestCreator, ImageView imgView) {
requestCreator.into(imgView);
}
testing:
public class ValidationTest {
@Mock
private Context mCtx = null;
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Before
public void setUp() throws Exception {
mCtx = Mockito.mock(Context.class);
Assert.assertNotNull("Context is not null", mCtx);
}
@Test
public void setImageOnImageView() throws Exception {
Uri mockUri = mock(Uri.class);
RequestCreator requestCreator = Picasso.with(mCtx).load(mockUri);
RequestCreator spyRequestCreator = spy(requestCreator);
ImageView imageView = new ImageView(mCtx);
ImageView spyImageView = spy(imageView);
doThrow().when(spyRequestCreator).into(spyImageView);
//spyRequestCreator.into(spyImageView);
}
}