Class TestSubjectInspector

java.lang.Object
com.weirddev.testme.intellij.template.context.TestSubjectInspector

public class TestSubjectInspector extends Object
Classifies test subject type. Date: 31/03/2017
Author:
Yaron Yamin
  • Constructor Details

    • TestSubjectInspector

      public TestSubjectInspector(boolean generateTestsForInheritedMethods, FileTemplateCustomization fileTemplateCustomization)
  • Method Details

    • hasTestableInstanceMethod

      public boolean hasTestableInstanceMethod(List<Method> methods)
    • shouldBeTested

      public boolean shouldBeTested(Method method)
      true - method should test
    • isMethodCalled

      public boolean isMethodCalled(Method calledMethod, Method callerMethod)
      Parameters:
      calledMethod - a calledMethod, possible being called
      callerMethod - a calledMethod, possibly calling another
      Returns:
      true - if callerMethod implementation invokes calledMethod
    • formatSpockParamNamesTitle

      public String formatSpockParamNamesTitle(Map<String,String> paramsMap, boolean methodHasReturn)
      Parameters:
      paramsMap - test params for spock parameterized test
      methodHasReturn - true - if test method returns anything
      Returns:
      formatted string of spock test method name with tested parameters
    • formatSpockDataParameters

      public String formatSpockDataParameters(Map<String,String> paramsMap, String linePrefix)
      Constructs a formatted string of parameterized params table for spock test. should probably be deprecated in the future, in favor of a method accepting paramsMap of Map<String,List<String>> for multiple values per input argument
      Parameters:
      paramsMap - map of test arguments. for constructing a single parameterized row.
      linePrefix - prefix add to resulting test params, typically used for indentation when passing the required preceding white spaces
      Returns:
      formatted string of parameterized params table for spock test.
    • isJavaFuture

      public boolean isJavaFuture(Type type)
      Returns:
      true - if type is a Java future
    • isScalaFuture

      public boolean isScalaFuture(Type type)
      Returns:
      true - if type is a Scala future
    • hasScalaFutureReturn

      public boolean hasScalaFutureReturn(List<Method> methods)
      Returns:
      true - if any method has a Scala future type being returned
    • findOptimalConstructor

      @Nullable public @Nullable Method findOptimalConstructor(Type type)
      find an optimal constructor in type declaration. a constructor that seems best suited to initialize the type.
      Parameters:
      type - a Type that has constructors
      Returns:
      the optimal constructor found
    • getJavaFutureTypes

      public Set<String> getJavaFutureTypes()
      Returns:
      list of Java SDK types that represent a future. as fully qualified class names
    • getScalaFutureTypes

      public Set<String> getScalaFutureTypes()
      Returns:
    • isMethodOwnedByClass

      public boolean isMethodOwnedByClass(Method method, Type testedClass)
      Parameters:
      method - call method
      testedClass - the tested class
      Returns:
      true - if the method is class object self called method
    • isNotInjectedInDiClass

      public boolean isNotInjectedInDiClass(Field field, Type testedClass)
      Avoid mocking a field if all these conditions are met: class has DI annotation field has no direct DI annotation field does not have a setter there is no class constructor.
      Parameters:
      field - field
      testedClass - testedClass
      Returns:
      true if field meet conditions above
    • hasAccessibleCtor

      public boolean hasAccessibleCtor(Type testedClass)
      for class with only private constructor that can not mock, for example util classes only with static methods
      Parameters:
      testedClass - tested class
      Returns:
      true - if tested class has public constructors