org.objenesis.ObjenesisStd Java Examples

The following examples show how to use org.objenesis.ObjenesisStd. 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: CglibProxy.java    From festival with Apache License 2.0 6 votes vote down vote up
@Override
public Object getProxy(ClassLoader classLoader) {
    Enhancer enhancer = new Enhancer();
    enhancer.setClassLoader(classLoader);
    enhancer.setCallbackType(MethodInterceptor.class);

    Class<?> targetClass = support.getBeanClass();
    enhancer.setSuperclass(targetClass);
    enhancer.setInterfaces(new Class[]{FestivalProxy.class, TargetClassAware.class});
    Class<?> proxyClass = enhancer.createClass();

    Objenesis objenesis = new ObjenesisStd();
    ObjectInstantiator<?> instantiator = objenesis.getInstantiatorOf(proxyClass);
    Object proxyInstance = instantiator.newInstance();

    ((Factory) proxyInstance).setCallbacks(new Callback[]{new CglibMethodInterceptor(support)});

    return proxyInstance;
}
 
Example #2
Source File: AbstractStoreOperationControllerIntegrationTest.java    From evernote-rest-webapp with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #3
Source File: GitAPITestCase.java    From git-client-plugin with MIT License 6 votes vote down vote up
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);
}
 
Example #4
Source File: ClassLayout.java    From pulsar with Apache License 2.0 5 votes vote down vote up
public static ClassLayout parseClass(Class<?> clazz) {
    long size = DEFAULT_SIZE;
    try {
        size = ObjectSizeCalculator.getObjectSize(new ObjenesisStd().newInstance(clazz));
    } catch (Throwable th) {
        log.info("Error estimating size of class %s",clazz, th);
    }
    return new ClassLayout(Math.toIntExact(size));
}
 
Example #5
Source File: PreAnalyzeFieldsTest.java    From jesterj with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void throwAway() {
  log.info("BEFORE_CLASS BEGINS");
  // this is just ot keep checkClusterConfiguration happy... actually better to do this per-test
  // to avoid cross talk between tests (see SOLR-12801 test revamp in solr)
  // future versions of solr won't require this....
  Objenesis objenesis = new ObjenesisStd();
  ObjectInstantiator<MiniSolrCloudCluster> instantiatorOf = objenesis.getInstantiatorOf(MiniSolrCloudCluster.class);
  cluster = instantiatorOf.newInstance();
  log.info("BEFORE_CLASS ENDSS");
}
 
Example #6
Source File: ReflectionUtils.java    From easy-random with MIT License 5 votes vote down vote up
/**
 * Create an empty collection for the given type.
 * @param fieldType for which an empty collection should we created
 * @param initialSize initial size of the collection
 * @return empty collection
 */
public static Collection<?> createEmptyCollectionForType(Class<?> fieldType, int initialSize) {
    rejectUnsupportedTypes(fieldType);
    Collection<?> collection;
    try {
        collection = (Collection<?>) fieldType.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        if (fieldType.equals(ArrayBlockingQueue.class)) {
            collection = new ArrayBlockingQueue<>(initialSize);
        } else {
            collection = (Collection<?>) new ObjenesisStd().newInstance(fieldType);
        }
    }
    return collection;
}
 
