Class PrintUtils

java.lang.Object
ru.vyarus.dropwizard.guice.test.util.PrintUtils

public final class PrintUtils extends Object
Utilities for test console reports formatting.
Since:
12.02.2025
  • Method Details

    • identity

      public static String identity(Object object)
      This is the same string as shown in the default Object.toString (@hash part).
      Parameters:
      object - object to get identity for
      Returns:
      object identity string
    • toStringArguments

      public static String[] toStringArguments(Object[] args, int maxLength)
      Converts arguments to string.
      Parameters:
      args - arguments
      maxLength - maximum string length to keep (longer strings get truncated)
      Returns:
      string representation of incoming arguments
    • toStringValue

      public static String toStringValue(Object value, int maxLength)
      Converts any value (object) to string. Rules: - Primitive values, number and booleans stored as is - String values could be truncated - Objects represented as ObjectType@instanceHash - null is "null"
      Parameters:
      value - value to convert to string
      maxLength - maximum string length to keep
      Returns:
      string representation for the object
    • renderTime

      public static String renderTime(Duration overall, Duration increase)
      Render duration together with increase indication: overall time (increase since last report).
      Parameters:
      overall - overall duration (including increase) (could be null)
      increase - increase since last report (could be null)
      Returns:
      string representation for suration
    • ms

      public static String ms(Duration duration)
      Render duration in milliseconds (2 decimal signs precision).
      Parameters:
      duration - duration
      Returns:
      string representation
    • ms

      public static String ms(long nanos)
      Parameters:
      nanos - time in nanoseconds
      Returns:
      string representation
    • formatMs

      public static String formatMs(long nanos, int precision)
      Format nano value in milliseconds with required precision (decimal numbers).
      Parameters:
      nanos - value in nanoseconds
      precision - required precision (decimal numbers)
      Returns:
      formatted value
    • formatMetric

      public static String formatMetric(double time)
      Time assumed to come from metrics snapshot.
      Parameters:
      time - time to format
      Returns:
      string representation (in ms)
    • formatMetric

      public static String formatMetric(double time, TimeUnit unit)
      Formats time, obtained from metrics snapshot to target unit.
      Parameters:
      time - time to format
      unit - target unit
      Returns:
      string representation (in selected unit)
    • getPerformanceReportSeparator

      public static String getPerformanceReportSeparator(org.junit.jupiter.api.extension.ExtensionContext context)
      Universal header string for performance reports in test to clearly identify current context.
      Parameters:
      context - junit context
      Returns:
      performance report header