Skip to content

Commit

Permalink
Added times to entry
Browse files Browse the repository at this point in the history
  • Loading branch information
cternes committed May 1, 2016
1 parent 5333b8f commit f4db2b9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/main/java/de/slackspace/openkeepass/domain/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ public class Entry implements KeePassFileElement {
@XmlElement(name = "History")
private History history;

@XmlElement(name = "Times")
private Times times;

Entry() {
this.uuid = UUID.randomUUID();
}
Expand All @@ -65,6 +68,7 @@ public Entry(EntryContract entryContract) {
this.iconData = entryContract.getIconData();
this.iconId = entryContract.getIconId();
this.customIconUUID = entryContract.getCustomIconUUID();
this.times = entryContract.getTimes();

setValue(false, NOTES, entryContract.getNotes());
setValue(true, PASSWORD, entryContract.getPassword());
Expand Down Expand Up @@ -151,6 +155,10 @@ public boolean isPasswordProtected() {
return getPropertyByName(PASSWORD).isProtected();
}

public Times getTimes() {
return times;
}

private void setValue(boolean isProtected, String propertyName, String propertyValue) {
Property property = getPropertyByName(propertyName);
if (property == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.slackspace.openkeepass.domain.builder;

import java.util.Calendar;
import java.util.UUID;

import org.junit.Assert;
Expand All @@ -8,6 +9,9 @@
import de.slackspace.openkeepass.domain.Entry;
import de.slackspace.openkeepass.domain.EntryBuilder;
import de.slackspace.openkeepass.domain.History;
import de.slackspace.openkeepass.domain.Times;
import de.slackspace.openkeepass.domain.TimesBuilder;
import de.slackspace.openkeepass.util.CalendarHandler;

public class EntryBuilderTest {

Expand Down Expand Up @@ -56,6 +60,18 @@ public void shouldBuildEntryFromEntryWithHistory() {
Assert.assertNull("username of the history should be null", historicEntry.getUsername());
}

@Test
public void shouldBuildEntryWithTimes() {
Calendar creationDate = CalendarHandler.createCalendar(2016, 2, 5);

Times times = new TimesBuilder().expires(true).usageCount(3).creationTime(creationDate).build();
Entry entry = new EntryBuilder("timesTest").times(times).build();

Assert.assertTrue(entry.getTimes().expires());
Assert.assertEquals(3, entry.getTimes().getUsageCount());
Assert.assertEquals(creationDate, entry.getTimes().getCreationTime());
}

@Test(expected = IllegalArgumentException.class)
public void shouldThrowIllegalArgumentExceptionWithNoEntrySet() {
new EntryBuilder("test").buildWithHistory();
Expand Down

0 comments on commit f4db2b9

Please sign in to comment.