/*
* Test setEncoding() with insufficient privilege.
*/
public void testSetEncoding_InsufficientPrivilege() throws Exception {
StreamHandler h = new StreamHandler();
SecurityManager oldMan = System.getSecurityManager();
System.setSecurityManager(new MockSecurityManager());
// set a normal value
try {
h.setEncoding("iso-8859-1");
fail("Should throw SecurityException!");
} catch (SecurityException e) {
// expected
} finally {
System.setSecurityManager(oldMan);
}
assertNull(h.getEncoding());
System.setSecurityManager(new MockSecurityManager());
// set an invalid value
try {
h.setEncoding("impossible");
fail("Should throw SecurityException!");
} catch (SecurityException e) {
// expected
} finally {
System.setSecurityManager(oldMan);
}
assertNull(h.getEncoding());
}