Commit 4eda29a4 authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '1.5.x'

parents 30e6b1d1 788fd777
......@@ -85,10 +85,9 @@ public class AuditEvent implements Serializable {
public AuditEvent(Date timestamp, String principal, String type,
Map<String, Object> data) {
Assert.notNull(timestamp, "Timestamp must not be null");
Assert.notNull(principal, "Principal must not be null");
Assert.notNull(type, "Type must not be null");
this.timestamp = timestamp;
this.principal = principal;
this.principal = principal != null ? principal : "";
this.type = type;
this.data = Collections.unmodifiableMap(data);
}
......@@ -117,7 +116,8 @@ public class AuditEvent implements Serializable {
}
/**
* Returns the user principal responsible for the event.
* Returns the user principal responsible for the event or an empty String if the
* principal is not available.
* @return the principal
*/
public String getPrincipal() {
......
......@@ -56,18 +56,18 @@ public class AuditEventTests {
}
@Test
public void nullTimestamp() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Timestamp must not be null");
new AuditEvent(null, "phil", "UNKNOWN",
public void nullPrincipalIsMappedToEmptyString() {
AuditEvent auditEvent = new AuditEvent(null, "UNKNOWN",
Collections.singletonMap("a", (Object) "b"));
assertThat(auditEvent.getPrincipal()).isEmpty();
}
@Test
public void nullPrincipal() throws Exception {
public void nullTimestamp() throws Exception {
this.thrown.expect(IllegalArgumentException.class);
this.thrown.expectMessage("Principal must not be null");
new AuditEvent(null, "UNKNOWN", Collections.singletonMap("a", (Object) "b"));
this.thrown.expectMessage("Timestamp must not be null");
new AuditEvent(null, "phil", "UNKNOWN",
Collections.singletonMap("a", (Object) "b"));
}
@Test
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment