本文整理匯總了Java中org.objenesis.ObjenesisStd類的典型用法代碼示例。如果您正苦於以下問題:Java ObjenesisStd類的具體用法?Java ObjenesisStd怎麽用?Java ObjenesisStd使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ObjenesisStd類屬於org.objenesis包,在下文中一共展示了ObjenesisStd類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getClient
import org.objenesis.ObjenesisStd; //導入依賴的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: createTestJar
import org.objenesis.ObjenesisStd; //導入依賴的package包/類
/**
* Creates the JAR file containing the test infrastructure.
*
* @return The jar file.
*/
private static JavaArchive createTestJar() {
JavaArchive testJar = ShrinkWrap.create(JavaArchive.class,
TEST_JAR_NAME);
// add resources
if (TEST_RESOURCES_DIRECTORY.exists()) {
ResourceUtils.addResources(testJar, TEST_RESOURCES_DIRECTORY,
new ResourceFilterForSuffixExclusion(
DEPLOYMENT_STRUCTURE_FILE));
}
// add common test class to the test.jar
testJar.addClass(AbstractArquillianTest.class);
testJar.addClass(AbstractServerTest.class);
// add Mockito
testJar.addPackages(true, Mockito.class.getPackage());
testJar.addPackages(true, ObjenesisStd.class.getPackage());
testJar.addPackage(Mock.class.getPackage());
// add CDI extension descriptors
addServices(testJar, Extension.class);
return testJar;
}
示例3: newInstance
import org.objenesis.ObjenesisStd; //導入依賴的package包/類
/**
* Create a new instance of a class without invoking its constructor.
* <p>
* No byte-code manipulation is needed to perform this operation and thus
* it's not necessary use the <code>PowerMockRunner</code> or
* <code>PrepareForTest</code> annotation to use this functionality.
*
* @param <T>
* The type of the instance to create.
* @param classToInstantiate
* The type of the instance to create.
* @return A new instance of type T, created without invoking the
* constructor.
*/
@SuppressWarnings("unchecked")
public static <T> T newInstance(Class<T> classToInstantiate) {
int modifiers = classToInstantiate.getModifiers();
final Object object;
if (Modifier.isInterface(modifiers)) {
object = Proxy.newProxyInstance(WhiteboxImpl.class.getClassLoader(), new Class<?>[] { classToInstantiate },
new InvocationHandler() {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
return TypeUtils.getDefaultValue(method.getReturnType());
}
});
} else if (classToInstantiate.isArray()) {
object = Array.newInstance(classToInstantiate.getComponentType(), 0);
} else if (Modifier.isAbstract(modifiers)) {
throw new IllegalArgumentException(
"Cannot instantiate an abstract class. Please use the ConcreteClassGenerator in PowerMock support to generate a concrete class first.");
} else {
Objenesis objenesis = new ObjenesisStd();
ObjectInstantiator thingyInstantiator = objenesis.getInstantiatorOf(classToInstantiate);
object = thingyInstantiator.newInstance();
}
return (T) object;
}
示例4: asmTypeValidateGeneratorSupport
import org.objenesis.ObjenesisStd; //導入依賴的package包/類
private static boolean asmTypeValidateGeneratorSupport(
AsmConstraint asmConstraint, Class<?> type
) {
ObjenesisStd objStd = new ObjenesisStd();
for (val asmValidateBy : asmConstraint.asmValidateBy()) {
val clazz = AsmTypeValidateGenerator.class;
if (!clazz.isAssignableFrom(asmValidateBy)) {
continue;
}
val generator = (AsmTypeValidateGenerator) objStd.newInstance(asmValidateBy);
if (generator.supportClass(type)) {
return true;
}
}
return false;
}
示例5: create
import org.objenesis.ObjenesisStd; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public <T> T create(Class<T> clazz, String widgetId) {
// creating proxy class
Enhancer enhancer = new Enhancer();
enhancer.setSuperclass(clazz);
enhancer.setUseFactory(true);
enhancer.setCallbackType(RemoteObjectMethodInterceptor.class);
if (clazz.getSigners() != null) {
enhancer.setNamingPolicy(NAMING_POLICY_FOR_CLASSES_IN_SIGNED_PACKAGES);
}
Class<?> proxyClass = enhancer.createClass();
// instantiating class without constructor call
ObjenesisStd objenesis = new ObjenesisStd();
Factory proxy = (Factory) objenesis.newInstance(proxyClass);
proxy.setCallbacks(new Callback[]{new RemoteObjectMethodInterceptor(this, invoker, widgetId)});
T widget = (T) proxy;
widgetIds.put(widget, widgetId);
return widget;
}
示例6: setup
import org.objenesis.ObjenesisStd; //導入依賴的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
示例7: createUnderlyingObjectProxy
import org.objenesis.ObjenesisStd; //導入依賴的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;
}
示例8: setupProxy
import org.objenesis.ObjenesisStd; //導入依賴的package包/類
private void setupProxy(GitClient gitClient)
throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException
{
final String proxyHost = getSystemProperty("proxyHost", "http.proxyHost", "https.proxyHost");
final String proxyPort = getSystemProperty("proxyPort", "http.proxyPort", "https.proxyPort");
final String proxyUser = getSystemProperty("proxyUser", "http.proxyUser", "https.proxyUser");
//final String proxyPassword = getSystemProperty("proxyPassword", "http.proxyPassword", "https.proxyPassword");
final String noProxyHosts = getSystemProperty("noProxyHosts", "http.noProxyHosts", "https.noProxyHosts");
if(isBlank(proxyHost) || isBlank(proxyPort)) return;
ProxyConfiguration proxyConfig = new ObjenesisStd().newInstance(ProxyConfiguration.class);
setField(ProxyConfiguration.class, "name", proxyConfig, proxyHost);
setField(ProxyConfiguration.class, "port", proxyConfig, Integer.parseInt(proxyPort));
setField(ProxyConfiguration.class, "userName", proxyConfig, proxyUser);
setField(ProxyConfiguration.class, "noProxyHost", proxyConfig, noProxyHosts);
//Password does not work since a set password results in a "Secret" call which expects a running Jenkins
setField(ProxyConfiguration.class, "password", proxyConfig, null);
setField(ProxyConfiguration.class, "secretPassword", proxyConfig, null);
gitClient.setProxy(proxyConfig);
}
示例9: newProxyByCglib
import org.objenesis.ObjenesisStd; //導入依賴的package包/類
private static Object newProxyByCglib(Typing typing, Handler handler) {
Enhancer enhancer = new Enhancer() {
/** includes all constructors */
protected void filterConstructors(Class sc, List constructors) {}
};
enhancer.setClassLoader(Thread.currentThread().getContextClassLoader());
enhancer.setUseFactory(true);
enhancer.setSuperclass(typing.superclass);
enhancer.setInterfaces(typing.interfaces.toArray(new Class[0]));
enhancer.setCallbackTypes(new Class[] { MethodInterceptor.class, NoOp.class });
enhancer.setCallbackFilter(new CallbackFilter() {
/** ignores bridge methods */
public int accept(Method method) {
return method.isBridge() ? 1 : 0;
}
});
Class<?> proxyClass = enhancer.createClass();
Factory proxy = (Factory) new ObjenesisStd().newInstance(proxyClass);
proxy.setCallbacks(new Callback[] { asMethodInterceptor(handler), new SerializableNoOp() });
return proxy;
}
示例10: newInstance
import org.objenesis.ObjenesisStd; //導入依賴的package包/類
public static <T> T newInstance(Class<T> type) {
try {
return type.newInstance();
} catch (Exception e) {
return new ObjenesisStd().newInstance(type);
}
}
示例11: main
import org.objenesis.ObjenesisStd; //導入依賴的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);
}
示例12: asmCreate
import org.objenesis.ObjenesisStd; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private AsmValidator<Object> asmCreate(Class<?> beanClass) {
val generator = new AsmValidatorClassGenerator(beanClass);
val asmValidatorClass = generator.generate();
val objenesisStd = new ObjenesisStd();
val asmValidator = objenesisStd.newInstance(asmValidatorClass);
return (AsmValidator<Object>) asmValidator;
}
示例13: asmCreate
import org.objenesis.ObjenesisStd; //導入依賴的package包/類
@SuppressWarnings("unchecked")
private static AsmValidator<Object> asmCreate(Method method, int parameterIndex) {
val generator = new AsmParamValidatorClassGenerator(method, parameterIndex);
val asmValidatorClass = generator.generate();
val objenesisStd = new ObjenesisStd();
val asmValidator = objenesisStd.newInstance(asmValidatorClass);
return (AsmValidator<Object>) asmValidator;
}
示例14: AlchemyRestClientFactory
import org.objenesis.ObjenesisStd; //導入依賴的package包/類
/**
* Creates the new factory.
*
* @param baseUri
* the base URI for the rest service.
* @param clientProvider
* the {@link Client} provider.
* @param interfaceAnalyzer
* the interface analyzer.
*/
@Inject
public AlchemyRestClientFactory(@Named(BASE_URI_NAMED_PARAM) final String baseUri,
final Provider<Client> clientProvider, final RestInterfaceAnalyzer interfaceAnalyzer,
final ResponseToThrowableMapper responseToThrowableMapper,
final RequestBuilderFilter builderFilter) {
this.baseUri = baseUri;
this.clientProvider = clientProvider;
this.interfaceAnalyzer = interfaceAnalyzer;
this.objenesis = new ObjenesisStd();
this.responseToThrowableMapper = responseToThrowableMapper;
this.builderFilter = builderFilter;
}
示例15: create
import org.objenesis.ObjenesisStd; //導入依賴的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);
}