@Override public Attachment visitAttachmentFile(final Path attachmentFile) { final RandomUidContext context = configuration.requireContext(RandomUidContext.class); return attachments.computeIfAbsent(attachmentFile, file -> { final String uid = context.getValue().get(); final String realType = probeContentType(file); final String extension = Optional.of(getExtension(file.toString())) .filter(s -> !s.isEmpty()) .map(s -> "." + s) .orElseGet(() -> getExtensionByMimeType(realType)); final String source = uid + (extension.isEmpty() ? "" : extension); final Long size = getFileSizeSafe(file); return new Attachment() .setUid(uid) .setName(file.getFileName().toString()) .setSource(source) .setType(realType) .setSize(size); }); }
@Test public void shouldAddLogAsAttachment() throws Exception { final Attachment hey = new Attachment().setUid("some-uid"); when(visitor.visitAttachmentFile(any())).thenReturn(hey); process( "junitdata/TEST-test.SampleTest.xml", "TEST-test.SampleTest.xml", "junitdata/test.SampleTest.txt", "test.SampleTest.txt" ); final ArgumentCaptor<Path> attachmentCaptor = ArgumentCaptor.forClass(Path.class); verify(visitor, times(1)).visitAttachmentFile(attachmentCaptor.capture()); assertThat(attachmentCaptor.getValue()) .isRegularFile() .hasContent("some-test-log"); final ArgumentCaptor<TestResult> captor = ArgumentCaptor.forClass(TestResult.class); verify(visitor, times(1)).visitTestResult(captor.capture()); final StageResult testStage = captor.getValue().getTestStage(); assertThat(testStage) .describedAs("Should create a test stage") .isNotNull(); assertThat(testStage.getAttachments()) .describedAs("Should add an attachment") .hasSize(1) .describedAs("Attachment should has right uid and name") .extracting(Attachment::getName, Attachment::getUid) .containsExactly(Tuple.tuple("System out", "some-uid")); }
@Override public Attachment visitAttachmentFile(final Path attachmentFile) { final RandomUidContext context = configuration.requireContext(RandomUidContext.class); return attachments.computeIfAbsent(attachmentFile, file -> { final String uid = context.getValue().get(); final String realType = probeContentType(file); final String extension = Optional.of(getExtension(file.toString())) .filter(s -> !s.isEmpty()) .map(s -> "." + s) .orElseGet(() -> getExtensionByMimeType(realType)); final String source = uid + (extension.isEmpty() ? "" : extension); final Long size = getFileSizeSafe(file); return new Attachment() .setUid(uid) .setName(file.getFileName().toString()) .setSource(source) .setType(realType) .setSize(size); }); }