Beispiel #1
0
 // Unsafe mechanics
 static long objectFieldOffset(sun.misc.Unsafe UNSAFE, String field, Class<?> klazz) {
   try {
     return UNSAFE.objectFieldOffset(klazz.getDeclaredField(field));
   } catch (NoSuchFieldException e) {
     // Convert Exception to corresponding Error
     NoSuchFieldError error = new NoSuchFieldError(field);
     error.initCause(e);
     throw error;
   }
 }
 /**
  * The instance is stored in a place directly accessible through the Java SE API, so that it can
  * be recovered from any class loader.
  */
 protected MockingBridge(Class<? extends MockingBridge> subclass) {
   super("mockit." + subclass.hashCode(), null);
   LogManager.getLogManager().addLogger(this);
 }
  public static void preventEventualClassLoadingConflicts() {
    // Pre-load certain JMockit classes to avoid NoClassDefFoundError's or re-entrancy loops during
    // class loading
    // when certain JRE classes are mocked, such as ArrayList or Thread.
    try {
      Class.forName("mockit.Capturing");
      Class.forName("mockit.Delegate");
      Class.forName("mockit.Invocation");
      Class.forName("mockit.internal.RedefinitionEngine");
      Class.forName("mockit.internal.util.GeneratedClasses");
      Class.forName("mockit.internal.util.MethodReflection");
      Class.forName("mockit.internal.util.ObjectMethods");
      Class.forName("mockit.internal.util.TypeDescriptor");
      Class.forName("mockit.internal.expectations.RecordAndReplayExecution");
      Class.forName("mockit.internal.expectations.invocation.InvocationResults");
      Class.forName("mockit.internal.expectations.invocation.MockedTypeCascade");
      Class.forName("mockit.internal.expectations.mocking.BaseTypeRedefinition$MockedClass");
      Class.forName("mockit.internal.expectations.mocking.SharedFieldTypeRedefinitions");
      Class.forName("mockit.internal.expectations.mocking.TestedClasses");
      Class.forName("mockit.internal.expectations.argumentMatching.EqualityMatcher");
    } catch (ClassNotFoundException ignore) {
    }

    wasCalledDuringClassLoading();
    DefaultValues.computeForReturnType("()J");
  }