Class MockTestSupport

java.lang.Object
net.officefloor.frame.test.MockTestSupport
All Implemented Interfaces:
TestSupport

public class MockTestSupport extends Object implements TestSupport
Mock test support.
Author:
Daniel Sagenschneider
  • Constructor Details

    • MockTestSupport

      public MockTestSupport(LogTestSupport logTestSupport)
      Initiate.
      Parameters:
      logTestSupport - LogTestSupport.
    • MockTestSupport

      public MockTestSupport()
      Default instantiation.
  • Method Details

    • init

      public void init(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Description copied from interface: TestSupport
      Intialise.
      Specified by:
      init in interface TestSupport
      Parameters:
      context - ExtensionContext.
      Throws:
      Exception - If fails to init.
    • createMock

      public <M> M createMock(Class<M> classToMock)
      Creates a mock object registering the mock object with registry for management.
      Type Parameters:
      M - Interface type.
      Parameters:
      classToMock - Class to be mocked.
      Returns:
      Mock object.
    • createSynchronizedMock

      public <M> M createSynchronizedMock(Class<M> interfaceToMock)
      Creates a thread safe mock object.
      Type Parameters:
      M - Interface type.
      Parameters:
      interfaceToMock - Class to mock.
      Returns:
      Mock object.
    • param

      public <T> T param(T value)
      Wraps a parameter value when attempting to capture.
      Type Parameters:
      T - Value type.
      Parameters:
      value - Value.
      Returns:
      Value for parameter.
    • paramType

      public <T> T paramType(Class<T> type)
      Wraps a parameter type expected.
      Type Parameters:
      T - Value type.
      Parameters:
      type - Expected type.
      Returns:
      Value for parameter.
    • recordReturn

      public <T> void recordReturn(Object mockObject, T ignore, T recordedReturn)
      Convenience method to record a method and its return on a mock object.
      Type Parameters:
      T - Expected result type.
      Parameters:
      mockObject - Mock object.
      ignore - Result of operation on the mock object. This is only provided to obtain correct return type for recording return.
      recordedReturn - Value that is recorded to be returned from the mock object.
    • recordReturn

      public <T> void recordReturn(Object mockObject, T ignore, T recordedReturn, ArgumentsMatcher matcher)
      Convenience method to record a method, an ArgumentsMatcher and return value.
      Type Parameters:
      T - Expected result type.
      Parameters:
      mockObject - Mock object.
      ignore - Result of operation on the mock object. This is only provided to obtain correct return type for recording return.
      recordedReturn - Value that is recorded to be returned from the mock object.
      matcher - ArgumentsMatcher.
    • recordVoid

      public void recordVoid(Object mockObject, ArgumentsMatcher matcher)
      Convenience method to record void method.
      Parameters:
      mockObject - Mock object.
      matcher - ArgumentsMatcher.
    • recordThrows

      public <T> void recordThrows(Object mockObject, T ignore, Throwable exception)
      Convenience method to record an Exception.
      Type Parameters:
      T - Expected result type.
      Parameters:
      mockObject - Mock object.
      ignore - Result of operation on the mock object. This is only provided to obtain correct return type for recording return.
      exception - Throwable.
    • replayMockObjects

      public void replayMockObjects()
      Flags all the mock objects to replay.
    • verifyMockObjects

      public void verifyMockObjects()
      Verifies all mock objects.
    • doTest

      protected <R, T extends Throwable> R doTest(MockTestSupport.TestLogic<R,T> test) throws T
      Undertakes test wrapping with mock object replay and verify.
      Type Parameters:
      R - Return type of test logic.
      T - Possible Throwable.
      Parameters:
      test - Test logic to wrap in replay/verify.
      Returns:
      Result of test logic.
      Throws:
      T - If logic throws Exception.