Class ThresholdFocusListener

java.lang.Object
io.micronaut.test.typepollution.ThresholdFocusListener
All Implemented Interfaces:
FocusListener

public final class ThresholdFocusListener extends Object implements FocusListener
FocusListener implementation that counts and tracks all focus events, including stack traces. At the end of the test, checkThresholds(long) can be used to verify that no concrete class exceeded a given focus event threshold.
  • Constructor Details

    • ThresholdFocusListener

      public ThresholdFocusListener()
  • Method Details

    • onFocus

      public void onFocus(Class<?> concreteType, Class<?> interfaceType)
      Description copied from interface: FocusListener
      Called on every focus event, potentially concurrently.
      Specified by:
      onFocus in interface FocusListener
      Parameters:
      concreteType - The concrete type that was checked
      interfaceType - The interface type that the concrete type was type checked against
    • checkThresholds

      public boolean checkThresholds(long threshold)
      Check whether the number of focus events exceeded the given threshold for any concrete class. If this is the case, this method also prints a human-readable report on all type checking stack traces for the concrete type to System.out.
      Parameters:
      threshold - The number of events that should not be exceeded
      Returns:
      false iff any concrete class was type checked too often