Package net.groboclown.retval.monitor
Class MockObservedMonitor<T>
- java.lang.Object
-
- net.groboclown.retval.monitor.MockObservedMonitor<T>
-
- All Implemented Interfaces:
ObservedMonitor<T>
- Direct Known Subclasses:
MockProblemMonitor
public abstract class MockObservedMonitor<T> extends java.lang.Object implements ObservedMonitor<T>
A mock check monitor, suitable for testing. Note that if used in a non-test environment, this has the potential to quickly consume lots of memory.This replaces the observed monitor and the ret generator to return monitored values.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMockObservedMonitor.Registered<T>Tracks the number of times the closeable is called.-
Nested classes/interfaces inherited from interface net.groboclown.retval.monitor.ObservedMonitor
ObservedMonitor.Listener
-
-
Field Summary
Fields Modifier and Type Field Description booleantraceEnabled
-
Constructor Summary
Constructors Modifier Constructor Description protectedMockObservedMonitor(ObservedMonitor<T> previous)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description MockObservedMonitor.Registered<T>findRegistered(T value)Finds the registered instance for the observed object.java.util.List<T>getNeverObserved()Return all registered closeable objects that never had the close called on the listener.protected ObservedMonitor<T>getPrevious()Get the previously installed monitor, which this monitor replaced.protected ReturnTypeFactorygetPreviousReturnTypeFactory()Get the previously installed return type factory, which this object replaced.booleanisTraceEnabled()Is tracing enabled? If not enabled, then more memory efficient versions of objects may be used.ObservedMonitor.ListenerregisterInstance(T instance)Register a new observable object with the monitor.abstract voidtearDown()Tear down this monitor to the pre-setup state.
-
-
-
Constructor Detail
-
MockObservedMonitor
protected MockObservedMonitor(@Nonnull ObservedMonitor<T> previous)
-
-
Method Detail
-
getPrevious
@Nonnull protected ObservedMonitor<T> getPrevious()
Get the previously installed monitor, which this monitor replaced. Allows for easy restore of the previous state when the system finishes using this mock monitor.- Returns:
- the previously installed monitor
-
getPreviousReturnTypeFactory
@Nonnull protected ReturnTypeFactory getPreviousReturnTypeFactory()
Get the previously installed return type factory, which this object replaced. Allows for easy restore of the previous state when the system finishes using this object.- Returns:
- the previously installed factory
- Since:
- 2.1
-
tearDown
public abstract void tearDown()
Tear down this monitor to the pre-setup state.
-
registerInstance
@Nonnull public ObservedMonitor.Listener registerInstance(@Nonnull T instance)
Description copied from interface:ObservedMonitorRegister a new observable object with the monitor. The returned value must be immutable in all but unit test environments.- Specified by:
registerInstancein interfaceObservedMonitor<T>- Parameters:
instance- instance to register- Returns:
- a callback listener for when the close action occurs.
-
isTraceEnabled
public boolean isTraceEnabled()
Description copied from interface:ObservedMonitorIs tracing enabled? If not enabled, then more memory efficient versions of objects may be used.- Specified by:
isTraceEnabledin interfaceObservedMonitor<T>- Returns:
- true if close tracing is enabled, false otherwise.
-
findRegistered
@Nullable public MockObservedMonitor.Registered<T> findRegistered(@Nonnull T value)
Finds the registered instance for the observed object. If not returned, then it was never registered. This uses `==` identity checking rather thanObject.equals(Object).This method allows for a deep inspection into how the RetVal classes operate.
- Parameters:
value- source object- Returns:
- registered closeable object, or null if never registered.
-
getNeverObserved
@Nonnull public java.util.List<T> getNeverObserved()
Return all registered closeable objects that never had the close called on the listener.- Returns:
- all never closed, registered objects.
-
-