Java Code Examples for com.openpojo.validation.affirm.Affirm#affirmFalse()
The following examples show how to use
com.openpojo.validation.affirm.Affirm#affirmFalse() .
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: PojoClassImplTest.java From openpojo with Apache License 2.0 | 6 votes |
@Test public void testCopy() { final AClassWithEquality first = new AClassWithEquality(RandomFactory.getRandomValue(String.class), RandomFactory .getRandomValue(Integer.class)); final AClassWithEquality second = new AClassWithEquality(); Affirm.affirmFalse(String.format("Class with data=[%s], evaluated equals to one without=[%s]!!", BusinessIdentity.toString (first), BusinessIdentity.toString(second)), first.equals(second)); final PojoClass pojoClass = getPojoClassImplForClass(first.getClass()); pojoClass.copy(first, second); Affirm.affirmTrue(String.format("Class=[%s] copied to=[%s] and still equals returned false using PojoClass" + " " + "implementation=[%s]!!", BusinessIdentity.toString(first), BusinessIdentity.toString(second), pojoClass), first.equals (second)); }
Example 2
Source File: CommonCode.java From openpojo with Apache License 2.0 | 6 votes |
/** * Utility method to assist with testing all non-Primitive classes. * * @param type * The class type to test. */ @SuppressWarnings("ConstantConditions") public static void testDoGenerateForClass(final RandomGenerator randomGenerator, final Class<?> type) { Affirm.affirmTrue(String.format("Failed to get the requested type=[%s] from [%s] received=[%s] instead", type, randomGenerator, randomGenerator.doGenerate(type)), type.isInstance(randomGenerator.doGenerate(type))); Object object = type.cast(randomGenerator.doGenerate(type)); Affirm.affirmNotNull(String.format("Request to registered type [%s] must return non-null value!!", type), object); Object anotherObject = randomGenerator.doGenerate(type); if (object.equals(anotherObject)) { // Just incase they are the same anotherObject = randomGenerator.doGenerate(type); // if Boolean, try for 20 times, since there is a 50% chance we land on the same value. if (object.equals(anotherObject) && type == Boolean.class) { for (int counter = 0; counter < 20; counter++) { anotherObject = randomGenerator.doGenerate(type); if (!object.equals(anotherObject)) { break; } } } } Affirm.affirmFalse(String.format("[%s] generating the same values for type=[%s]", randomGenerator, type), object.equals(anotherObject)); }
Example 3
Source File: PojoMethodImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void testIsPublic() { String prefix = "publicMethod"; PojoMethod pojoMethod = getPojoMethodStartingWith(prefix); Affirm.affirmNotNull("method not found [" + prefix + "]", pojoMethod); Affirm.affirmTrue("isPublic() check on method=[" + pojoMethod + "] returned false!!", pojoMethod.isPublic()); Affirm.affirmFalse("isPrivate() check on method=[" + pojoMethod + "] returned true!!", pojoMethod.isPrivate()); Affirm.affirmFalse("isPackagePrivate() check on method=[" + pojoMethod + "] returned true!!", pojoMethod.isPackagePrivate()); Affirm.affirmFalse("isProtected() check on method=[" + pojoMethod + "] returned true!!", pojoMethod.isProtected()); }
Example 4
Source File: PojoFieldImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void testIsPublic() { String prefix = "public"; PojoField pojoField = getFieldStartingWith(prefix); Affirm.affirmNotNull("Field not found [" + prefix + "]", pojoField); Affirm.affirmTrue("isPublic() check on field=[" + pojoField + "] returned false!!", pojoField.isPublic()); Affirm.affirmFalse("isPrivate() check on field=[" + pojoField + "] returned true!!", pojoField.isPrivate()); Affirm.affirmFalse("isPackagePrivate() check on field=[" + pojoField + "] returned true!!", pojoField.isPackagePrivate()); Affirm.affirmFalse("isProtected() check on field=[" + pojoField + "] returned true!!", pojoField.isProtected()); }
Example 5
Source File: PojoFieldImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void shouldGetParameterizedType() { PojoClass pojoClass = PojoClassFactory.getPojoClass(ClassWithGenericTypes.class); Affirm.affirmEquals("Fields added/removed?!", 4, pojoClass.getPojoFields().size()); int affirmChecks = 0; for (PojoField pojoField : pojoClass.getPojoFields()) { if (pojoField.getName().equals("parameterizedChildren")) { Affirm.affirmTrue("Not Generic?!", pojoField.isParameterized()); Affirm.affirmTrue("Wrong Parameterization!?", pojoField.getParameterTypes().contains(ClassWithGenericTypes.class)); affirmChecks++; } if (pojoField.getName().equals("nonparameterizedList") || pojoField.getName().equals("nonParameterizedString")) { Affirm.affirmFalse("Turned generic?!", pojoField.isParameterized()); Affirm.affirmEquals("Returned non-empty list for nonParameterized type!? [" + pojoField.getParameterTypes() + "]", 0, pojoField.getParameterTypes().size()); affirmChecks++; } if (pojoField.getName().equals("parameterizedMap")) { Affirm.affirmEquals("MultipTypeGeneric failed!!", 2, pojoField.getParameterTypes().size()); Affirm.affirmTrue(String.format("Type not found [%s]", String.class), pojoField.getParameterTypes().contains(String .class)); Affirm.affirmTrue(String.format("Type not found [%s]", Integer.class), pojoField.getParameterTypes().contains(Integer .class)); affirmChecks++; } } Affirm.affirmEquals("Fields added/removed/renamed? expected 4 checks!!", 4, affirmChecks); }
Example 6
Source File: PojoFieldPrefixedFieldsTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void shouldNotHaveGettersAndSetters() { PojoClass pojoClass = PojoClassFactory.getPojoClass(AClassWithFieldsPrefixed.class); for (PojoField pojoField : pojoClass.getPojoFields()) { Affirm.affirmFalse(String.format("Getters / Setters not found on field =[%s]", pojoField), pojoField.hasGetter() || pojoField.hasSetter()); } }
Example 7
Source File: PojoFieldImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void isPackagePrivate() { String prefix = "packagePrivate"; PojoField pojoField = getFieldStartingWith(prefix); Affirm.affirmNotNull("Field not found [" + prefix + "]", pojoField); Affirm.affirmTrue("isPackagePrivate() check on field=[" + pojoField + "] returned false!!", pojoField.isPackagePrivate()); Affirm.affirmFalse("isPrivate() check on field=[" + pojoField + "] returned true!!", pojoField.isPrivate()); Affirm.affirmFalse("isPublic() check on field=[" + pojoField + "] returned true!!", pojoField.isPublic()); Affirm.affirmFalse("isProtected() check on field=[" + pojoField + "] returned true!!", pojoField.isProtected()); }
Example 8
Source File: PojoClassImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void isPackagePrivateClass() { PojoClass pojoclass = getClass(SAMPLE_CLASSES_PKG + ".AccessibilityClass$PackagePrivateClass"); Affirm.affirmNotNull("class not found", pojoclass); Affirm.affirmTrue("isPackagePrivate() check on class=[" + pojoclass + "] returned false!!", pojoclass.isPackagePrivate()); Affirm.affirmFalse("isPrivate() check on class=[" + pojoclass + "] returned true!!", pojoclass.isPrivate()); Affirm.affirmFalse("isProtected() check on class=[" + pojoclass + "] returned true!!", pojoclass.isProtected()); Affirm.affirmFalse("isPublic() check on class=[" + pojoclass + "] returned true!!", pojoclass.isPublic()); }
Example 9
Source File: PojoMethodImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void isPackagePrivate() { String prefix = "packagePrivateMethod"; PojoMethod pojoMethod = getPojoMethodStartingWith(prefix); Affirm.affirmNotNull("method not found [" + prefix + "]", pojoMethod); Affirm.affirmTrue("isPackagePrivate() check on method=[" + pojoMethod + "] returned false!!", pojoMethod.isPackagePrivate()); Affirm.affirmFalse("isPrivate() check on method=[" + pojoMethod + "] returned true!!", pojoMethod.isPrivate()); Affirm.affirmFalse("isProtected() check on method=[" + pojoMethod + "] returned true!!", pojoMethod.isProtected()); Affirm.affirmFalse("isPublic() check on method=[" + pojoMethod + "] returned true!!", pojoMethod.isPublic()); }
Example 10
Source File: PojoClassImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void isProtectedClass() { PojoClass pojoclass = getClass(SAMPLE_CLASSES_PKG + ".AccessibilityClass$ProtectedClass"); Affirm.affirmNotNull("class not found", pojoclass); Affirm.affirmTrue("isProtected() check on class=[" + pojoclass + "] returned false!!", pojoclass.isProtected()); Affirm.affirmFalse("isPrivate() check on class=[" + pojoclass + "] returned true!!", pojoclass.isPrivate()); Affirm.affirmFalse("isPackagePrivate() check on class=[" + pojoclass + "] returned true!!", pojoclass.isPackagePrivate()); Affirm.affirmFalse("isPublic() check on class=[" + pojoclass + "] returned true!!", pojoclass.isPublic()); }
Example 11
Source File: RandomFactoryTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void generateRandomWithNoRegisteredRandomGenerator() { final Class<?> clazz = AClassWithNoRegisteredRandomGenerator.class; final Object someInstance = RandomFactory.getRandomValue(clazz); Affirm.affirmNotNull(String.format("Null value returned for random instance of [%s]", clazz.getName()), someInstance); Affirm.affirmFalse(String.format("Non randomized instance returned (i.e. same object) for [%s]", clazz.getName()), someInstance.equals(RandomFactory.getRandomValue(clazz))); }
Example 12
Source File: CollectionAndMapPackageRandomGeneratorsTest.java From openpojo with Apache License 2.0 | 5 votes |
/** * This test will test every random generator against its declared types, for every type returned from getTypes. */ @Test public void shouldReturnRandomInstanceForDeclaredType() { for (final PojoClass randomGeneratorPojoClass : collectionRandomGenerators) { final RandomGenerator randomGenerator = (RandomGenerator) InstanceFactory.getInstance(randomGeneratorPojoClass); final Collection<Class<?>> generatorTypes = randomGenerator.getTypes(); for (final Class<?> type : generatorTypes) { LoggerFactory.getLogger(this.getClass()).debug("Generating Type [" + type + "]"); Object firstInstance = randomGenerator.doGenerate(type); Affirm.affirmNotNull(MessageFormatter.format("[{0}] returned null for type [{1}]", randomGenerator.getClass(), type), firstInstance); Affirm.affirmTrue(MessageFormatter.format("[{0}] returned incompatible type [{1}] when requesting type [{2}]", randomGenerator.getClass(), firstInstance.getClass(), type), type.isAssignableFrom(firstInstance.getClass())); int counter = 10; Object secondInstance = null; while (counter > 0) { firstInstance = randomGenerator.doGenerate(type); secondInstance = randomGenerator.doGenerate(type); if (!firstInstance.equals(secondInstance)) { break; } counter--; } Affirm.affirmFalse(MessageFormatter.format("[{0}] returned identical instances for type [{1}]", randomGenerator.getClass(), type), firstInstance.equals(secondInstance)); } } }
Example 13
Source File: AbstractUnitTest.java From cia with Apache License 2.0 | 5 votes |
public void run(final PojoClass pojoClass) { final Object instance = randomValues(pojoClass); Affirm.affirmFalse("EqualsCompareNullFailure", instance.equals(null)); Affirm.affirmFalse("EqualsCompareWrongClassFailure", instance.equals("WrongClass")); Affirm.affirmTrue("EqualsCompareSelfFailure", instance.equals(instance)); final Object instance2 = randomValues(pojoClass); instance.equals(instance2); }
Example 14
Source File: PojoMethodImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void testIsSynthetic() { PojoClass syntheticPojoClass = PojoClassFactory.getPojoClass(AClassWithSyntheticMethod.class); for (PojoMethod pojoMethod : syntheticPojoClass.getPojoMethods()) { if (!pojoMethod.getName().equals("doSomethingSneaky") && !pojoMethod.isConstructor()) { Affirm.affirmFalse("Failed to check synthetic method [" + pojoMethod + "]", !pojoMethod.isSynthetic()); return; } } Affirm.fail("failed to find a synthetic method in class"); }
Example 15
Source File: PojoClassImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void testIsFinalOnNonFinalClass() { final Class<?> aNonFinalClass = ANonFinalClass.class; final PojoClass pojoClass = getPojoClassImplForClass(aNonFinalClass); Affirm.affirmFalse(String.format("IsFinal on non-final=[%s] returned true for PojoClass implementation=[%s]!!", aNonFinalClass, pojoClass), pojoClass.isFinal()); }
Example 16
Source File: FilterClassNameTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void testShouldExcludeFileName() { // Include only class names that are in the format of xSample final PojoClassFilter filter = new FilterClassName(".+Sample$"); final String[] classNames = new String[] { "packagepath.packageSample.MyClass", "SampleClass", "Sample", "sample", "Somesample", "someSampleClass" }; for (final String className : classNames) { PojoClass pojoClassStub = PojoStubFactory.getStubPojoClass(className); Affirm.affirmFalse(String.format("[%s] didn't exclude class [%s]!!", filter, className), filter.include(pojoClassStub)); } }
Example 17
Source File: PackageTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public final void testIsValid() { Package javaPackage = new Package(RandomFactory.getRandomValue(String.class)); Affirm.affirmFalse("Invalid package evaluated to as valid?!", javaPackage.isValid()); javaPackage = new Package(this.getClass().getPackage().getName()); Affirm.affirmTrue("Valid package evaluated to as invalid?!", javaPackage.isValid()); }
Example 18
Source File: FilterEnumTest.java From openpojo with Apache License 2.0 | 4 votes |
@Test public final void shouldExcludeEnum() { Affirm.affirmFalse(String.format("[%s] didn't exclude enum!!", enumFilter), enumFilter.include(PojoClassFactory .getPojoClass(SampleEnum.class))); }
Example 19
Source File: PojoClassImplTest.java From openpojo with Apache License 2.0 | 4 votes |
@Test public void shouldReturnNullForNonEnclosedClass() { PojoClass aClassWithNested = PojoClassFactory.getPojoClass(AClassWithNestedClass.class); Affirm.affirmFalse("Class should not be nested", aClassWithNested.isNestedClass()); Affirm.affirmNull("Should not have any enclosing classes", aClassWithNested.getEnclosingClass()); }
Example 20
Source File: RandomInstanceFromInterfaceRandomGeneratorTest.java From openpojo with Apache License 2.0 | 4 votes |
@Test public void shouldReturnANewInstanceEveryTime() { Affirm.affirmFalse("Same instance returned or faulty equality implementation on proxy", aSimpleInterface.equals(proxyGenerator.doGenerate(ASimpleInterface.class))); }