當前位置: 首頁>>代碼示例>>Java>>正文


Java ObjenesisStd類代碼示例

本文整理匯總了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;
}
 
開發者ID:Parabot,項目名稱:Parabot-317-API-Minified-OS-Scape,代碼行數:14,代碼來源:Loader.java

示例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;
}
 
開發者ID:PureSolTechnologies,項目名稱:Purifinity,代碼行數:28,代碼來源:AbstractServerTest.java

示例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;
}
 
開發者ID:awenblue,項目名稱:powermock,代碼行數:39,代碼來源:WhiteboxImpl.java

示例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;
}
 
開發者ID:bingoohuang,項目名稱:asmvalidator,代碼行數:19,代碼來源:MethodGeneratorUtils.java

示例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;
}
 
開發者ID:sterodium,項目名稱:sterodium-rmi,代碼行數:23,代碼來源:RemoteObjectProxyFactory.java

示例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;
}
 
開發者ID:ttddyy,項目名稱:spring-social-evernote,代碼行數:23,代碼來源:StoreOperationsActualInvocationTest.java

示例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);
}
 
開發者ID:jenkinsci,項目名稱:git-client-plugin,代碼行數:20,代碼來源:GitAPITestCase.java

示例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;
}
 
開發者ID:maciejmikosik,項目名稱:testory,代碼行數:22,代碼來源:CglibProxer.java

示例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);
    }
}
 
開發者ID:dizitart,項目名稱:nitrite-database,代碼行數:8,代碼來源:ObjectUtils.java

示例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);

}
 
開發者ID:bingoohuang,項目名稱:javacode-demo,代碼行數:12,代碼來源:FinalClassCreate.java

示例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;
}
 
開發者ID:bingoohuang,項目名稱:asmvalidator,代碼行數:11,代碼來源:AsmValidatorFactory.java

示例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;
}
 
開發者ID:bingoohuang,項目名稱:asmvalidator,代碼行數:11,代碼來源:AsmParamsValidatorFactory.java

示例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;
}
 
開發者ID:strandls,項目名稱:alchemy-rest-client-generator,代碼行數:23,代碼來源:AlchemyRestClientFactory.java

示例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);
}
 
開發者ID:markhobson,項目名稱:hamcrest-submatcher,代碼行數:14,代碼來源:Spy.java


注:本文中的org.objenesis.ObjenesisStd類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。