当前位置: 首页>>代码示例>>Java>>正文


Java CodeGenerationException类代码示例

本文整理汇总了Java中org.mockito.cglib.core.CodeGenerationException的典型用法代码示例。如果您正苦于以下问题:Java CodeGenerationException类的具体用法?Java CodeGenerationException怎么用?Java CodeGenerationException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


CodeGenerationException类属于org.mockito.cglib.core包,在下文中一共展示了CodeGenerationException类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPropertiesHelper

import org.mockito.cglib.core.CodeGenerationException; //导入依赖的package包/类
private static PropertyDescriptor[] getPropertiesHelper(Class type, boolean read, boolean write) {
    try {
        BeanInfo info = Introspector.getBeanInfo(type, Object.class);
        PropertyDescriptor[] all = info.getPropertyDescriptors();
        if (read && write) {
            return all;
        }
        List properties = new ArrayList(all.length);
        for (int i = 0; i < all.length; i++) {
            PropertyDescriptor pd = all[i];
            if ((read && pd.getReadMethod() != null) ||
                (write && pd.getWriteMethod() != null)) {
                properties.add(pd);
            }
        }
        return (PropertyDescriptor[])properties.toArray(new PropertyDescriptor[properties.size()]);
    } catch (IntrospectionException e) {
        throw new CodeGenerationException(e);
    }
}
 
开发者ID:elastic,项目名称:securemock,代码行数:21,代码来源:ReflectUtils.java

示例2: getConstructor

import org.mockito.cglib.core.CodeGenerationException; //导入依赖的package包/类
public static Constructor getConstructor(final Class type, final Class[] parameterTypes) {
    try {
        return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor>() {
          @Override
          public Constructor run() throws NoSuchMethodException {
            Constructor constructor = type.getDeclaredConstructor(parameterTypes);
            constructor.setAccessible(true);
            return constructor;
          }
        });
    } catch (PrivilegedActionException e) {
        throw new CodeGenerationException(e.getCause());
    }
}
 
开发者ID:elastic,项目名称:securemock,代码行数:15,代码来源:ReflectUtils.java

示例3: createProxyClass

import org.mockito.cglib.core.CodeGenerationException; //导入依赖的package包/类
private Class<?> createProxyClass(Class<?> mockedType, Class<?>...interfaces) {
    if (mockedType == Object.class) {
        mockedType = ClassWithSuperclassToWorkAroundCglibBug.class;
    }
    
    Enhancer enhancer = new Enhancer() {
        @Override
        @SuppressWarnings("unchecked")
        protected void filterConstructors(Class sc, List constructors) {
            // Don't filter
        }
    };
    enhancer.setClassLoader(SearchingClassLoader.combineLoadersOf(mockedType));
    enhancer.setUseFactory(true);
    if (mockedType.isInterface()) {
        enhancer.setSuperclass(Object.class);
        enhancer.setInterfaces(prepend(mockedType, interfaces));
    } else {
        enhancer.setSuperclass(mockedType);
        enhancer.setInterfaces(interfaces);
    }
    enhancer.setCallbackTypes(new Class[]{MethodInterceptor.class, NoOp.class});
    enhancer.setCallbackFilter(IGNORE_BRIDGE_METHODS);
    if (mockedType.getSigners() != null) {
        enhancer.setNamingPolicy(NAMING_POLICY_THAT_ALLOWS_IMPOSTERISATION_OF_CLASSES_IN_SIGNED_PACKAGES);
    } else {
        enhancer.setNamingPolicy(MockitoNamingPolicy.INSTANCE);
    }
    
    try {
        return enhancer.createClass(); 
    } catch (CodeGenerationException e) {
        if (Modifier.isPrivate(mockedType.getModifiers())) {
            throw new MockitoException("\n"
                    + "Mockito cannot mock this class: " + mockedType 
                    + ".\n"
                    + "Most likely it is a private class that is not visible by Mockito");
        }
        throw new MockitoException("\n"
                + "Mockito cannot mock this class: " + mockedType 
                + "\n" 
                + "Mockito can only mock visible & non-final classes."
                + "\n" 
                + "If you're not sure why you're getting this error, please report to the mailing list.", e);
    }
}
 
开发者ID:elastic,项目名称:securemock,代码行数:47,代码来源:ClassImposterizer.java

示例4: createProxyClass

