本文整理汇总了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;
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
示例10: isCompliant
import org.objenesis.Objenesis; //导入方法依赖的package包/类
@Override
public boolean isCompliant(Objenesis objenesis) {
objenesis.newInstance(ReadExternalAndAll.class);
return called.isEmpty();
}
示例11: isCompliant
import org.objenesis.Objenesis; //导入方法依赖的package包/类
@Override
public boolean isCompliant(Objenesis objenesis) {
objenesis.newInstance(ExtendsSerializable.class);
return called.isEmpty();
}
示例12: isCompliant
import org.objenesis.Objenesis; //导入方法依赖的package包/类
@Override
public boolean isCompliant(Objenesis objenesis) {
objenesis.newInstance(IsSerializable.class);
return called.isEmpty();
}
示例13: isCompliant
import org.objenesis.Objenesis; //导入方法依赖的package包/类
@Override
public boolean isCompliant(Objenesis objenesis) {
objenesis.newInstance(ReadObjectAndAll.class);
return called.isEmpty();
}
示例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>");
}
示例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);
}