Enum Class InternalUtils

java.lang.Object
java.lang.Enum<InternalUtils>
jp.co.moneyforward.autotest.framework.internal.InternalUtils
All Implemented Interfaces:
Serializable, Comparable<InternalUtils>, Constable

public enum InternalUtils extends Enum<InternalUtils>
An internal utility class of the insdog framework.
  • Field Details

    • LOGGER

      public static final org.slf4j.Logger LOGGER
  • Method Details

    • values

      public static InternalUtils[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static InternalUtils valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • currentBranchName

      public static Optional<String> currentBranchName()
      Returns an Optional of a String that contains a branch name. This method internally calls InternalUtils#currentBranchNameFor(new File(".")).
      Returns:
      An Optional of branch name String.
      See Also:
    • currentBranchNameFor

      public static Optional<String> currentBranchNameFor(File projectDir)

      Returns an Optional of a String that contains a branch name, if the given projectDir has .git directory and a current branch name of it can be retrieved. An exception will be thrown on a failure during this step.

      Otherwise, an empty Optional will be returned.

      Returns:
      An Optional of branch name String.
    • isPresumablyRunningFromIDE

      public static boolean isPresumablyRunningFromIDE()
    • isRunUnderSurefire

      public static boolean isRunUnderSurefire()
    • isRunUnderPitest

      public static boolean isRunUnderPitest()
    • composeResultMessageLine

      public static String composeResultMessageLine(Class<?> testClass, String stageName, String line)
    • projectDir

      public static File projectDir()
    • simpleClassNameOf

      public static String simpleClassNameOf(Class<?> clazz)
    • flattenIfSequential

      public static Stream<com.github.dakusui.actionunit.core.Action> flattenIfSequential(com.github.dakusui.actionunit.core.Action a)
    • shorten

      public static String shorten(String string)
      A shorthand method of shorten(string, 120).
      Parameters:
      string - A string to be shortened.
      Returns:
      A shortened string.
    • shorten

      public static String shorten(String string, int length)
      Shorten a string to the specified length. In case string contains a carriage return (\r), a substring from the beginning of the string to the position of the character will be returned.
      Parameters:
      string - A string to be shortened.
      length - A length to which string to be shortened.
      Returns:
      A shortened string.
    • mask

      public static String mask(Object o)
    • flattenSequentialAction

      public static Stream<com.github.dakusui.actionunit.core.Action> flattenSequentialAction(com.github.dakusui.actionunit.core.Action action)
    • nameOf

      public static String nameOf(Method m)

      Returns a "name" a given method. If the method has @Named annotation and its value is set, the value will be returned. If the value is equal to Named.DEFAULT_VALUE, the name of the method itself will be returned.

      This method should be called for a method with @Named annotation.

      Parameters:
      m - A method whose name should be returned.
      Returns:
      The name of the method the framework recognizes.
    • findMethodByName

      public static Optional<Method> findMethodByName(String methodName, Class<?> klass)
      Note that resolution is done based on the value of Named annotation first.
      Parameters:
      methodName - A name of a method to be found.
      klass - A class from which a method is searched.
      Returns:
      An optional containing a found method, otherwise, empty.
    • isDependencyAnnotationPresent

      public static boolean isDependencyAnnotationPresent(Method m)
    • getDependencyAnnotationValues

      public static String[] getDependencyAnnotationValues(Method m)
    • variableNameToString

      public static String variableNameToString(String variableName)
    • spaces

      public static String spaces(int i)
    • date

      public static Date date(String dateString)
      Creates a Date object from a string formatted with MMM/dd/yyyy. Locale.US is used to create a SimpleDateFormat object.
      Parameters:
      dateString - A string from which a Date object is created.
      Returns:
      A date object created from dateString.
    • now

      public static Date now()
      Returns a Date object from the current date.
      Returns:
      A date object created from the current date.
    • dateToSafeString

      public static String dateToSafeString(Date date)
    • concat

      @SafeVarargs public static <T> Stream<T> concat(Stream<T>... streams)
      Concatenates given streams.
      Type Parameters:
      T - The type of the values streamed by the given streams.
      Parameters:
      streams - Streams to be concatenated.
      Returns:
      Concatenated stream.
    • createContext

      public static com.github.dakusui.actionunit.core.Context createContext()
      Returns an action context for InsDog. The returned context is designed to print a proper message when each value in the action context is a variable store.
      Returns:
      A created context.
    • printableConsumer

      public static Consumer<com.github.dakusui.actionunit.core.Context> printableConsumer(String consumerName, Consumer<com.github.dakusui.actionunit.core.Context> consumer)
      Creates a consumer, which gives a consumerName, when toString method is called.
      Parameters:
      consumerName - A name of the created consumer. Returned from toString.
      consumer - A consumer from which the returned object is created.
      Returns:
      A consumer which executes the accept method of the consumer and returns consumerName for toString.
    • action

      public static com.github.dakusui.actionunit.core.Action action(String name, Consumer<com.github.dakusui.actionunit.core.Context> contextConsumer)
      Creates a leaf action, which executes the accept method of contextConsumer. Inside this method, the given contextConsumer method is made printable using the printableConsumer method. Then it will be passed to ActionSupport#leaf method to turn it into an action.
      Parameters:
      name - A name of the action.
      contextConsumer - A consumer to define the behavior of the returned action.
      Returns:
      A leaf action created from the contextConsumer.
    • trivialAction

      public static com.github.dakusui.actionunit.core.Action trivialAction(String name, Consumer<com.github.dakusui.actionunit.core.Context> contextConsumer)
      Creates a trivial leaf action, which is the same as an action created by InternalUtils.action(String, Consumer<Context>).
      Parameters:
      name - A name of the action.
      contextConsumer - A consumer that defines the behavior of the action.
    • dateAfter

      public static Predicate<Date> dateAfter(Date date)
      Returns a predicate that tests if the date given to it is after the date.
      Parameters:
      date - The returned predicate returns true if a given date is after this.
      Returns:
      A predicate to check if a given date is after date.
    • isToStringOverridden

      public static boolean isToStringOverridden(Object object)
      Checks if the given object has a toString method which overrides Object#toString.
      Parameters:
      object - An object to be checked.
      Returns:
      true - toString method is overridden / false - otherwise.
    • wrap

      public static RuntimeException wrap(Throwable e)

      // @formatter:off Wraps a given exception e with a framework specific exception, AutotestException.

      This method has RuntimeException as return value type, however, this method will never return a value but throws an exception. The return type is defined to be able to write a caller code in the following style, which increases readability.

      try {
        doSomthing()
      } catch (SomeCheckedException e) {
        throw wrap(e);
      }
      

      If a given exception e is a RuntimeException, or an Error, it will not be wrapped, but e will be directly thrown.

      // @formatter:on

      Parameters:
      e - An exception to be wrapped.
      Returns:
      This method will never return any value.
    • writeTo

      public static void writeTo(File file, String text)

      Write a given text to a file. When the file already exists, text will be appended to it. text will be encoded into UTF-8 since this method calls Files.writeString(Path,String,OpenOption...) internally.

      In case the file doesn't exist or its parent directories don't exist, this function will try to create them.

      On a failure, a runtime exception will be thrown.

      Parameters:
      file - A file to which text is written to.
      text - A data to be written.
    • removeFile

      public static void removeFile(File file)
      Removes a given file, if exists. If it doesn't exist, this method does nothing. If the file is a directory, it must be empty. Otherwise, an exception will be thrown.
      Parameters:
      file - A file to be deleted. Must not be null.
    • reverse

      public static <T> List<T> reverse(List<T> list)
    • materializeResource

      public static File materializeResource(String resourcePath)
      Copies the contents of a resource file from the classpath to a temporary file
      Parameters:
      resourcePath - A path to a resource on a class path to be materialized
      Returns:
      a temporary file path containing the contents of the resource
    • materializeResource

      public static void materializeResource(File output, String resourcePath)
      Copies the contents of a resource file from the classpath to a specified output file.
      Parameters:
      output - The output file to which the resource contents will be written
      resourcePath - A path to a resource on a class path to be materialized
    • copyTo

      public static void copyTo(InputStream in1, OutputStream out1)
    • temporaryDirectory

      public static File temporaryDirectory()