Package com.jk.core.test
Class JKMockUtil
java.lang.Object
com.jk.core.test.JKMockUtil
This class is used for creating mock objects and generating random values for
various Java types.
- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> TcreateObject(Class<T> clas) This method creates and returns an instance of the specified class with filled fields.static StringcreateRandomeString(int length, boolean includeQuotation) This method creates a random string of the specified length.static StringcreateSequentialString(int length) This method creates a sequential string of the specified length.static voidfillFields(Object model) This method fills the fields of the provided model object with generated random values.static ObjectgenerateRandomValue(Class<?> javaType) This method generates a random value of the specified Java type.static ObjectgenerateRandomValue(Field field) This method generates a random value for the specified field's type.protected static ObjectgenerateRandomValue(String clas) This method generates a random value for the specified class name.static voidThis main method is used for testing the generation of a random value for the String class.
-
Constructor Details
-
JKMockUtil
public JKMockUtil()
-
-
Method Details
-
createObject
This method creates and returns an instance of the specified class with filled fields.- Type Parameters:
T- Specifies the type of class.- Parameters:
clas- Specifies the class to create an instance of.- Returns:
- an instance of the specified class with filled fields.
-
fillFields
This method fills the fields of the provided model object with generated random values.- Parameters:
model- Specifies the object whose fields need to be filled.
-
generateRandomValue
This method generates a random value of the specified Java type.- Parameters:
javaType- Specifies the Java type for which to generate a random value.- Returns:
- a random value of the specified Java type.
-
generateRandomValue
This method generates a random value for the specified field's type.- Parameters:
field- Specifies the field for which to generate a random value.- Returns:
- a random value for the specified field's type.
-
generateRandomValue
This method generates a random value for the specified class name.- Parameters:
clas- Specifies the class name for which to generate a random value.- Returns:
- a random value for the specified class name.
-
createRandomeString
This method creates a random string of the specified length.- Parameters:
length- Specifies the length of the random string.includeQuotation- Indicated whether to include quotation marks around the string.- Returns:
- a random string of the specified length.
-
createSequentialString
This method creates a sequential string of the specified length.- Parameters:
length- Specifies the length of the sequential string.- Returns:
- a sequential string of the specified length.
-
main
This main method is used for testing the generation of a random value for the String class.- Parameters:
args- the command line arguments.
-