Example #7
Source File: VoxelGamesLib.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
@Override
public void onEnable() {
    try {
        // logging first, only changes prefixes anyways
        loggingHandler = new LoggingHandler();
        loggingHandler.setErrorHandler(errorHandler);
        loggingHandler.enable();
        // enable by enabling external stuff. they don't require any VGL stuff

        // timings
        timingManager = TimingManager.of(this);

        // commands
        commandManager = new BukkitCommandManager(this);
        commandManager.setDefaultExceptionHandler((scope, registeredCommand, sender, args, t) -> {
            errorHandler.handle(sender, args, t);
            return false;
        });
        // living on the edge!
        commandManager.enableUnstableAPI("help");

        // task chain
        taskChainFactory = BukkitTaskChainFactory.create(this);
        taskChainFactory.setDefaultErrorHandler((e, t) -> {
            log.severe("Task " + t.hashCode() + " generated an exception:");
            e.printStackTrace();
        });

        // chat menu api
        ChatMenuAPI.init(this);

        // menu builder (excuse the hack, but we want to shade you)
        MenuBuilderPlugin menuBuilderPluginFake = new ObjenesisStd().getInstantiatorOf(MenuBuilderPlugin.class).newInstance();
        menuBuilderPluginFake.inventoryListener = new InventoryListener(menuBuilderPluginFake);
        MenuBuilderPlugin.instance = menuBuilderPluginFake;
        Bukkit.getPluginManager().registerEvents(menuBuilderPluginFake.inventoryListener, this);

        // guice
        VoxelGamesLibModule module = new VoxelGamesLibModule(this, loggingHandler, timingManager,
                commandManager, getVersion(), getDataFolder(), ModuleHandler.getOfferedModules(), errorHandler);
        injector = module.createInjector();
        injector.injectMembers(this);

        // startup handler
        startupHandler.registerService("onEnable");
        Bukkit.getPluginManager().registerEvents(injector.getInstance(StartupListener.class), this);

        // then enable all VGL stuff
        try (final Timing timing = new Timing("EnableAllHandlers")) {
            eventHandler.enable();
            configHandler.enable();
            persistenceHandler.enable();
            langHandler.enable();
            tickHandler.enable();
            chatHandler.enable();
            userHandler.enable();
            roleHandler.enable();
            mapHandler.enable();
            worldHandler.enable();
            teamHandler.enable();
            eloHandler.enable();
            matchmakingHandler.enable();
            signHandler.enable();
            metricHandler.enable();
            pointHandler.enable();
            kitHandler.enable();
            commandHandler.enable();
            textureHandler.enable();
            statsHandler.enable();

            gameHandler.enable();
        }

        registerListeners();
    } catch (Exception ex) {
        errorHandler.handle(ex, Severity.ERROR, true);
        startupHandler.interrupt();
        return;
    }

    // register commands
    registerCommandContexts();
    registerCommandReplacements();
    registerCommands();
    registerCommandCompletions();

    moduleHandler.enable();

    gameHandler.startDefaultGame();

    getServer().getPluginManager().callEvent(new VoxelGamesLibEnableEvent());

    testStuff.test();

    startupHandler.unregisterService("onEnable");

    enabledCleanly = true;
}
 
Example #8
Source File: SolrSchemaUtil.java    From jesterj with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unchecked")
private static <T> T create(final Class<T> classToMock) {
  Objenesis objenesis = new ObjenesisStd();
  return objenesis.getInstantiatorOf(classToMock).newInstance();
}
 
Example #9
Source File: CustomMorphiaObjectFactory.java    From DotCi with MIT License 4 votes vote down vote up
public CustomMorphiaObjectFactory(final ClassLoader classloader) {
    this.objenesis = new ObjenesisStd();
    this.classloader = classloader;
}
 
Example #10
Source File: ObjenesisTest.java    From objenesis with Apache License 2.0 4 votes vote down vote up
@SmallTest
public void testObjenesis() throws Exception {
   TCK tck = new TCK(new ObjenesisStd(), new ObjenesisSerializer(), new JUnitReporter());
   tck.runTests();
}
 
Example #11
Source File: ObjenesisTest.java    From objenesis with Apache License 2.0 4 votes vote down vote up
@Test
public void test() {
   TCK tck = new TCK(new ObjenesisStd(), new ObjenesisSerializer(), new JUnitReporter());
   tck.runTests();
}
 
Example #12
Source File: Main.java    From objenesis with Apache License 2.0 2 votes vote down vote up
/**
 * Run the full test suite using standard Objenesis instances
 *
 * @param reporter result are recorded in the reporter
 */
public static void run(Reporter reporter) {
   TCK tck = new TCK(new ObjenesisStd(), new ObjenesisSerializer(), reporter);
   tck.runTests();
}