Java Code Examples for com.openpojo.reflection.impl.PojoClassFactory#getPojoClass()
The following examples show how to use
com.openpojo.reflection.impl.PojoClassFactory#getPojoClass() .
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: ClassReaderFactoryTest.java From openpojo with Apache License 2.0 | 6 votes |
@Test(expected = UnsupportedOperationException.class) public void shouldNotBeAbleToConstruct() { try { PojoClass pojoClass = PojoClassFactory.getPojoClass(ClassReaderFactory.class); org.testng.Assert.assertEquals(1, pojoClass.getPojoConstructors().size()); InstanceFactory.getLeastCompleteInstance(pojoClass); } catch (ReflectionException re) { Throwable cause = re.getCause(); while (cause != null) { if (cause instanceof UnsupportedOperationException) throw (UnsupportedOperationException) cause; cause = cause.getCause(); } } Assert.fail("Should have not been able to construct"); }
Example 2
Source File: ClassUtilTest.java From openpojo with Apache License 2.0 | 6 votes |
@Test(expected = UnsupportedOperationException.class) public void shouldNotBeAbleToConstruct() { try { PojoClass classUtilPojoClass = PojoClassFactory.getPojoClass(ClassUtil.class); Assert.assertEquals(1, classUtilPojoClass.getPojoConstructors().size()); InstanceFactory.getLeastCompleteInstance(classUtilPojoClass); } catch (ReflectionException re) { Throwable cause = re.getCause(); while (cause != null) { if (cause instanceof UnsupportedOperationException) throw (UnsupportedOperationException) cause; cause = cause.getCause(); } } Assert.fail("Should have not been able to construct"); }
Example 3
Source File: IssueTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void testBooleanVariations() { PojoClass pojoClass = PojoClassFactory.getPojoClass(ClassWithBooleanFields.class); Affirm.affirmEquals("Fields must be 4", 4, pojoClass.getPojoFields().size()); int countOfbooleans = 0; int countOfBooleans = 0; for (PojoField pojoField : pojoClass.getPojoFields()) { if (pojoField.isPrimitive() && pojoField.getType() == boolean.class) { countOfbooleans++; } if (!pojoField.isPrimitive() && pojoField.getType() == Boolean.class) { countOfBooleans++; } } Affirm.affirmEquals("2 boolean fields must exist", 2, countOfbooleans); Affirm.affirmEquals("2 Boolean fields must exist", 2, countOfBooleans); Validator pojoValidator = ValidatorBuilder.create() .with(new GetterMustExistRule()) .with(new SetterMustExistRule()) .with(new GetterTester()) .with(new SetterTester()) .build(); pojoValidator.validate(pojoClass); }
Example 4
Source File: ByteCodeFactoryTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void givenAnAbstractClassWithConstructorShouldConstruct() { PojoClass pojoClass = PojoClassFactory.getPojoClass(AnAbstractClassWithConstructor.class); Class<?> subClass = getSubClass(pojoClass.getClazz()); assertIsConcreteAndConstructable(subClass); }
Example 5
Source File: EqualsAndHashCodeMatchRuleTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void shouldPassWhenEqualsAndHashCodeAreImplemented() { PojoClass aClassImplementingEqualsAndHashcode = PojoClassFactory.getPojoClass(AClassImplementingEqualsAndHashCode.class); List<PojoMethod> methods = aClassImplementingEqualsAndHashcode.getPojoMethods(); Assert.assertEquals(3, methods.size()); boolean constructorFound = false; boolean equalsFound = false; boolean hashCodeFound = false; for (PojoMethod method : methods) { if (method.isConstructor()) constructorFound = true; if (method.getName().equals("hashCode") && method.getPojoParameters().size() == 0 && method.getReturnType().equals(int.class)) hashCodeFound = true; if (method.getName().equals("equals") && method.getPojoParameters().size() == 1 && method.getReturnType().equals(boolean.class)) equalsFound = true; } Assert.assertTrue("Constructor not found", constructorFound); Assert.assertTrue("Equals not found", equalsFound); Assert.assertTrue("hashCode not found", hashCodeFound); rule.evaluate(aClassImplementingEqualsAndHashcode); }
Example 6
Source File: ASMServiceEnd2EndTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void shouldInvokeUsingConstructorArgs() { final Class<AbstractClassWithConstructorArgs> type = AbstractClassWithConstructorArgs.class; PojoClass pojoClass = PojoClassFactory.getPojoClass(type); assertThat(pojoClass.isAbstract(), is(true)); assertThat(pojoClass.getPojoConstructors().size(), is(1)); final List<PojoParameter> constructorParameters = pojoClass.getPojoConstructors().get(0).getPojoParameters(); assertThat(constructorParameters .size(), is(12)); int index = 0; assertType(constructorParameters.get(index++).getType(), String.class); assertType(constructorParameters.get(index++).getType(), boolean.class); assertType(constructorParameters.get(index++).getType(), byte.class); assertType(constructorParameters.get(index++).getType(), char.class); assertType(constructorParameters.get(index++).getType(), double.class); assertType(constructorParameters.get(index++).getType(), float.class); assertType(constructorParameters.get(index++).getType(), int.class); assertType(constructorParameters.get(index++).getType(), long.class); assertType(constructorParameters.get(index++).getType(), short.class); assertType(constructorParameters.get(index++).getType(), int[].class); assertType(constructorParameters.get(index++).getType(), String[].class); assertType(constructorParameters.get(index).getType(), List.class); AbstractClassWithConstructorArgs ap = getRandomValue(type); assertThat(ap, notNullValue()); }
Example 7
Source File: SerializableTesterTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void shouldNotFailIfNonSerializableIsTransient() { Class clazz = SerializableTest_SerializableWithTransientNonSerializableField.class; PojoClass pojoClass = PojoClassFactory.getPojoClass(clazz); serializableTester.run(pojoClass); }
Example 8
Source File: ValidationHelperTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void testIsStaticFinal() { PojoClass pojoClass = PojoClassFactory.getPojoClass(StaticFinalData.class); List<PojoField> pojoFields = pojoClass.getPojoFields(); Assert.assertEquals(4, pojoFields.size()); for (PojoField fieldEntry : pojoFields) { if (fieldEntry.getName().equals("staticAndNotFinal")) { Assert.assertTrue("Static and not Final test failed!!", fieldEntry.isStatic() && !fieldEntry.isFinal() && !ValidationHelper.isStaticFinal(fieldEntry)); } if (fieldEntry.getName().equals("notStaticAndNotFinal")) { Assert.assertTrue("Not static OR final test failed!!", !fieldEntry.isStatic() && !fieldEntry.isFinal() && !ValidationHelper.isStaticFinal(fieldEntry)); } if (fieldEntry.getName().equals("STATIC_AND_FINAL")) { Assert.assertTrue("Static AND Final test failed!!!", fieldEntry.isStatic() && fieldEntry.isFinal() && ValidationHelper.isStaticFinal(fieldEntry)); } if (fieldEntry.getName().equals("finalAndNotStatic")) { Assert.assertTrue("Final and not Static test failed!!", !fieldEntry.isStatic() && fieldEntry.isFinal() && !ValidationHelper.isStaticFinal(fieldEntry)); } } }
Example 9
Source File: EnumRandomGenerator.java From openpojo with Apache License 2.0 | 5 votes |
public Object doGenerate(final Class<?> type) { final PojoClass pojoClass = PojoClassFactory.getPojoClass(type); final Enum<?>[] values = getValues(pojoClass); if (values.length == 0) throw RandomGeneratorException.getInstance("Can't generate random value for Enum class [" + type + "] enum doesn't " + "define any values"); return values[RANDOM.nextInt(values.length)]; }
Example 10
Source File: NoFieldShadowingRuleTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void ensureAChildWithFieldShadowingIsAccurateWW() { PojoClass aChildWithFieldShadowing = PojoClassFactory.getPojoClass(NoShadowAChildWithFieldShadowing.class); List<PojoField> pojoFields = aChildWithFieldShadowing.getPojoFields(); Assert.assertThat(pojoFields.size(), is(1)); Assert.assertThat(pojoFields.get(0).getName(), is("aField")); }
Example 11
Source File: CollectionRandomGeneratorTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void exhaustiveTest() { PojoClass pojoClass = PojoClassFactory.getPojoClass(AClassWithExhaustiveCollection.class); Validator pojoValidator = ValidatorBuilder.create() .with(new SetterMustExistRule()) .with(new SetterTester()) .build(); pojoValidator.validate(pojoClass); }
Example 12
Source File: PrincipalNameRandomGenerator.java From openpojo with Apache License 2.0 | 5 votes |
public Object doGenerate(Class<?> type) { try { PojoClass pojoClass = PojoClassFactory.getPojoClass(principalNameClass); return InstanceFactory.getInstance(pojoClass, getPrincipleParsableString()); } catch (Exception e) { throw RandomGeneratorException.getInstance("Failed to generate " + TYPE + " instance.", e); } }
Example 13
Source File: ByteCodeFactoryTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void givenAnAbstractClassWithGenericConstructorShouldConstruct() { PojoClass pojoClass = PojoClassFactory.getPojoClass(AnAbstractClassWithGenericConstructor.class); Class<?> subClass = getSubClass(pojoClass.getClazz()); assertIsConcreteAndConstructable(subClass); }
Example 14
Source File: LoggingTesterTest.java From openpojo with Apache License 2.0 | 4 votes |
private PojoField getPojoField() { PojoClass pojoClass = PojoClassFactory.getPojoClass(sampleClass); return pojoClass.getPojoFields().get(0); }
Example 15
Source File: PrincipalNameRandomGeneratorTest.java From openpojo with Apache License 2.0 | 4 votes |
protected PojoClass getPojoClass() { return PojoClassFactory.getPojoClass(PrincipalNameRandomGenerator.class); }
Example 16
Source File: PojoTestBase.java From spring-batch-lightmin with Apache License 2.0 | 4 votes |
protected void testStructureAndBehavior(final Class<?> clazz) { final PojoClass pojoClass = PojoClassFactory.getPojoClass(clazz); this.pojoValidator.validate(pojoClass); }
Example 17
Source File: issue27Test.java From openpojo with Apache License 2.0 | 4 votes |
@Test(expected = AssertionError.class) public void shouldFailValidationWithIntegerFieldAndPrimitiveIntParameterSetter() { final PojoClass pojoClass = PojoClassFactory.getPojoClass(ClassWithIntegerFieldAndPrimitiveIntParameterSetter.class); final Validator pojoValidator = ValidatorBuilder.create().with(new SetterMustExistRule()).build(); pojoValidator.validate(pojoClass); }
Example 18
Source File: IssueTest.java From openpojo with Apache License 2.0 | 4 votes |
@Before public void setUp() { pojoClass = PojoClassFactory.getPojoClass(ClassAggregatingAbstractClass.class); RandomGeneratorService randomGeneratorService = ServiceRegistrar.getInstance().getRandomGeneratorService(); randomGeneratorService.registerRandomGenerator(new AbstractClassRandomGenerator()); }
Example 19
Source File: InstanceFactory.java From openpojo with Apache License 2.0 | 4 votes |
private static PojoClass wrapAbstractClass(final PojoClass pojoClass) { return PojoClassFactory.getPojoClass(ByteCodeFactory.getSubClass(pojoClass.getClazz())); }
Example 20
Source File: issue27Test.java From openpojo with Apache License 2.0 | 4 votes |
@Test(expected = AssertionError.class) public void shouldFailValidationWithPrimitiveIntFieldAndIntegerParameterSetter() { final PojoClass pojoClass = PojoClassFactory.getPojoClass(ClassWithPrimitiveIntFieldAndIntegerParameterSetter.class); final Validator pojoValidator = ValidatorBuilder.create().with(new SetterMustExistRule()).build(); pojoValidator.validate(pojoClass); }