lundi 16 novembre 2020

How to avoid skipping methods of mock/spy

My target is to get inside the flow of spy method. I mean, I don't want to skip "manager.createChange(processId);". Actually, I want the test class will take me inside (and then I will do all mockito behavior changes..). For now, I can reach the flow until the method and then the method has been skipped.

I know the code logic may not correct, so please do not focus on that :)

Any help regarding how I suppose to design the test class in order to:

  1. Use manager as a mock/spy (control mockito behavior).
  2. Can be able to run his methods.

My test class:

@RunWith(SpringRunner.class)
public class createChangeTest {

    @Mock
    private ProcessRepository processRepository;
    
    @Mock
    private ProcessManager manager;

    @InjectMocks
    private RequestsImpl Requestsimpl;

    Process p = new Process();

    @Before
    public void setUpBefore() {
        ProcessManager manager = spy(new ProcessManager(processRepository));
    }


    @Test
    public void changeRequestTest() {
        Process p = Requestsimpl.createChange(11l);
    }

inside Requestimpl:

    public Process createChange(Long processId) {
        Process changeRequest = manager.createChange(processId);
        return changeRequest;
    }

Aucun commentaire:

Enregistrer un commentaire