Module org.mockito
Package org.mockito

Interface MockedSingleton<T>

Type Parameters:
T - The type of the singleton being mocked.
All Superinterfaces:
AutoCloseable, ScopedMock

public interface MockedSingleton<T> extends ScopedMock
Represents an active thread-local mock of a singleton instance. The mocking only affects the thread on which Mockito.mockSingleton(Object) was called, and the instance only behaves as a mock on that thread. The singleton mock is released when this object's ScopedMock.close() method is invoked. If this object is never closed, the mock will remain active on the initiating thread. It is therefore recommended to create this object within a try-with-resources statement.

Stubbing and verification on the instance can be done using the standard Mockito APIs.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the mocked singleton instance.

    Methods inherited from interface org.mockito.ScopedMock

    close, closeOnDemand, isClosed
  • Method Details

    • getInstance

      T getInstance()
      Returns the mocked singleton instance.