Class MockitoMockBuilder

java.lang.Object
com.weirddev.testme.intellij.template.context.MockitoMockBuilder
All Implemented Interfaces:
MockBuilder
Direct Known Subclasses:
PowerMockBuilder

public class MockitoMockBuilder extends Object implements MockBuilder
Utilities for Building string constructs of Mockito mock expressions. Date: 31/03/2017
Author:
Yaron Yamin
  • Field Details

    • TYPE_TO_ARG_MATCHERS

      public static final Map<String,String> TYPE_TO_ARG_MATCHERS
    • LOGGER_PATTERN

      public static final Pattern LOGGER_PATTERN
    • WRAPPER_TYPES

      public static final Set<String> WRAPPER_TYPES
  • Constructor Details

    • MockitoMockBuilder

      public MockitoMockBuilder(boolean isMockitoMockMakerInlineOn, boolean stubMockMethodCallsReturnValues, TestSubjectInspector testSubjectInspector, @Nullable @Nullable String mockitoCoreVersion, FileTemplateCustomization fileTemplateCustomization)
  • Method Details

    • isMockable

      @Deprecated public boolean isMockable(Field field)
      Deprecated.
      true - field can be mocked
    • isMockable

      public boolean isMockable(Field field, Type testedClass)
      true - field can be mocked
      Specified by:
      isMockable in interface MockBuilder
    • isMockable

      public boolean isMockable(Param param, Map<String,String> defaultTypes)
      true - if argument can be mocked given the provided default types
    • hasMockable

      public boolean hasMockable(List<Field> fields, Type testedClass)
      true - if any given field can be mocked
    • hasMocks

      public boolean hasMocks(Type testedClass)
      Parameters:
      testedClass - the tested class
      Returns:
      true - if the tested class has mockable field
    • hasMocks

      public boolean hasMocks(Method ctor, Map<String,String> defaultTypes)
      true - if method had any argument that can be mocked given the provided default types
    • getImmockabiliyReason

      public String getImmockabiliyReason(String prefix, Field field)
      constructs an error message explaining why field cannot be mocked
      Specified by:
      getImmockabiliyReason in interface MockBuilder
      Parameters:
      prefix - add prefix to message
      field - reported field
      Returns:
      an error message explaining why field cannot be mocked
    • buildMockArgsMatchers

      public String buildMockArgsMatchers(List<Param> params, String language)
      constructs mocked arguments expression
      Specified by:
      buildMockArgsMatchers in interface MockBuilder
      Parameters:
      params - method params being mocked
      language - String representation of test code Language
      Returns:
      mocked arguments expression
      See Also:
    • shouldStub

      @Deprecated public boolean shouldStub(Method testMethod, List<Field> testedClassFields)
      Deprecated.
    • shouldStub

      public boolean shouldStub(Method testMethod, Type testedClass)
      true - if should stub tested method
      Parameters:
      testMethod - method being tested
      testedClass - tested class
    • shouldVerify

      @Deprecated public boolean shouldVerify(Method testMethod, List<Field> testedClassFields)
      Deprecated.
      true - if should verify tested method
      Parameters:
      testMethod - method being tested
      testedClassFields - tested class fields
    • shouldVerify

      public boolean shouldVerify(Method testMethod, Type testedClass)
      true - if should verify tested method
      Parameters:
      testMethod - method being tested
      testedClass - tested class
    • shouldStub

      public boolean shouldStub(Method testMethod, Method ctor, Map<String,String> defaultTypes)
      true - if tested method should be stubbed
      Parameters:
      testMethod - - method being tested
      ctor - - constructor of method return type
      defaultTypes - - default type values
    • isMockExpected

      public boolean isMockExpected(Field field)
      Specified by:
      isMockExpected in interface MockBuilder
      Returns:
      true - if Field should be mocked
    • isWrapperType

      public boolean isWrapperType(Type type)
      true - if type is a wrapper for other type, such as a primitive
    • getMockitoCoreVersion

      @Nullable public @Nullable String getMockitoCoreVersion()
      Mockito core version. in case mockito-core jar can be found on the target test module classpath. null otherwise
    • getInitMocksMethod

      public String getInitMocksMethod()
      Returns:
      Mockito init mocks method name. typically "initMocks" or "openMocks" depending on Mockito version