It is probably. But that is the wrong idea here!
You want to test a sort method. If you think you need mocking for that you are doing something seriously wrong!
That method takes an array and should return the same array - just sorted.
Thus your tests should only use that : pass in an array - and check if the output is as expected! You absolutely do not care what happens inside. You focus on testing the what -not how that is done.
So your tests look somehow like:
@Test
public void testReverseArray() {
assertThat(Whatever.mergeSort(new int[] { 3, 2, 1 }), is(new int[] { 1, 2, 3 });
}
for example (where is is a hamcrest matcher).
In other words: if you think you have to "factor out" that call to a static method - then you are probably doing that because calling the real method gives you all kinds of trouble.
So you have to "mock" it when testing this method. But surprise, you will also have to get rid of it when you test methods that call the outer mergeSort()
method.
Therefore:
- be really careful about using the static keyword
- as soon as you find that calling a static method turns into a problem in unit test: take that as clear evidence that you have to rework that method
Meaning: either the static call should be reworked to allow calling it within unit tests - or you get rid of the static modifier.