| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- package pl.konrad;
- import org.junit.jupiter.api.Test;
- import org.mockito.ArgumentCaptor;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.mockito.Mockito.*;
- public class DirConverterBehaviourTest {
- DirConverter dirConverter = mock(DirConverter.class);
- @Test
- public void testBehaviourWithDoNothing() {
- doNothing().when(dirConverter).convert("", ".xml");
- dirConverter.convert("", ".xml");
- verify(dirConverter, times(1)).convert("", ".xml");
- }
- @Test
- public void testBehaviourWithArgumentCaptor() {
- ArgumentCaptor<String> valueCapture = ArgumentCaptor.forClass(String.class);
- doNothing().when(dirConverter).convert(anyString(), valueCapture.capture());
- dirConverter.convert("","captured");
- assertEquals("captured",valueCapture.getValue());
- }
- @Test
- public void testBehaviourWithCalledAnswer(){
- doAnswer(invocationOnMock -> {
- Object arg0 = invocationOnMock.getArgument(0);
- Object arg1 = invocationOnMock.getArgument(1);
- assertEquals("filepath", arg0);
- assertEquals(".json", arg1);
- return null;
- }).when(dirConverter).convert(anyString(),anyString());
- dirConverter.convert("filepath",".json");
- }
- @Test
- public void testBehaviourWithPartialMocking(){
- doCallRealMethod().when(dirConverter).convert(anyString(),anyString());
- dirConverter.convert("pathToDirectory",".xml");
- verify(dirConverter,times(1)).convert("pathToDirectory",".xml");
- }
- }
|