Package org.mockito

Interface ScopedMock

  • All Superinterfaces:
    java.lang.AutoCloseable
    All Known Subinterfaces:
    MockedConstruction<T>, MockedStatic<T>
    All Known Implementing Classes:
    MockedConstructionImpl, MockedStaticImpl

    public interface ScopedMock
    extends java.lang.AutoCloseable
    Represents a mock with a thread-local explicit scope. Scoped mocks must be closed by the entity that activates the scoped mock.
    • Method Summary

      All Methods Instance Methods Abstract Methods 
      Modifier and Type Method Description
      void close()
      Closes this scoped mock and throws an exception if already closed.
      void closeOnDemand()
      Releases this scoped mock and is non-operational if already released.
      boolean isClosed()
      Checks if this mock is closed.
    • Method Detail

      • isClosed

        boolean isClosed()
        Checks if this mock is closed.
        Returns:
        true if this mock is closed.
      • close

        void close()
        Closes this scoped mock and throws an exception if already closed.
        Specified by:
        close in interface java.lang.AutoCloseable
      • closeOnDemand

        void closeOnDemand()
        Releases this scoped mock and is non-operational if already released.