code: @SuppressWarnings({"PMD.NullAssignment", "PMD.UseObjectForClearerAPI"})
      public String prepareAttachment(final String name, final String type, final String fileExtension) {
          final String extension = Optional.ofNullable(fileExtension)
                  .filter(ext -> !ext.isEmpty())
                  .map(ext -> ext.charAt(0) == '.' ? ext : "." + ext)
                  .orElse("");
          final String source = UUID.randomUUID().toString() + ATTACHMENT_FILE_SUFFIX + extension;
  
          final Optional<String> current = threadContext.getCurrent();
          if (!current.isPresent()) {
              LOGGER.error("Could not add attachment: no test is running");
              //backward compatibility: return source even if no attachment is going to be written.
              return source;
          }
          final Attachment attachment = new Attachment()
                  .setName(isEmpty(name) ? null : name)
                  .setType(isEmpty(type) ? null : type)
                  .setSource(source);
  
          final String uuid = current.get();
          storage.get(uuid, WithAttachments.class).ifPresent(withAttachments -> {
              synchronized (storage) {
                  withAttachments.getAttachments().add(attachment);
              }
          });
          return attachment.getSource();
      }
docs: Adds attachment to current running test or step, and returns source. In order
  to store attachment content use {@link #writeAttachment(String, InputStream)} method.
  
  @param name          the name of attachment
  @param type          the content type of attachment
  @param fileExtension the attachment file extension
  @return the source of added attachment