org.objenesis.ObjenesisHelper Java Examples
The following examples show how to use
org.objenesis.ObjenesisHelper.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImmutableProxy.java From reflection-util with Apache License 2.0 | 5 votes |
public static <T> T create(T instance) { if (isImmutable(instance)) { return instance; } Class<? extends T> proxyClass = getOrCreateProxyClass(instance); T proxy = ObjenesisHelper.newInstance(proxyClass); PropertyUtils.writeDirectly(proxy, DELEGATE_FIELD_NAME, instance); return proxy; }
Example #2
Source File: PropertyUtils.java From reflection-util with Apache License 2.0 | 5 votes |
private static <T> T createProxy(Class<T> beanClass, MethodCaptor methodCaptor) { Class<? extends T> proxyClass = getCache(beanClass).getMethodCapturingProxy(); try { T proxyInstance = ObjenesisHelper.newInstance(proxyClass); writeDirectly(proxyInstance, MethodCaptor.FIELD_NAME, methodCaptor); return proxyInstance; } catch (IllegalAccessError e) { throw new ReflectionRuntimeException("Failed to create proxy on " + beanClass, e); } }
Example #3
Source File: ClonesArguments.java From astor with GNU General Public License v2.0 | 5 votes |
public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); for (int i = 0; i < arguments.length; i++) { Object from = arguments[i]; Object newInstance = ObjenesisHelper.newInstance(from.getClass()); new LenientCopyTool().copyToRealObject(from, newInstance); arguments[i] = newInstance; } return new ReturnsEmptyValues().answer(invocation); }
Example #4
Source File: ClonesArguments.java From astor with GNU General Public License v2.0 | 5 votes |
public Object answer(InvocationOnMock invocation) throws Throwable { Object[] arguments = invocation.getArguments(); for (int i = 0; i < arguments.length; i++) { Object from = arguments[i]; Object newInstance = ObjenesisHelper.newInstance(from.getClass()); new LenientCopyTool().copyToRealObject(from, newInstance); arguments[i] = newInstance; } return new ReturnsEmptyValues().answer(invocation); }
Example #5
Source File: ThrowsExceptionClass.java From astor with GNU General Public License v2.0 | 5 votes |
public Object answer(InvocationOnMock invocation) throws Throwable { Throwable throwable = (Throwable) ObjenesisHelper.newInstance(throwableClass); throwable.fillInStackTrace(); filter.filter(throwable); throw throwable; }
Example #6
Source File: InterceptableProxyFactory.java From proxy with MIT License | 4 votes |
private <T> T createProxyWithObjenesis() { Object obj = ObjenesisHelper.newInstance(factory.createClass()); ((ProxyObject) obj).setHandler(new JavassistInterceptorMethodHandler()); return (T) obj; }
Example #7
Source File: ClassesTest.java From Skript with GNU General Public License v3.0 | 4 votes |
@SuppressWarnings({"resource", "deprecation"}) @Before public void before() throws Exception { final File dataDir = new File("build/resources/"); final File jar = new File("build/", "skript.jar"); assumeTrue(jar.exists()); final Logger l = Logger.getLogger(getClass().getCanonicalName()); l.setParent(SkriptLogger.LOGGER); l.setLevel(Level.WARNING); final Server s = createMock(Server.class); s.getLogger(); expectLastCall().andReturn(l).anyTimes(); s.isPrimaryThread(); expectLastCall().andReturn(true).anyTimes(); s.getName(); expectLastCall().andReturn("Whatever").anyTimes(); s.getVersion(); expectLastCall().andReturn("2.0").anyTimes(); s.getBukkitVersion(); expectLastCall().andReturn("2.0").anyTimes(); replay(s); Bukkit.setServer(s); final Skript skript = (Skript) ObjenesisHelper.newInstance(Skript.class); // bypass the class loader check final Field instance = Skript.class.getDeclaredField("instance"); instance.setAccessible(true); instance.set(null, skript); final PluginDescriptionFile pdf = new PluginDescriptionFile(new FileInputStream(new File(dataDir, "plugin.yml"))); // final void init(PluginLoader loader, Server server, PluginDescriptionFile description, File dataFolder, File file, ClassLoader classLoader) { final Method init = JavaPlugin.class.getDeclaredMethod("init", PluginLoader.class, Server.class, PluginDescriptionFile.class, File.class, File.class, ClassLoader.class); init.setAccessible(true); init.invoke(skript, new JavaPluginLoader(s), s, pdf, dataDir, jar, getClass().getClassLoader()); Skript.getAddonInstance().loadClasses("ch.njol.skript", "entity"); new JavaClasses(); new BukkitClasses(); new BukkitEventValues(); new SkriptClasses(); final Field r = Skript.class.getDeclaredField("acceptRegistrations"); r.setAccessible(true); r.set(null, false); Classes.onRegistrationsStop(); }
Example #8
Source File: OsgiTest.java From objenesis with Apache License 2.0 | 4 votes |
@Test public void testCanInstantiate() { assertSame(OsgiTest.class, ObjenesisHelper.newInstance(getClass()).getClass()); }
Example #9
Source File: OsgiTest.java From objenesis with Apache License 2.0 | 4 votes |
@Test public void testCanInstantiateSerialize() { assertSame(OsgiTest.class, ObjenesisHelper.newSerializableInstance(getClass()).getClass()); }