0

I have the following setup :

Class to test : SeriesOffset which extends BaseDisplayOption

Test Class : SeriesOffsetTest

When creating an object of the SeriesOffset class to test it, the constructor of the same makes a super call which then makes the following method call :

 logger = LoggingService.getLog(this.getClass());

where LoggingService is an abstract class and getLog(Class<?> clazz) is a static method with a generic class parameter. This very method call needs to be mocked. I created a mock implementation for the same with a class called ILogImpl and this is how I am trying to test it:

    ILogImpl a = new ILogImpl();
    PowerMockito.mockStatic(LoggingService.class);
    PowerMockito.when(LoggingService.getLog( SeriesOffset.class)).thenReturn(a);

But this method doesnt seem to work and it calls the real implementation instead of the mock one that I need it to call. The error trace is the following : error trace

Parth Mody
  • 438
  • 1
  • 5
  • 17

1 Answers1

0

According to the error trace, I don't see where your real implementation of getLog is being called—but the real class initializer ("clinit") is being called as part of mock creation, because you're at least referring to the actual class and its static fields and static {} blocks are being loaded as usual.

Look to line 41 of LoggingService.java, and if the problem isn't obvious there, edit your answer so we can see it and diagnose further.

Jeff Bowman
  • 90,959
  • 16
  • 217
  • 251