This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generate IllegalAccessException

 
Nirav Nagda
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
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();
}
}

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.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please BeForthrightWhenCrossPostingToOtherSites (link).

Welcome to the Ranch!
 
Nirav Nagda
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know but I did not get reply there and I am stuck up...

its like the solution there does work but the situation I am in the steps given there just fail


Can anyone here help
 
Nirav Nagda
Greenhorn
Posts: 5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying MockIto also and when I try to mock Field class

Field mockIT = Mockito.mock(Field.class);
Mockito.doCallRealMethod().when(mockIT).getInt(String.class);
mockIT.getInt(str);

output:

Exception in thread "main" org.mockito.exceptions.base.MockitoException:
Cannot mock/spy class java.lang.reflect.Field
Mockito cannot mock/spy following:
- final classes
- anonymous classes
- primitive types


does any one know how can I go forward with this
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic