/**
   * @param entity user reference.
   * @return a pretty name for the user based on entities "alt" attributes or their names.
   */
  protected String getEntityReadableName(EntityReference entity) {
    if (entity == null) {
      return "Main Wiki";
    }

    StringBuilder result = null;

    if (entity.getType() == EntityType.DOCUMENT) {
      TestEntity docEntity = testDefinition.searchEntity(entity);
      String name =
          (docEntity != null && docEntity instanceof TestDocument)
              ? ((TestDocument) docEntity).getDescription()
              : null;
      name = (name != null) ? name : entity.getName();
      result = new StringBuilder(name);
      entity = entity.getParent();
    }

    if (entity.getType() == EntityType.SPACE) {
      TestEntity spaceEntity = testDefinition.searchEntity(entity);
      String name =
          (spaceEntity != null && spaceEntity instanceof TestSpace)
              ? ((TestSpace) spaceEntity).getDescription()
              : null;
      name = (name != null) ? name : entity.getName();
      if (result == null || !name.startsWith("any")) {
        if (result != null) {
          result.append(" in ");
          result.append(name);
        } else {
          result = new StringBuilder(name);
        }
      }
      entity = entity.getParent();
    }

    if (entity.getType() == EntityType.WIKI) {
      TestEntity wikiEntity = testDefinition.getWiki(new WikiReference(entity));
      String name = (wikiEntity != null) ? ((TestWiki) wikiEntity).getDescription() : null;
      name = (name != null) ? name : entity.getName();
      if (result == null || !name.startsWith("any")) {
        if (result != null) {
          result.append(" from ");
          result.append(name);
        } else {
          result = new StringBuilder(name);
        }
      }
    }

    return result.toString();
  }
  /**
   * @param user user reference.
   * @return a pretty name for the user based on entities "alt" attributes or their names.
   */
  protected String getUserReadableName(DocumentReference user) {
    if (user == null) {
      return "Public";
    }

    TestEntity userEntity = testDefinition.searchEntity(user);
    String result =
        (userEntity != null && userEntity instanceof TestDocument)
            ? ((TestDocument) userEntity).getDescription()
            : null;
    result = (result != null) ? result : user.getName();

    TestWiki wiki = testDefinition.getWiki(user.getWikiReference());
    String name = (wiki != null) ? wiki.getDescription() : null;
    name = (name != null) ? name : user.getWikiReference().getName();
    if (!name.startsWith("any")) {
      result += " from " + name;
    }

    return result;
  }
 /**
  * @param name document name.
  * @param space space name.
  * @return a reference to a document in a space of the main wiki.
  */
 protected DocumentReference getXDoc(String name, String space) {
   return new DocumentReference(
       name, new SpaceReference(space, testDefinition.getMainWiki().getWikiReference()));
 }
 /**
  * @param space space name.
  * @return a reference to a space in the main wiki.
  */
 protected SpaceReference getXSpace(String space) {
   return new SpaceReference(space, testDefinition.getMainWiki().getWikiReference());
 }
 /** @return a reference to the main wiki. */
 protected WikiReference getXWiki() {
   return testDefinition.getMainWiki().getWikiReference();
 }
 /**
  * @param name user name.
  * @param wiki subwiki name.
  * @return a reference to a user in a sub wiki.
  */
 protected DocumentReference getUser(String name, String wiki) {
   return new DocumentReference(
       name,
       new SpaceReference(
           XWikiConstants.XWIKI_SPACE, testDefinition.getWiki(wiki).getWikiReference()));
 }