Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to initialize IssueService for unit testing?

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
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you