0

I have a JUnit test written for a function that creates an s3 client, fetches data to parse it. So, I have a class called M, P and M's test class MTest. MTest has annotation

@RunWith(MockitoJUnitRunner.class)

on top. P's object is a member variable in M. I have defined the variables in my test class as follows

@InjectMocks
private M MObj;

@Mock
private P PObj;

In my setup (@Before) function, I have

when(PObj.processInputFile(any(), anyInt())).thenReturn(**something**);

The first input to processInputFile in the actual implementation is an input stream from S3, which involves creating s3 client and making network call, which is why I used the when.thenReturn function to mock the functionality for unit tests.

Pobject.processInputFile(**expressions evals new input stream from s3**, <some integer>)

When I run tests with above configuration, I get an error in the actual processInputFile function, as it tries to make the network call from a server that doesn't have such access.

My Question is - if I have any() in my unit test, does the unit test try to evaluate the expression in the actual code so as to compare it with the any() object.

If not, what could be the reason for the unit tests trying to evaluate the expression when I have explicity mocked the function.

If yes, is there a way to work around that and have the unit tests not evaluate the expression in the actual code.

Him
  • 318
  • 3
  • 11

1 Answers1

0

The method is executed if it is final because Mockito by default cannot mock final methods.

Stefan Birkner
  • 24,059
  • 12
  • 57
  • 72