Skip to content

Commit 78355bb

Browse files
Fix #326 (#376)
Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
1 parent 2730ae4 commit 78355bb

File tree

3 files changed

+35
-11
lines changed

3 files changed

+35
-11
lines changed

core/src/main/java/io/cloudevents/core/v03/CloudEventV03.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,12 @@ public String toString() {
236236
"id='" + id + '\'' +
237237
", source=" + source +
238238
", type='" + type + '\'' +
239-
", datacontenttype='" + datacontenttype + '\'' +
240-
", schemaurl=" + schemaurl +
241-
", subject='" + subject + '\'' +
242-
", time=" + time +
243-
", data=" + getData() +
244-
", extensions" + this.extensions +
239+
((datacontenttype != null) ? ", datacontenttype='" + datacontenttype + '\'' : "") +
240+
((schemaurl != null) ? ", schemaurl=" + schemaurl : "") +
241+
((subject != null) ? ", subject='" + subject + '\'' : "") +
242+
((time != null) ? ", time=" + time : "") +
243+
((getData() != null) ? ", data=" + getData() : "") +
244+
", extensions=" + this.extensions +
245245
'}';
246246
}
247247
}

core/src/main/java/io/cloudevents/core/v1/CloudEventV1.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,11 @@ public String toString() {
223223
"id='" + id + '\'' +
224224
", source=" + source +
225225
", type='" + type + '\'' +
226-
", datacontenttype='" + datacontenttype + '\'' +
227-
", dataschema=" + dataschema +
228-
", subject='" + subject + '\'' +
229-
", time=" + time +
230-
", data=" + getData() +
226+
((datacontenttype != null) ? ", datacontenttype='" + datacontenttype + '\'' : "") +
227+
((dataschema != null) ? ", dataschema=" + dataschema : "") +
228+
((subject != null) ? ", subject='" + subject + '\'' : "") +
229+
((time != null) ? ", time=" + time : "") +
230+
((getData() != null) ? ", data=" + getData() : "") +
231231
", extensions=" + this.extensions +
232232
'}';
233233
}

core/src/test/java/io/cloudevents/core/impl/CloudEventImplTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,4 +91,28 @@ public void testGetAttributeNames() {
9191
);
9292
}
9393

94+
@Test
95+
public void testToStringV1() {
96+
CloudEvent event = CloudEventBuilder.v1()
97+
.withId(ID)
98+
.withType(TYPE)
99+
.withSource(SOURCE)
100+
.build();
101+
102+
assertThat(event.toString())
103+
.doesNotContain("time");
104+
}
105+
106+
@Test
107+
public void testToStringV03() {
108+
CloudEvent event = CloudEventBuilder.v03()
109+
.withId(ID)
110+
.withType(TYPE)
111+
.withSource(SOURCE)
112+
.build();
113+
114+
assertThat(event.toString())
115+
.doesNotContain("time");
116+
}
117+
94118
}

0 commit comments

Comments
 (0)