Class DefaultMethodOverrideCheck

java.lang.Object
org.dbunit.annotation.runtime.DefaultMethodOverrideCheck

public class DefaultMethodOverrideCheck extends Object
Checks whether a type provides its own body for a method it would otherwise inherit - either an interface default method (overridesDefaultMethod(java.lang.Class<?>, java.lang.Class<?>, java.lang.String, java.lang.Class<?>...)), or a method a known base class declares (declaresBelow(java.lang.Class<?>, java.lang.Class<?>, java.lang.String, java.lang.Class<?>...)). Shared by every org.dbunit.annotation/ org.dbunit.junit.jupiter call site that needs to fail fast (or otherwise react) when a configured attribute cannot actually reach a non-overriding implementation, instead of silently doing nothing.

Public so a binding outside org.dbunit.annotation.runtime - such as DbUnitExtension - can reach it too.

Since:
3.6.0
Author:
Jeff Jensen
  • Method Details

    • overridesDefaultMethod

      public static boolean overridesDefaultMethod(Class<?> implementationType, Class<?> declaringInterface, String methodName, Class<?>... parameterTypes)
      Returns whether implementationType overrides the named default method declaringInterface declares, rather than inheriting that interface's own default body.

      Known limitation: this check only asks which class declares the method, so it cannot distinguish a real override from a dynamic proxy or a mocking-framework-generated subclass - an unstubbed Mockito mock, for instance - that mechanically redeclares every interface method, default ones included, no matter what its generated body actually does. Such an instance reports true here for every method, silently defeating a fail-fast check built on it. Narrow-audience: only reachable when a test injects such an instance directly, rather than a real implementation.

      Parameters:
      implementationType - The runtime type to check.
      declaringInterface - The interface whose default method methodName names.
      methodName - The method's name.
      parameterTypes - The method's parameter types.
      Returns:
      True when implementationType overrides the method.
    • declaresBelow

      public static boolean declaresBelow(Class<?> type, Class<?> ceiling, String methodName, Class<?>... parameterTypes)
      Returns whether type, or any class between it and ceiling (exclusive), declares the named method - the "does a concrete class redeclare this method below a known base class" question, as distinct from overridesDefaultMethod(java.lang.Class<?>, java.lang.Class<?>, java.lang.String, java.lang.Class<?>...)'s "does a type override an interface default". Walks type's superclass chain, stopping before ceiling and before Object.

      Unlike overridesDefaultMethod(java.lang.Class<?>, java.lang.Class<?>, java.lang.String, java.lang.Class<?>...), a NoSuchMethodException for one class in the range is not an error: that class simply does not declare the method, and the walk continues to its superclass.

      Parameters:
      type - The concrete type to start the walk from.
      ceiling - The base class to stop before; a declaration on ceiling itself does not count.
      methodName - The method's name.
      parameterTypes - The method's parameter types.
      Returns:
      True when some class in [type, ceiling) declares the method.