str.copy(); fail("expected exception"); } catch (IllegalStateException e) {
@Test public void testReadOnly() { GuardedString str = new GuardedString("foo".toCharArray()); assertFalse(str.isReadOnly()); str.makeReadOnly(); assertTrue(str.isReadOnly()); assertEquals(decryptToString(str), "foo"); try { str.appendChar('2'); fail("expected exception"); } catch (IllegalStateException e) { /* ignore */ } str = str.copy(); assertEquals(decryptToString(str), "foo"); str.appendChar('2'); assertEquals(decryptToString(str), "foo2"); }