0

I'm writing test cases for Legacy code. I have a scenario like this.

class A
{
  static final X = getUI().getResourceX();

  A(){}

  ....some methods to test....

}

I have to create spy object from class A. But while creating object it calls getUI method which returns null and it caused a NullpointerException. So, how I eliminate getting null from getUI method?

Madhujith
  • 157
  • 4
  • 18

1 Answers1

0

First I would advise to have a look here: How to mock a static final variable using JUnit, EasyMock or PowerMock

In general, to fix your issue you can go with this:

     Mockito.when(getUI().getResourceX()).thenReturn(whatYouNeed);
Community
  • 1
  • 1
Rufi
  • 2,529
  • 1
  • 20
  • 41