7

I'm trying to unit test one of my methods. Inside this method it has a line:

val dynamicFrame = DynamicFrame(dataFrame, glueContext)

The issue is that DynamicFrame is an object:

object DynamicFrame {
   ... methods()
}

and I'm trying to use PowerMock to mock the call to DynamicFrame(dataFrame, glueContext). I know that PowerMock can mock classes, but how can I mock an object? I've seen similar questions here and here but it doesn't seem straightforward.

In my test code I've tried

PowerMockito.whenNew(classOf[DynamicFrame])
  .withAnyArguments().thenReturn(mockDynamicFrame)

but I get a NullPointerException on the line where DynamicFrame is created. My guess is that it's because I used syntax for mocking classes but DynamicFrame is an object.

Does PowerMock (from Mockito) support this functionality out of the gate? If not how would I go about making my test succeed?

Victor Cui
  • 1,393
  • 2
  • 15
  • 35

0 Answers0