Record Class SpringTestContextsPrintFormat

java.lang.Object
java.lang.Record
org.approvej.spring.SpringTestContextsPrintFormat
Record Components:
includeTestClasses - whether to list the test classes using each context
All Implemented Interfaces:
org.approvej.print.PrintFormat<SpringTestContexts>

@NullMarked public record SpringTestContextsPrintFormat(boolean includeTestClasses) extends Record implements org.approvej.print.PrintFormat<SpringTestContexts>
PrintFormat for SpringTestContexts that prints each distinct context with all details relevant to Spring's context caching.

The contexts are sorted by their printed form, so adding or removing test classes does not reorder the output. The parent contexts of context hierarchies are printed as contexts of their own, as Spring caches them as well. For example:

 - loader: SpringBootContextLoader
   classes:
     - com.example.Application
   profiles:
     - test
   customizers:
     - @MockitoBean com.example.PaymentClient field=paymentClient
     - @SpringBootTest(webEnvironment=MOCK)
 

Usages of @DirtiesContext are listed with each context they cause to be started again, as they slow down the test suite just like additional contexts.

Some details of unknown context customizers cannot be printed. If two distinct contexts are printed identically, both are marked with a note.

  • Constructor Details

    • SpringTestContextsPrintFormat

      public SpringTestContextsPrintFormat(boolean includeTestClasses)
      Creates an instance of a SpringTestContextsPrintFormat record class.
      Parameters:
      includeTestClasses - the value for the includeTestClasses record component
  • Method Details

    • contextConfigurations

      public static SpringTestContextsPrintFormat contextConfigurations()
      Creates a new SpringTestContextsPrintFormat that does not list the test classes, so adding a test class that uses an existing context does not change the output.
      Returns:
      a new SpringTestContextsPrintFormat
    • withTestClasses

      public SpringTestContextsPrintFormat withTestClasses()
      Returns a copy of this that also lists the test classes using each context.

      Note that this changes the output whenever a test class is added, removed, or renamed.

      Returns:
      a copy of this including the test classes
    • printer

      public org.approvej.print.Printer<SpringTestContexts> printer()
      Specified by:
      printer in interface org.approvej.print.PrintFormat<SpringTestContexts>
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • includeTestClasses

      public boolean includeTestClasses()
      Returns the value of the includeTestClasses record component.
      Returns:
      the value of the includeTestClasses record component