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


Java Objenesis.newInstance方法代码示例

本文整理汇总了Java中org.objenesis.Objenesis.newInstance方法的典型用法代码示例。如果您正苦于以下问题:Java Objenesis.newInstance方法的具体用法?Java Objenesis.newInstance怎么用?Java Objenesis.newInstance使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.objenesis.Objenesis的用法示例。


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

示例1: getClient

import org.objenesis.Objenesis; //导入方法依赖的package包/类
public static Client getClient() {
    if (client == null) {
        Objenesis objenesis = new ObjenesisStd();

        try {
            client = (Client) objenesis.newInstance(Context.getInstance().getASMClassLoader().loadClass("oss/iIIiiiiIiI"));
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }

    return client;
}
 
开发者ID:Parabot,项目名称:Parabot-317-API-Minified-OS-Scape,代码行数:14,代码来源:Loader.java

示例2: setup

import org.objenesis.Objenesis; //导入方法依赖的package包/类
@Before
public void setup() {
	this.mockMvc = MockMvcBuilders.webAppContextSetup(this.wac).build();

	// prepare mocks
	this.noteStoreOperations = mock(NoteStoreOperations.class, withSettings().extraInterfaces(StoreClientHolder.class));
	this.userStoreOperations = mock(UserStoreOperations.class, withSettings().extraInterfaces(StoreClientHolder.class));

	// To work around getClass() method to return actual store-client class for parameter name discovery, use
	// objenesis to create actual impl class instead of mocking.
	// mockito cannot mock getClass() since this method is final.
	Objenesis objenesis = new ObjenesisStd();
	UserStoreClient userStoreClient = (UserStoreClient) objenesis.newInstance(UserStoreClient.class);
	NoteStoreClient noteStoreClient = (NoteStoreClient) objenesis.newInstance(NoteStoreClient.class);
	when(((StoreClientHolder) userStoreOperations).getStoreClient()).thenReturn(userStoreClient);
	when(((StoreClientHolder) noteStoreOperations).getStoreClient()).thenReturn(noteStoreClient);

	when(this.evernote.userStoreOperations()).thenReturn(userStoreOperations);
	when(this.evernote.noteStoreOperations()).thenReturn(noteStoreOperations);
}
 
开发者ID:ttddyy,项目名称:evernote-rest-webapp,代码行数:21,代码来源:AbstractStoreOperationControllerIntegrationTest.java

示例3: createUnderlyingObjectProxy

import org.objenesis.Objenesis; //导入方法依赖的package包/类
private Object createUnderlyingObjectProxy(InvocationReporter invocationReporter) {
	// use Cglib Enhancer inlined in spring3.2
	// spring3.2's ProxyFactory cannot creates a proxy with constructor arguments.
	// CglibAopProxy is package scoped and cannot call "setConstructorArguments" operationMethod.
	// This is fixed in spring4 with ObjenesisCglibAopProxy: https://jira.springsource.org/browse/SPR-3150
	// for now simulate what spring4 does with cglib and objenesis.
	final Enhancer enhancer = new Enhancer();
	enhancer.setSuperclass(implClass);
	enhancer.setInterfaces(implClass.getInterfaces());

	Objenesis objenesis = new ObjenesisStd();
	Callback[] callbacks = new Callback[]{invocationReporter};
	Class<?>[] types = new Class[callbacks.length];
	for (int x = 0; x < types.length; x++) {
		types[x] = callbacks[x].getClass();
	}
	enhancer.setCallbackTypes(types);

	Object client = objenesis.newInstance(enhancer.createClass());
	((Factory) client).setCallbacks(callbacks);
	return client;
}
 
开发者ID:ttddyy,项目名称:spring-social-evernote,代码行数:23,代码来源:StoreOperationsActualInvocationTest.java

示例4: main

import org.objenesis.Objenesis; //导入方法依赖的package包/类
public static void main(String[] args) {
    Objenesis objenesis = new ObjenesisStd();
    FinalBean o = objenesis.newInstance(FinalBean.class);  // 能成功创建
    Reflect.on(o).set("name", "bingoo");
    System.out.println(o);

    // 异常:com.alibaba.fastjson.JSONException: default constructor not found. class org.n3r.sandbox.objenesis.FinalClassCreate$FinalBean
    FinalBean finalBean = JSON.parseObject("{name:\"dingoo\"}", FinalBean.class);
    System.out.println(finalBean);

}
 
开发者ID:bingoohuang,项目名称:javacode-demo,代码行数:12,代码来源:FinalClassCreate.java

示例5: create

import org.objenesis.Objenesis; //导入方法依赖的package包/类
public T create()
{
	Enhancer enhancer = new Enhancer();
	enhancer.setSuperclass(type);
	enhancer.setCallbackType(MethodInterceptor.class);
	Class<?> proxyType = enhancer.createClass();
	
	Objenesis objenesis = new ObjenesisStd();
	Factory proxy = (Factory) objenesis.newInstance(proxyType);
	proxy.setCallbacks(new Callback[] {this});
	
	return type.cast(proxy);
}
 
开发者ID:markhobson,项目名称:hamcrest-submatcher,代码行数:14,代码来源:Spy.java

示例6: isCompliant

import org.objenesis.Objenesis; //导入方法依赖的package包/类
@Override
public boolean isCompliant(Objenesis objenesis) {
   try {
      objenesis.newInstance(NotSerializable.class);
   }
   catch(ObjenesisException e) {
      return true;
   }
   return false;
}
 
开发者ID:easymock,项目名称:objenesis,代码行数:11,代码来源:NotSerializableClass.java

示例7: runCandidate

import org.objenesis.Objenesis; //导入方法依赖的package包/类
private void runCandidate(Reporter reporter, Class<?> candidate, Objenesis objenesis, Candidate.CandidateType type) {
   try {
      Object instance = objenesis.newInstance(candidate);
      boolean success = instance != null && instance.getClass() == candidate;
      reporter.result(type, success);
   }
   catch(Exception e) {
      reporter.exception(type, e);
   }
}
 
开发者ID:easymock,项目名称:objenesis,代码行数:11,代码来源:TCK.java

示例8: getFakeParameters

import org.objenesis.Objenesis; //导入方法依赖的package包/类
private Object[] getFakeParameters(Method method) {
	Objenesis objenesis = new ObjenesisStd();
	Class<?>[] paramTypes = method.getParameterTypes();
	Object[] fakeParams = new Object[paramTypes.length];
	for (int i = 0; i < paramTypes.length; i++) {
		Class<?> paramType = paramTypes[i];

		// TODO: better impl.
		Object fakeParam;
		if (ClassUtils.isPrimitiveArray(paramType)) {
			// can objenesis handle primitive array? for now, create just empty array
			fakeParam = Array.newInstance(paramType.getComponentType(), 0);
		} else {
			if (paramType.isPrimitive()) {
				paramType = ClassUtils.resolvePrimitiveIfNecessary(paramType);
			} else if (paramType.isInterface()) {
				if (paramType.isAssignableFrom(List.class)) {
					paramType = ArrayList.class;
				}
			}
			fakeParam = objenesis.newInstance(paramType);
		}
		fakeParams[i] = fakeParam;
	}

	return fakeParams;
}
 
开发者ID:ttddyy,项目名称:spring-social-evernote,代码行数:28,代码来源:StoreOperationsActualInvocationTest.java

示例9: constructInstance

import org.objenesis.Objenesis; //导入方法依赖的package包/类
private static Object constructInstance(Class<?> clazz)  {
 	/**
 	 * Use the objensis magic (like PowerMock/EasyMock) to construct an instance of a Java
 	 * object without invoking a constructor.  This is a local proxy, and it shouldn't
 	 * run code locally.  We only inherit in concrete class cases to allow a proper
 	 * programming interface in the local classloader.
 	 */
Objenesis objenesis = new ObjenesisStd();
return objenesis.newInstance(clazz);
 }
 
开发者ID:lithiumtech,项目名称:multiverse-test,代码行数:11,代码来源:FunctionalTestClassLoader.java

示例10: isCompliant

import org.objenesis.Objenesis; //导入方法依赖的package包/类
@Override
public boolean isCompliant(Objenesis objenesis) {
   objenesis.newInstance(ReadExternalAndAll.class);
   return called.isEmpty();
}
 
开发者ID:easymock,项目名称:objenesis,代码行数:6,代码来源:ReadExternalNotCalled.java

示例11: isCompliant

import org.objenesis.Objenesis; //导入方法依赖的package包/类
@Override
public boolean isCompliant(Objenesis objenesis) {
   objenesis.newInstance(ExtendsSerializable.class);
   return called.isEmpty();
}
 
开发者ID:easymock,项目名称:objenesis,代码行数:6,代码来源:ExtendsSerializableClass.java

示例12: isCompliant

import org.objenesis.Objenesis; //导入方法依赖的package包/类
@Override
public boolean isCompliant(Objenesis objenesis) {
   objenesis.newInstance(IsSerializable.class);
   return called.isEmpty();
}
 
开发者ID:easymock,项目名称:objenesis,代码行数:6,代码来源:SerializableClass.java

示例13: isCompliant

import org.objenesis.Objenesis; //导入方法依赖的package包/类
@Override
public boolean isCompliant(Objenesis objenesis) {
   objenesis.newInstance(ReadObjectAndAll.class);
   return called.isEmpty();
}
 
开发者ID:easymock,项目名称:objenesis,代码行数:6,代码来源:ReadObjectNotCalled.java

示例14: isCompliant

import org.objenesis.Objenesis; //导入方法依赖的package包/类
@Override
public boolean isCompliant(Objenesis objenesis) {
   objenesis.newInstance(ExtendsNotSerializable.class);
   return called.size() == 1 && called.get(0).equals(NotSerializableClass.NotSerializable.class.getSimpleName() + ".<init>");
}
 
开发者ID:easymock,项目名称:objenesis,代码行数:6,代码来源:ExtendsNotSerializableParentClass.java

示例15: newInstanceOf

import org.objenesis.Objenesis; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
public Object newInstanceOf(Class type) throws Exception {
    Assert.isNotNull(type);
    Objenesis objenesis = Serializable.class.isAssignableFrom(type) ? serializer : standard;
    return objenesis.newInstance(type);
}
 
开发者ID:csm,项目名称:java-sandbox,代码行数:9,代码来源:ObjenesisInstantiationStrategy.java


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