How to initialize IssueService for unit testing?

Jan Bacz December 9, 2019

I have read following post: https://community.atlassian.com/t5/Jira-questions/How-to-mock-the-IssueService/qaq-p/1029014?tempId=eyJvaWRjX2NvbnNlbnRfbGFuZ3VhZ2VfdmVyc2lvbiI6IjEuMCIsIm9pZGNfY29uc2VudF9ncmFudGVkX2F0IjoxNTc1OTEzOTY5NzQ0fQ%3D%3D

 

but it didn't provide answer for my problem.

 

I have class like this:

 

...
public MyProcessor {

    ...
    private IssueService;

    public MyProcessor(..., IssueService issueService) {
        ...
        this.issueService = issueService;
    }

    public void run() {
        ...
        IssueInputParameters issueInputParameters = issueService.newIssueInputParameters(); // NullPointerException: issueService is NULL !!!
    }
    ...
}


...



 IssueService should be injected in production code but how to inject it with uni tests?

I have tried ComponentAccessor, but it returns NULL!!!

```

public MyProcessorTest{

    @Test
    public void myTest() {
        ...
        new MockComponentWorker().init();
        IssueService issueService = ComponentAccessor.getIssueService(); // NULL!!!
        MyProcessor myProcessor = new MyProcessor(..., issueService);
        myProcessor.run(); // NullPointerException!
        ...
    }
}
```

0 answers

Suggest an answer

Log in or Sign up to answer