import org.mockito.cglib.core.CodeGenerationException; //导入依赖的package包/类
public Class<Factory> createProxyClass(Class<?> mockedType, Class<?>... interfaces) {
    if (mockedType == Object.class) {
        mockedType = ClassWithSuperclassToWorkAroundCglibBug.class;
    }

    Enhancer enhancer = new Enhancer() {
        @Override
        @SuppressWarnings("unchecked")
        protected void filterConstructors(Class sc, List constructors) {
            // Don't filter
        }
    };
    Class<?>[] allMockedTypes = prepend(mockedType, interfaces);
    enhancer.setClassLoader(SearchingClassLoader.combineLoadersOf(allMockedTypes));
    enhancer.setUseFactory(true);
    if (mockedType.isInterface()) {
        enhancer.setSuperclass(Object.class);
        enhancer.setInterfaces(allMockedTypes);
    } else {
        enhancer.setSuperclass(mockedType);
        enhancer.setInterfaces(interfaces);
    }
    enhancer.setCallbackTypes(new Class[]{MethodInterceptor.class, NoOp.class});
    enhancer.setCallbackFilter(IGNORE_BRIDGE_METHODS);
    if (mockedType.getSigners() != null) {
        enhancer.setNamingPolicy(NAMING_POLICY_THAT_ALLOWS_IMPOSTERISATION_OF_CLASSES_IN_SIGNED_PACKAGES);
    } else {
        enhancer.setNamingPolicy(MockitoNamingPolicy.INSTANCE);
    }

    enhancer.setSerialVersionUID(42L);

    try {
        return enhancer.createClass();
    } catch (CodeGenerationException e) {
        if (Modifier.isPrivate(mockedType.getModifiers())) {
            throw new MockitoException("\n"
                    + "Mockito cannot mock this class: " + mockedType
                    + ".\n"
                    + "Most likely it is a private class that is not visible by Mockito");
        }
        throw new MockitoException("\n"
                + "Mockito cannot mock this class: " + mockedType
                + "\n"
                + "Mockito can only mock visible & non-final classes."
                + "\n"
                + "If you're not sure why you're getting this error, please report to the mailing list.", e);
    }
}
 
开发者ID:mockito,项目名称:mockito-cglib,代码行数:50,代码来源:ClassImposterizer.java

示例5: createProxyClass

import org.mockito.cglib.core.CodeGenerationException; //导入依赖的package包/类
public Class<?> createProxyClass(Class<?> mockedType, Class<?>... interfaces) {
      if (mockedType == Object.class) {
          mockedType = ClassWithSuperclassToWorkAroundCglibBug.class;
      }
      
      Enhancer enhancer = new Enhancer() {
          @Override
          @SuppressWarnings("unchecked")
          protected void filterConstructors(Class sc, List constructors) {
              // Don't filter
          }
      };
      Class<?>[] allMockedTypes = prepend(mockedType, interfaces);
enhancer.setClassLoader(SearchingClassLoader.combineLoadersOf(allMockedTypes));
      enhancer.setUseFactory(true);
      if (mockedType.isInterface()) {
          enhancer.setSuperclass(Object.class);
          enhancer.setInterfaces(allMockedTypes);
      } else {
          enhancer.setSuperclass(mockedType);
          enhancer.setInterfaces(interfaces);
      }
      enhancer.setCallbackTypes(new Class[]{MethodInterceptor.class, NoOp.class});
      enhancer.setCallbackFilter(IGNORE_BRIDGE_METHODS);
      if (mockedType.getSigners() != null) {
          enhancer.setNamingPolicy(NAMING_POLICY_THAT_ALLOWS_IMPOSTERISATION_OF_CLASSES_IN_SIGNED_PACKAGES);
      } else {
          enhancer.setNamingPolicy(MockitoNamingPolicy.INSTANCE);
      }

      enhancer.setSerialVersionUID(42L);
      
      try {
          return enhancer.createClass(); 
      } catch (CodeGenerationException e) {
          if (Modifier.isPrivate(mockedType.getModifiers())) {
              throw new MockitoException("\n"
                      + "Mockito cannot mock this class: " + mockedType 
                      + ".\n"
                      + "Most likely it is a private class that is not visible by Mockito");
          }
          throw new MockitoException("\n"
                  + "Mockito cannot mock this class: " + mockedType 
                  + "\n" 
                  + "Mockito can only mock visible & non-final classes."
                  + "\n" 
                  + "If you're not sure why you're getting this error, please report to the mailing list.", e);
      }
  }
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:50,代码来源:ClassImposterizer.java


注:本文中的org.mockito.cglib.core.CodeGenerationException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。