Class TestSubjectInspector
java.lang.Object
com.weirddev.testme.intellij.template.context.TestSubjectInspector
Classifies test subject type.
Date: 31/03/2017
- Author:
- Yaron Yamin
-
Constructor Summary
ConstructorDescriptionTestSubjectInspector
(boolean generateTestsForInheritedMethods, FileTemplateCustomization fileTemplateCustomization) -
Method Summary
Modifier and TypeMethodDescription@Nullable Method
findOptimalConstructor
(Type type) find an optimal constructor in type declaration.formatSpockDataParameters
(Map<String, String> paramsMap, String linePrefix) Constructs a formatted string of parameterized params table for spock test.formatSpockParamNamesTitle
(Map<String, String> paramsMap, boolean methodHasReturn) boolean
hasAccessibleCtor
(Type testedClass) for class with only private constructor that can not mock, for example util classes only with static methodsboolean
hasScalaFutureReturn
(List<Method> methods) boolean
hasTestableInstanceMethod
(List<Method> methods) boolean
isJavaFuture
(Type type) boolean
isMethodCalled
(Method calledMethod, Method callerMethod) boolean
isMethodOwnedByClass
(Method method, Type testedClass) 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.boolean
isScalaFuture
(Type type) boolean
shouldBeTested
(Method method) true - method should test
-
Constructor Details
-
TestSubjectInspector
public TestSubjectInspector(boolean generateTestsForInheritedMethods, FileTemplateCustomization fileTemplateCustomization)
-
-
Method Details
-
hasTestableInstanceMethod
-
shouldBeTested
true - method should test -
isMethodCalled
- Parameters:
calledMethod
- a calledMethod, possible being calledcallerMethod
- a calledMethod, possibly calling another- Returns:
- true - if callerMethod implementation invokes calledMethod
-
formatSpockParamNamesTitle
- Parameters:
paramsMap
- test params for spock parameterized testmethodHasReturn
- true - if test method returns anything- Returns:
- formatted string of spock test method name with tested parameters
-
formatSpockDataParameters
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
- Returns:
- true - if type is a Java future
-
isScalaFuture
- Returns:
- true - if type is a Scala future
-
hasScalaFutureReturn
- Returns:
- true - if any method has a Scala future type being returned
-
findOptimalConstructor
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
- Returns:
- list of Java SDK types that represent a future. as fully qualified class names
-
getScalaFutureTypes
- Returns:
-
isMethodOwnedByClass
- Parameters:
method
- call methodtestedClass
- the tested class- Returns:
- true - if the method is class object self called method
-
isNotInjectedInDiClass
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
- fieldtestedClass
- testedClass- Returns:
- true if field meet conditions above
-
hasAccessibleCtor
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
-