Class SourceFile

java.lang.Object
org.springframework.core.test.tools.DynamicFile
org.springframework.core.test.tools.SourceFile
All Implemented Interfaces:
org.assertj.core.api.AssertProvider<SourceFileAssert>

public final class SourceFile extends DynamicFile implements org.assertj.core.api.AssertProvider<SourceFileAssert>
DynamicFile that holds Java source code and provides SourceFileAssert support. Usually created from an AOT generated type, for example:
SourceFile.of(generatedFile::writeTo)
Since:
6.0
Author:
Phillip Webb, Scott Frederick
  • Method Details

    • forTestClass

      public static SourceFile forTestClass(Class<?> type)
      Factory method to create a new SourceFile by looking up source for the given test Class.
      Parameters:
      type - the class file to get the source from
      Returns:
      a SourceFile instance
    • forClass

      public static SourceFile forClass(File sourceDirectory, Class<?> type)
      Factory method to create a new SourceFile by looking up source for the given Class.
      Parameters:
      sourceDirectory - the source directory
      type - the class file to get the source from
      Returns:
      a SourceFile instance
    • of

      public static SourceFile of(CharSequence charSequence)
      Factory method to create a new SourceFile from the given CharSequence.
      Parameters:
      charSequence - a file containing the source contents
      Returns:
      a SourceFile instance
    • of

      public static SourceFile of(@Nullable String path, CharSequence charSequence)
      Factory method to create a new SourceFile from the given CharSequence.
      Parameters:
      path - the relative path of the file or null to have the path deduced
      charSequence - a file containing the source contents
      Returns:
      a SourceFile instance
    • of

      public static SourceFile of(org.springframework.core.io.InputStreamSource inputStreamSource)
      Factory method to create a new SourceFile from the given InputStreamSource.
      Parameters:
      inputStreamSource - the source for the file
      Returns:
      a SourceFile instance
    • of

      public static SourceFile of(@Nullable String path, org.springframework.core.io.InputStreamSource inputStreamSource)
      Factory method to create a new SourceFile from the given InputStreamSource.
      Parameters:
      path - the relative path of the file or null to have the path deduced
      inputStreamSource - the source for the file
      Returns:
      a SourceFile instance
    • of

      public static SourceFile of(WritableContent writableContent)
      Factory method to create a new SourceFile from the given WritableContent.
      Parameters:
      writableContent - the content to write to the file
      Returns:
      a SourceFile instance
    • of

      public static SourceFile of(@Nullable String path, WritableContent writableContent)
      Factory method to create a new SourceFile from the given WritableContent.
      Parameters:
      path - the relative path of the file or null to have the path deduced
      writableContent - the content to write to the file
      Returns:
      a SourceFile instance
    • getClassName

      public String getClassName()
      Return the fully-qualified class name.
      Returns:
      the fully qualified class name
    • assertThat

      public SourceFileAssert assertThat()
      Use assertThat(sourceFile) rather than calling this method directly.
      Specified by:
      assertThat in interface org.assertj.core.api.AssertProvider<SourceFileAssert>