Enum Class InternalUtils
- All Implemented Interfaces:
Serializable,Comparable<InternalUtils>,Constable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final recordstatic classNested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic com.github.dakusui.actionunit.core.ActionCreates a leaf action, which executes theacceptmethod ofcontextConsumer.static StringcomposeResultMessageLine(Class<?> testClass, String stageName, String line) static <T> Stream<T> Concatenates given streams.static voidcopyTo(InputStream in1, OutputStream out1) static com.github.dakusui.actionunit.core.ContextReturns an action context for InsDog.Returns anOptionalof aStringthat contains a branch name.currentBranchNameFor(File projectDir) Returns anOptionalof aStringthat contains a branch name, if the givenprojectDirhas.gitdirectory and a current branch name of it can be retrieved.static DateCreates aDateobject from a string formatted withMMM/dd/yyyy.Returns a predicate that tests if the date given to it is after thedate.static StringdateToSafeString(Date date) static Stream<com.github.dakusui.actionunit.core.Action> flattenIfSequential(com.github.dakusui.actionunit.core.Action a) static Stream<com.github.dakusui.actionunit.core.Action> flattenSequentialAction(com.github.dakusui.actionunit.core.Action action) static booleanstatic booleanstatic booleanstatic booleanisToStringOverridden(Object object) Checks if the givenobjecthas atoStringmethod which overridesObject#toString.static Stringstatic voidmaterializeResource(File output, String resourcePath) Copies the contents of a resource file from the classpath to a specified output file.static FilematerializeResource(String resourcePath) Copies the contents of a resource file from the classpath to a temporary filestatic Datenow()Returns aDateobject from the current date.static Consumer<com.github.dakusui.actionunit.core.Context> printableConsumer(String consumerName, Consumer<com.github.dakusui.actionunit.core.Context> consumer) Creates a consumer, which gives aconsumerName, whentoStringmethod is called.static Filestatic voidremoveFile(File file) Removes a givenfile, if exists.static <T> List<T> static StringA shorthand method ofshorten(string, 120).static StringShorten astringto the specifiedlength.static StringsimpleClassNameOf(Class<?> clazz) static Filestatic com.github.dakusui.actionunit.core.ActiontrivialAction(String name, Consumer<com.github.dakusui.actionunit.core.Context> contextConsumer) Creates a trivial leaf action, which is the same as an action created byInternalUtils.action(String, Consumer<Context>).static InternalUtilsReturns the enum constant of this class with the specified name.static InternalUtils[]values()Returns an array containing the constants of this enum class, in the order they are declared.static RuntimeException// @formatter:off Wraps a given exceptionewith a framework specific exception,AutotestException.static voidWrite a giventextto afile.
-
Field Details
-
LOGGER
public static final org.slf4j.Logger LOGGER
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
currentBranchName
-
currentBranchNameFor
Returns an
Optionalof aStringthat contains a branch name, if the givenprojectDirhas.gitdirectory and a current branch name of it can be retrieved. An exception will be thrown on a failure during this step.Otherwise, an empty
Optionalwill be returned.- Returns:
- An
Optionalof branch nameString.
-
isPresumablyRunningFromIDE
public static boolean isPresumablyRunningFromIDE() -
isRunUnderSurefire
public static boolean isRunUnderSurefire() -
isRunUnderPitest
public static boolean isRunUnderPitest() -
composeResultMessageLine
-
projectDir
-
simpleClassNameOf
-
flattenIfSequential
public static Stream<com.github.dakusui.actionunit.core.Action> flattenIfSequential(com.github.dakusui.actionunit.core.Action a) -
shorten
-
shorten
Shorten astringto the specifiedlength. In casestringcontains a carriage return (\r), a substring from the beginning of thestringto the position of the character will be returned.- Parameters:
string- A string to be shortened.length- A length to whichstringto be shortened.- Returns:
- A shortened string.
-
mask
-
flattenSequentialAction
public static Stream<com.github.dakusui.actionunit.core.Action> flattenSequentialAction(com.github.dakusui.actionunit.core.Action action) -
date
-
now
Returns aDateobject from the current date.- Returns:
- A date object created from the current date.
-
dateToSafeString
-
concat
Concatenates given streams.- Type Parameters:
T- The type of the values streamed by the givenstreams.- 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 aconsumerName, whentoStringmethod is called.- Parameters:
consumerName- A name of the created consumer. Returned fromtoString.consumer- A consumer from which the returned object is created.- Returns:
- A consumer which executes the
acceptmethod of the consumer and returnsconsumerNamefortoString.
-
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 theacceptmethod ofcontextConsumer. Inside this method, the givencontextConsumermethod is made printable using theprintableConsumermethod. Then it will be passed toActionSupport#leafmethod 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 byInternalUtils.action(String, Consumer<Context>).- Parameters:
name- A name of the action.contextConsumer- A consumer that defines the behavior of the action.
-
dateAfter
-
isToStringOverridden
Checks if the givenobjecthas atoStringmethod which overridesObject#toString.- Parameters:
object- An object to be checked.- Returns:
true-toStringmethod is overridden /false- otherwise.
-
wrap
// @formatter:off Wraps a given exception
ewith a framework specific exception,AutotestException.This method has
RuntimeExceptionas 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
eis aRuntimeException, or anError, it will not be wrapped, butewill be directly thrown.// @formatter:on
- Parameters:
e- An exception to be wrapped.- Returns:
- This method will never return any value.
-
writeTo
Write a given
textto afile. When thefilealready exists,textwill be appended to it.textwill be encoded intoUTF-8since this method callsFiles.writeString(Path,String,OpenOption...)internally.In case the
filedoesn'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 whichtextis written to.text- A data to be written.
-
removeFile
Removes a givenfile, if exists. If it doesn't exist, this method does nothing. If thefileis a directory, it must be empty. Otherwise, an exception will be thrown.- Parameters:
file- A file to be deleted. Must not benull.
-
reverse
-
materializeResource
-
materializeResource
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 writtenresourcePath- A path to a resource on a class path to be materialized
-
copyTo
-
temporaryDirectory
-