@Test public void testEquals() { GuardedString str1 = new GuardedString(); GuardedString str2 = new GuardedString(); assertEquals(str1, str2); str2.appendChar('2'); assertFalse(str1.equals(str2)); str1.appendChar('2'); assertEquals(str1, str2); }
@Test public void testBasics() { GuardedString str = new GuardedString("foo".toCharArray()); assertEquals(decryptToString(str), "foo"); str.appendChar('2'); assertEquals(decryptToString(str), "foo2"); assertFalse(str.verifyBase64SHA1Hash(SecurityUtil .computeBase64SHA1Hash("foo".toCharArray()))); assertTrue(str.verifyBase64SHA1Hash(SecurityUtil .computeBase64SHA1Hash("foo2".toCharArray()))); }
@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"); }
str.appendChar('c'); fail("expected exception"); } catch (IllegalStateException e) {