org.objenesis.Objenesis Java Examples
The following examples show how to use
org.objenesis.Objenesis.
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: AbstractStoreOperationControllerIntegrationTest.java From evernote-rest-webapp with Apache License 2.0 | 6 votes |
@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 #2
Source File: CglibProxy.java From festival with Apache License 2.0 | 6 votes |
@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 #3
Source File: TCK.java From objenesis with Apache License 2.0 | 5 votes |
/** * @param objenesisStandard Objenesis instance used to instantiate classes the standard way (no constructor called) * @param objenesisSerializer Objenesis instance used to instantiate classes in a serialization compliant way (first not serializable constructor called) * @param reporter Where to report the results of the tests to */ public TCK(Objenesis objenesisStandard, Objenesis objenesisSerializer, Reporter reporter) { this.objenesisStandard = objenesisStandard; this.objenesisSerializer = objenesisSerializer; this.reporter = reporter; try { loadCandidates(); } catch(IOException e) { throw new RuntimeException(e); } Collections.sort(candidates); }
Example #4
Source File: HipchatConsumerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 5 votes |
@Deployment public static JavaArchive createDeployment() { JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "camel-hipchat-tests.jar"); archive.addPackages(true, Mockito.class.getPackage(), Objenesis.class.getPackage(), ByteBuddy.class.getPackage()); archive.addClasses(HipchatComponentSupport.class, HipchatEndpointSupport.class); return archive; }
Example #5
Source File: OsgiTest.java From objenesis with Apache License 2.0 | 5 votes |
@Configuration public Option[] config() { String version = getImplementationVersion(Objenesis.class); return options( bundle("file:../main/target/objenesis-" + version + ".jar"), junitBundles() ); }
Example #6
Source File: TCK.java From objenesis with Apache License 2.0 | 5 votes |
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); } }
Example #7
Source File: TCK.java From objenesis with Apache License 2.0 | 5 votes |
private void runFeature(Reporter reporter, Class<?> clazz, Objenesis objenesis, Candidate.CandidateType type) { try { @SuppressWarnings("unchecked") Constructor<Feature> constructor = (Constructor<Feature>) clazz.getConstructor(); Feature feature = constructor.newInstance(); boolean compliant = feature.isCompliant(objenesis); reporter.result(type, compliant); } catch(Exception e) { reporter.exception(type, e); } }
Example #8
Source File: TCK.java From objenesis with Apache License 2.0 | 5 votes |
private void runTest(Reporter reporter, Class<?> candidate, Objenesis objenesis, Candidate.CandidateType type) { if(Feature.class.isAssignableFrom(candidate)) { runFeature(reporter, candidate, objenesis, type); } else { runCandidate(reporter, candidate, objenesis, type); } }
Example #9
Source File: NotSerializableClass.java From objenesis with Apache License 2.0 | 5 votes |
@Override public boolean isCompliant(Objenesis objenesis) { try { objenesis.newInstance(NotSerializable.class); } catch(ObjenesisException e) { return true; } return false; }
Example #10
Source File: TextReporter.java From objenesis with Apache License 2.0 | 5 votes |
@Override public void startTests(String platformDescription, Objenesis objenesisStandard, Objenesis objenesisSerializer) { this.platformDescription = platformDescription; this.objenesisStandard = objenesisStandard; this.objenesisSerializer = objenesisSerializer; this.currentCandidate = null; this.errorCount = 0; this.results.clear(); this.startTime = System.currentTimeMillis(); }
Example #11
Source File: JspReporter.java From objenesis with Apache License 2.0 | 5 votes |
@Override public void startTests(String platformDescription, Objenesis objenesisStandard, Objenesis objenesisSerializer) { this.platformDescription = platformDescription; this.objenesisStandard = objenesisStandard; this.objenesisSerializer = objenesisSerializer; this.currentCandidate = null; this.errorCount = 0; this.results.clear(); this.startTime = System.currentTimeMillis(); }
Example #12
Source File: PreAnalyzeFieldsTest.java From jesterj with Apache License 2.0 | 5 votes |
@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 #13
Source File: PrinterIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Deployment public static JavaArchive deployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "camel-lpr-tests"); archive.addPackages(true, Mockito.class.getPackage(), Objenesis.class.getPackage(), ByteBuddy.class.getPackage()); return archive; }
Example #14
Source File: ExtendsSerializableClass.java From objenesis with Apache License 2.0 | 4 votes |
@Override public boolean isCompliant(Objenesis objenesis) { objenesis.newInstance(ExtendsSerializable.class); return called.isEmpty(); }
Example #15
Source File: GoogleBigQueryIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Deployment public static JavaArchive createDeployment() { return ShrinkWrap.create(JavaArchive.class, "camel-google-bigquery-tests.jar") .addPackages(true, Mockito.class.getPackage(), Objenesis.class.getPackage(), ByteBuddy.class.getPackage()); }
Example #16
Source File: BeanstalkIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Deployment public static JavaArchive createdeployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "camel-beanstalk-tests"); archive.addPackages(true, Mockito.class.getPackage(), Objenesis.class.getPackage(), ByteBuddy.class.getPackage()); return archive; }
Example #17
Source File: SolrSchemaUtil.java From jesterj with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private static <T> T create(final Class<T> classToMock) { Objenesis objenesis = new ObjenesisStd(); return objenesis.getInstantiatorOf(classToMock).newInstance(); }
Example #18
Source File: HazelcastMapProducerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Deployment public static JavaArchive deployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "hazelcast-map-producer-tests"); archive.addPackages(true, Mockito.class.getPackage(), Objenesis.class.getPackage(), ByteBuddy.class.getPackage()); return archive; }
Example #19
Source File: HazelcastMapConsumerIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Deployment public static JavaArchive deployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "hazelcast-map-consumer-tests"); archive.addPackages(true, Mockito.class.getPackage(), Objenesis.class.getPackage(), ByteBuddy.class.getPackage()); return archive; }
Example #20
Source File: NagiosIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Deployment public static JavaArchive createDeployment() { final JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "camel-nagios-test"); archive.addPackages(true, Mockito.class.getPackage(), Objenesis.class.getPackage(), ByteBuddy.class.getPackage()); return archive; }
Example #21
Source File: OpenstackIntegrationTest.java From wildfly-camel with Apache License 2.0 | 4 votes |
@Deployment public static JavaArchive createDeployment() { JavaArchive archive = ShrinkWrap.create(JavaArchive.class, "camel-openstack-tests.jar"); archive.addPackages(true, Mockito.class.getPackage(), Objenesis.class.getPackage(), ByteBuddy.class.getPackage()); return archive; }
Example #22
Source File: TCKTest.java From objenesis with Apache License 2.0 | 4 votes |
@Override public void startTests(String platformDescription, Objenesis objenesisStandard, Objenesis objenesisSerializer) { log.append("startTests()\n"); }
Example #23
Source File: TCKTest.java From objenesis with Apache License 2.0 | 4 votes |
@Override public boolean isCompliant(Objenesis objenesis) { return true; }
Example #24
Source File: TextReporterTest.java From objenesis with Apache License 2.0 | 4 votes |
@Test public void testReportsSuccessesInTabularFormat() { Objenesis instantiator1 = new ObjenesisBase(new SingleInstantiatorStrategy( ConstructorInstantiator.class)); Objenesis instantiator2 = new ObjenesisBase(new SingleInstantiatorStrategy( FailingInstantiator.class)); textReporter.startTests("Some platform", instantiator1, instantiator2); textReporter.startTest(new Candidate(TCKTest.CandidateA.class, "candidate A", Candidate.CandidateType.STANDARD, Candidate.CandidateType.SERIALIZATION)); textReporter.result(Candidate.CandidateType.STANDARD,false); textReporter.result(Candidate.CandidateType.SERIALIZATION, true); textReporter.startTest(new Candidate(TCKTest.CandidateB.class, "candidate B", Candidate.CandidateType.STANDARD)); textReporter.result(Candidate.CandidateType.STANDARD,true); textReporter.startTest(new Candidate(TCKTest.CandidateC.class,"candidate C", Candidate.CandidateType.STANDARD, Candidate.CandidateType.SERIALIZATION)); textReporter.exception(Candidate.CandidateType.STANDARD, new RuntimeException("Problem")); textReporter.result(Candidate.CandidateType.SERIALIZATION, false); textReporter.startTest(new Candidate(TCKTest.CandidateD.class,"candidate D", Candidate.CandidateType.SERIALIZATION)); textReporter.result(Candidate.CandidateType.SERIALIZATION, true); textReporter.endTests(); ByteArrayOutputStream expectedSummaryBuffer = new ByteArrayOutputStream(); PrintStream out = new PrintStream(expectedSummaryBuffer); out.println("Running TCK on platform: Some platform"); out.println(); out.println("Instantiators used: "); out.println(" Objenesis standard : org.objenesis.instantiator.basic.ConstructorInstantiator"); out.println(" Objenesis serializer: org.objenesis.instantiator.basic.FailingInstantiator"); out.println(); out.println(" Objenesis standard Objenesis serializer"); out.println("candidate A n Y "); out.println("candidate B Y N/A "); out.println("candidate C n n "); out.println("candidate D N/A Y "); out.println(); out.println("--- FAILED: 3 error(s) occurred ---"); out.println(); assertEquals(expectedSummaryBuffer.toString(), summaryBuffer.toString()); }
Example #25
Source File: ObjenesisTest.java From objenesis with Apache License 2.0 | 4 votes |
@Override public void startTests(String platformDescription, Objenesis objenesisStandard, Objenesis objenesisSerializer) { }
Example #26
Source File: ObjenesisTest.java From objenesis with Apache License 2.0 | 4 votes |
@Override public void startTests(String platformDescription, Objenesis objenesisStandard, Objenesis objenesisSerializer) { }
Example #27
Source File: ClassDefinitionUtilsTest.java From objenesis with Apache License 2.0 | 4 votes |
@Test public void testDefineClass() throws Exception { byte[] b = ClassDefinitionUtils.readClass(className); Class<?> c = ClassDefinitionUtils.defineClass(className, b, Objenesis.class, getClass().getClassLoader()); assertEquals(c.getName(), className); }
Example #28
Source File: ExtendsNotSerializableParentClass.java From objenesis with Apache License 2.0 | 4 votes |
@Override public boolean isCompliant(Objenesis objenesis) { objenesis.newInstance(ExtendsNotSerializable.class); return called.size() == 1 && called.get(0).equals(NotSerializableClass.NotSerializable.class.getSimpleName() + ".<init>"); }
Example #29
Source File: ReadObjectNotCalled.java From objenesis with Apache License 2.0 | 4 votes |
@Override public boolean isCompliant(Objenesis objenesis) { objenesis.newInstance(ReadObjectAndAll.class); return called.isEmpty(); }
Example #30
Source File: SerializableClass.java From objenesis with Apache License 2.0 | 4 votes |
@Override public boolean isCompliant(Objenesis objenesis) { objenesis.newInstance(IsSerializable.class); return called.isEmpty(); }