I am testing an algorithm for StringSearch and the algorithm has many IllegalAccessExceptions in it.
I wanted to test that the code is working fine with the exceptions...and it is important also to test them as they call some functions when the exception occurs.
I just wanted to know how can i implicitly generate the exception.
I am trying to use the Java Security Manager but don't know how to use it to revoke the program's access to String class.
below is the code that I am testing:
#[code = java]
try {
int o = offset.getInt(text);
char[] t = (char[]) value.get(text);
return instance.searchChars(t, textStart + o, textEnd + o, getChars(pattern), processed) - o;
} catch (IllegalAccessException ex) {
synchronized (activeStringAccess) {
activeStringAccess = new StringAccess();
}
}
[/code]
in above code "offset.getInt(text)" generates the IllegalAccessException
I have tried to use MockIt but MockIt cannot mock the class for getInt i.e. Field.