Skip to content

Commit a58eed2

Browse files
baevArtem Eroshenko
authored andcommitted
fix npe for null attachment (fixes allure-framework#77, via allure-framework#78)
1 parent 866dc64 commit a58eed2

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

allure-java-migration/src/main/java/io/qameta/allure/aspects/Allure1AttachAspects.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public void attachment(final JoinPoint joinPoint, final Object result) {
5353
);
5454

5555
final byte[] bytes = (result instanceof byte[])
56-
? (byte[]) result : result.toString().getBytes(StandardCharsets.UTF_8);
56+
? (byte[]) result : Objects.toString(result).getBytes(StandardCharsets.UTF_8);
5757
getLifecycle().addAttachment(title, attachment.type(), "", bytes);
5858
}
5959

allure-java-migration/src/test/java/io/qameta/allure/aspects/Allure1AttachAspectsTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,30 @@ public void shouldSetupAttachmentTitleFromMethodSignature() {
7070

7171
}
7272

73+
@Test
74+
public void shouldProcessNullAttachment() throws Exception {
75+
final String uuid = UUID.randomUUID().toString();
76+
final TestResult result = new TestResult().withUuid(uuid);
77+
78+
lifecycle.scheduleTestCase(result);
79+
lifecycle.startTestCase(uuid);
80+
81+
attachmentWithNullValue();
82+
83+
lifecycle.stopTestCase(uuid);
84+
lifecycle.writeTestCase(uuid);
85+
86+
assertThat(results.getTestResults())
87+
.flatExtracting(TestResult::getAttachments)
88+
.extracting("name", "type")
89+
.containsExactly(tuple("attachmentWithNullValue", null));
90+
}
91+
92+
@Attachment
93+
public byte[] attachmentWithNullValue() {
94+
return null;
95+
}
96+
7397
@Attachment
7498
public byte[] attachmentWithoutTitle() {
7599
return new byte[]{};

0 commit comments

Comments
 (0)