All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jio.test.pbt.ExceptionContext Maven / Gradle / Ivy

Go to download

JIO test library based on Property Based Testing and Java Flight Recording Debuggers

There is a newer version: 3.0.0-RC2
Show newest version
package jio.test.pbt;


import jsonvalues.JsArray;
import jsonvalues.JsObj;
import jsonvalues.JsStr;

import java.util.Arrays;
import java.util.List;

/**
 * Represents information related to an exception that occurred during the execution of a specific test.
 *
 * @param context   The context of the exception.
 * @param exception The exception.
 */
public record ExceptionContext(Context context,
                               Throwable exception) {

  /**
   * Serializes this record into a JSON object, converting the exception into a JSON object with its message, class
   * name, and stacktrace. The JSON schema is as follows:
   *
   * 
   *     {@code
   *     {
   *         "context": JsObj (see Context#toJson()),
   *         "message": String (or empty string if null),
   *         "type": String (class name of the exception),
   *         "stacktrace": JsArray[String]
   *     }
   *     }
   * 
* * @return A JSON representation of the exception context. * @see Context#toJson() */ public JsObj toJson() { List stacktrace = Arrays.stream(exception.getStackTrace()) .map(it -> JsStr.of(it.toString())) .toList(); return JsObj.of("context", context.toJson(), "message", exception.getMessage() != null ? JsStr.of(exception.getMessage()) : JsStr.of(""), "type", JsStr.of(exception.getClass() .getName()), "stacktrace", JsArray.ofIterable(stacktrace) ); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy