@Test public void checkAddChangeRemoveProperty() { // only applies to databases that support arbitrary properties E entry = database.newEntry(); assertEquals(Entry.STANDARD_PROPERTY_NAMES.size(), entry.getPropertyNames().size()); try { entry.setProperty("test", "test1"); } catch (UnsupportedOperationException e) { if (!database.supportsNonStandardPropertyNames()) { return; } fail("Database must report that it doesn't support non standrad properties"); } assertEquals("test1", entry.getProperty("test")); entry.setProperty("test", "test2"); assertEquals("test2", entry.getProperty("test")); assertTrue(entry.removeProperty("test")); assertFalse(entry.removeProperty("test")); assertFalse(entry.removeProperty("test-test")); assertEquals(Entry.STANDARD_PROPERTY_NAMES.size(), entry.getPropertyNames().size()); try { entry.removeProperty(Entry.STANDARD_PROPERTY_NAME_USER_NAME); fail("Should not be able to remove standard property"); } catch (IllegalArgumentException ignore) { // ignore as expected } }
@Test public void testNewEntry() { E e2 = database.newEntry(); Assert.assertNull(e2.getParent()); assertEquals("", e2.getPassword()); Assert.assertNotNull(e2.getUuid()); assertEquals("", e2.getUrl()); assertEquals("", e2.getNotes()); assertEquals("", e2.getUsername()); assertEquals("", e2.getTitle()); Assert.assertNull(e2.getProperty("silly")); List<String> l = e2.getPropertyNames(); l.removeAll(Entry.STANDARD_PROPERTY_NAMES); Assert.assertEquals(0, l.size()); }
properties.add("silly"); properties.removeAll(e1.getPropertyNames()); Assert.assertEquals(0, properties.size()); } catch (UnsupportedOperationException e) { assertArrayEquals(e1.getPropertyNames().toArray(), Entry.STANDARD_PROPERTY_NAMES.toArray());
@Override public E newEntry(Entry<?,?,?,?> entry) { E result = newEntry(); for (String propertyName: entry.getPropertyNames()) { try { // all implementations must support setting of STANDARD_PROPERTY_NAMES result.setProperty(propertyName, entry.getProperty(propertyName)); } catch (UnsupportedOperationException e) { // oh well, we tried } } try { for (String propertyName: (entry.getBinaryPropertyNames())) { try { // all implementations must support setting of STANDARD_PROPERTY_NAMES result.setBinaryProperty(propertyName, entry.getBinaryProperty(propertyName)); } catch (UnsupportedOperationException e) { // oh well, we tried } } } catch (UnsupportedOperationException e) { // never mind } result.setIcon(this.newIcon(entry.getIcon().getIndex())); // everything else should have been copied via properties return result; }