Ejemplo n.º 1
0
 static {
   fraw.setLineSeparator("\n");
   fcompact.setLineSeparator("\n");
   fpretty.setLineSeparator("\n");
   ftso.setLineSeparator("\n");
   ftso.setSpecifiedAttributesOnly(true);
   ftfw.setLineSeparator("\n");
   ftfw.setTextMode(TextMode.TRIM_FULL_WHITE);
 }
Ejemplo n.º 2
0
  /**
   * The following method will run the output data through each of the three base formatters, raw,
   * compact, and pretty. It will also run each of those formatters as the outputString(content),
   * output(content, OutputStream) and output(content, Writer).
   *
   * <p>The expectation is that the results of the three output forms (String, OutputStream, and
   * Writer) will be identical, and that it will match the expected value for the appropriate
   * formatter.
   *
   * @param content The content to output
   * @param methodprefix What the methods are called
   * @param clazz The class used as the parameter for the methods.
   * @param setup A callback mechanism to modify the formatters
   * @param raw What we expect the content to look like with the RAW format
   * @param compact What we expect the content to look like with the COMPACT format
   * @param pretty What we expect the content to look like with the PRETTY format
   * @param trimfw What we expect the content to look like with the TRIM_FULL_WHITE format
   */
  protected void checkOutput(
      Object content,
      String methodprefix,
      Class<?> clazz,
      FormatSetup setup,
      String raw,
      String compact,
      String pretty,
      String tso,
      String trimfw) {
    Method meth = getMyMethod(methodprefix + "String", Format.class, clazz);

    if (meth == null) {
      return;
    }

    String[] descn =
        new String[] {"Raw", "Compact", "Pretty", "PrettySpecifiedOnly", "TrimFullWhite"};
    Format ftrimfw = Format.getPrettyFormat();
    ftrimfw.setTextMode(TextMode.TRIM_FULL_WHITE);
    Format fattspec = Format.getPrettyFormat();
    fattspec.setSpecifiedAttributesOnly(true);
    Format[] formats =
        new Format[] {
          getFormat(setup, Format.getRawFormat()),
          getFormat(setup, Format.getCompactFormat()),
          getFormat(setup, Format.getPrettyFormat()),
          getFormat(setup, fattspec),
          getFormat(setup, ftrimfw)
        };
    String[] result = new String[] {raw, compact, pretty, tso, trimfw};

    for (int i = 0; i < 5; i++) {

      String mstring;
      try {
        mstring = (String) meth.invoke(this, formats[i], content);
      } catch (Exception e) {
        e.printStackTrace();
        throw new IllegalStateException(e);
      }
      String msg = "outputString Format " + descn[i];
      assertEquals(msg, expect(result[i]), mstring);
    }
  }