@Test public void testGetItem2() throws Exception { String link = "link"; final Item item = new Item(link, "login", "pass"); // Compare items without password databaseControl.addItem(item, password); assertEquals(databaseControl.getItem(link, password), item); try { databaseControl.getItem("wronglink", password); fail("Didn't trigger NoSuchItemException."); } catch (NoSuchItemException nsie) { } // Crypted tests Password newPassword = new Password("NewPassword".getBytes()); databaseControl.addItem(item, password); databaseControl.setPassword(password, newPassword); try { databaseControl.getItem(link, password); fail("Didn't trigger InvalidPasswordException!"); } catch (InvalidPasswordException e) { } assertEquals(databaseControl.getItem(link, newPassword), item); }
@Test public void testDelItem() throws Exception { String link = "link"; Item item = new Item(link, "login", "pass"); databaseControl.addItem(item, password); databaseControl.delItem(link, password); try { databaseControl.delItem(link, password); fail("Didn't trigger NoSuchItemException."); } catch (NoSuchItemException nsie) { } Password newPassword = new Password("NewPassword".getBytes()); databaseControl.addItem(item, password); databaseControl.setPassword(password, newPassword); try { databaseControl.delItem(link, password); fail("Didn't trigger InvalidPasswordException!"); } catch (InvalidPasswordException e) { } }
@Test public void testIsEncrypted() throws Exception { assertEquals(databaseControl.isEncrypted(), false); Password newPassword = new Password("NewPassword".getBytes()); databaseControl.setPassword(password, newPassword); assertEquals(databaseControl.isEncrypted(), true); }
@Test public void testSetPassword() throws Exception { Password newPassword = new Password("NewPassword".getBytes()); assertEquals(databaseControl.isEncrypted(), false); databaseControl.setPassword(null, password); assertEquals(databaseControl.isEncrypted(), true); Item item = new Item("link", "user", "pass"); databaseControl.addItem(item, password); databaseControl.setPassword(password, newPassword); Item item1 = new Item("link1", "user1", "pass1"); databaseControl.addItem(item1, newPassword); try { Item item2 = new Item("link2", "user2", "pass2"); databaseControl.addItem(item2, password); fail("Didn't trigger InvalidPasswordException!"); } catch (InvalidPasswordException ipe) { } }