I have a static wrapper class for the android Log
.
It looks like this (simplified):
// Source: https://github.com/ccrama/Slide/blob/master/app/src/main/java/me/ccrama/redditslide/util/LogUtil.java
public class LogUtil {
private static final int CALLING_METHOD_INDEX;
static {
int i = 1;
for (StackTraceElement ste : Thread.currentThread().getStackTrace()) {
i++;
if (ste.getClassName().equals(LogUtil.class.getName())) {
break;
}
}
CALLING_METHOD_INDEX = i;
}
public static String getTag() {
final StackTraceElement ste = Thread.currentThread().getStackTrace()[CALLING_METHOD_INDEX];
return "(" + ste.getFileName() + ":" + ste.getLineNumber() + ")";
}
public static void v(String message) {
Log.v(getTag(), message);
}
}
My problem: I'm testing another method that calls this LogUtil.v()
's method.
Is there a way to test the other method with Mockito and not Powermock(ito) if possible?
Currently it throws a LogUtil.v not mocked
Exception.
I read that if I have to use PowerMockito, I'm doing something wrong (=> not following TDD).