Browse Source

Merge branch '1.5.x'

pull/10978/merge
Stephane Nicoll 8 years ago
parent
commit
4eda29a42e
  1. 6
      spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java
  2. 14
      spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java

6
spring-boot-project/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/audit/AuditEvent.java

@ -85,10 +85,9 @@ public class AuditEvent implements Serializable { @@ -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 { @@ -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() {

14
spring-boot-project/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/audit/AuditEventTests.java

@ -56,18 +56,18 @@ public class AuditEventTests { @@ -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

Loading…
Cancel
Save