Class JKMockUtil

java.lang.Object
com.jk.core.test.JKMockUtil

public class JKMockUtil extends Object
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 Details

    • JKMockUtil

      public JKMockUtil()
  • Method Details

    • createObject

      public static <T> T createObject(Class<T> clas)
      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

      public static void fillFields(Object model)
      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

      public static Object generateRandomValue(Class<?> javaType)
      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

      public static Object generateRandomValue(Field field)
      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

      protected static Object generateRandomValue(String clas)
      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

      public static String createRandomeString(int length, boolean includeQuotation)
      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

      public static String createSequentialString(int length)
      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

      public static void main(String[] args)
      This main method is used for testing the generation of a random value for the String class.
      Parameters:
      args - the command line arguments.