Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Unable to use PowerMockRunner along with Assertj

Open
#225 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
25/100
Issue type
Bug
Clarity
Needs clarification
Activity status
Stale
Tech stack
java
Domain
desktop, testing

Research direction

Start by reproducing the reported interaction between PowerMockRunner, AssertJ, JUnit, and the minimal Backend/GUI scenario described in the issue. Verify whether Backend.m1() is intercepted when the GUI is initialized and whether its dependent methods are avoided; done means the static method remains mocked in the combined test class.

Written by the indexing model from the issue text.

Description

I started using Assertj for unit testing for GUI related code in my application. But I stumbled across an issue when I was trying to use PowerMockito.mockStatic() along with assertj in the same test class.
In my application, along with the swing related components initialization, I have some backend related code which is a static method, so I need to use PowerMockito.mockStatic() to mock those static method calls. But what actually happening is, it is not returning the mocked object instead it is calling the actual method without being mocked.

Due to company policy, I can't share the code, but this is the scenario I'm facing :

/*The actual code is similar to this representation  */
class Backend
{
public static void m1()
{
// some lines which does registration and doesn't return any value
}
}
class GUI
{
// GUI LINES
Backend.m1(); //This is where code says error saying initialization error. 
}

Actually the calling is being made to m1() and it m1() is calling other internal classes.
When i mock the class, it is not supposed to call the other methods dependent on m1(), which is not the case when im using assertj in my junit.
So i would like someone to look into the issue of using PowerMockRunner along with assertj.

Dominant language
Java
Stars
121
Forks
52
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from assertj/assertj-swing

All issues in assertj/assertj-swing

Similar issues

More Java issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.