Enum Class InternalUtils
- All Implemented Interfaces:
Serializable
,Comparable<InternalUtils>
,Constable
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static final record
static class
Nested 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.Action
Creates a leaf action, which executes theaccept
method ofcontextConsumer
.static String
composeResultMessageLine
(Class<?> testClass, String stageName, String line) static <T> Stream
<T> Concatenates given streams.static void
copyTo
(InputStream in1, OutputStream out1) static com.github.dakusui.actionunit.core.Context
Returns an action context for InsDog.Returns anOptional
of aString
that contains a branch name.currentBranchNameFor
(File projectDir) Returns anOptional
of aString
that contains a branch name, if the givenprojectDir
has.git
directory and a current branch name of it can be retrieved.static Date
Creates aDate
object from a string formatted withMMM/dd/yyyy
.Returns a predicate that tests if the date given to it is after thedate
.static String
dateToSafeString
(Date date) findMethodByName
(String methodName, Class<?> klass) Note that resolution is done based on the value ofNamed
annotation first.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 String[]
static boolean
static boolean
static boolean
static boolean
static boolean
isToStringOverridden
(Object object) Checks if the givenobject
has atoString
method which overridesObject#toString
.static String
static void
materializeResource
(File output, String resourcePath) Copies the contents of a resource file from the classpath to a specified output file.static File
materializeResource
(String resourcePath) Copies the contents of a resource file from the classpath to a temporary filestatic String
Returns a "name" a givenmethod
.static Date
now()
Returns aDate
object 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
, whentoString
method is called.static File
static void
removeFile
(File file) Removes a givenfile
, if exists.static <T> List
<T> static String
A shorthand method ofshorten(string, 120)
.static String
Shorten astring
to the specifiedlength
.static String
simpleClassNameOf
(Class<?> clazz) static String
spaces
(int i) static File
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>)
.static InternalUtils
Returns 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 String
variableNameToString
(String variableName) static RuntimeException
// @formatter:off Wraps a given exceptione
with a framework specific exception,AutotestException
.static void
Write a giventext
to 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
Optional
of aString
that contains a branch name, if the givenprojectDir
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 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 astring
to the specifiedlength
. In casestring
contains a carriage return (\r
), a substring from the beginning of thestring
to the position of the character will be returned.- Parameters:
string
- A string to be shortened.length
- A length to whichstring
to 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) -
nameOf
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 toNamed.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
Note that resolution is done based on the value ofNamed
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
-
getDependencyAnnotationValues
-
variableNameToString
-
spaces
-
date
-
now
Returns aDate
object 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
, whentoString
method 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
accept
method of the consumer and returnsconsumerName
fortoString
.
-
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 theaccept
method ofcontextConsumer
. Inside this method, the givencontextConsumer
method is made printable using theprintableConsumer
method. Then it will be passed toActionSupport#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 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 givenobject
has atoString
method which overridesObject#toString
.- Parameters:
object
- An object to be checked.- Returns:
true
-toString
method is overridden /false
- otherwise.
-
wrap
// @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 aRuntimeException
, or anError
, it will not be wrapped, bute
will be directly thrown.// @formatter:on
- Parameters:
e
- An exception to be wrapped.- Returns:
- This method will never return any value.
-
writeTo
Write a given
text
to afile
. When thefile
already exists,text
will be appended to it.text
will be encoded intoUTF-8
since this method callsFiles.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 whichtext
is written to.text
- A data to be written.
-
removeFile
Removes a givenfile
, if exists. If it doesn't exist, this method does nothing. If thefile
is 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
-