Java Code Examples for com.openpojo.validation.affirm.Affirm#affirmTrue()
The following examples show how to use
com.openpojo.validation.affirm.Affirm#affirmTrue() .
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: PojoMethodImplTest.java From openpojo with Apache License 2.0 | 6 votes |
@Test public void multipleAnnotationsShouldBeReturned() { for (PojoMethod pojoMethod : pojoMethods) { if (pojoMethod.getName().equals("methodWithMultipleAnnotations")) { Affirm.affirmEquals(String.format("Annotations added/removed from method=[%s]", pojoMethod), 2, pojoMethod.getAnnotations().size()); List<Class<?>> expectedAnnotations = new LinkedList<Class<?>>(); expectedAnnotations.add(SomeAnnotation.class); expectedAnnotations.add(AnotherAnnotation.class); for (Annotation annotation : pojoMethod.getAnnotations()) { Affirm.affirmTrue(String.format("Expected annotations [%s] not found, instead found [%s]", expectedAnnotations, annotation.annotationType()), expectedAnnotations.contains(annotation.annotationType())); } return; } } Affirm.fail(String.format("methodWithMultipleAnnotations renamed? expected in [%s]", pojoClass)); }
Example 2
Source File: JARPackageLoaderTest.java From openpojo with Apache License 2.0 | 6 votes |
@Test public final void shouldGetJarSubClasses() { JARPackageLoader jarPackage = getJarPackageLoader(packageName); Set<String> classesNames = new LinkedHashSet<String>(); for (Type type : jarPackage.getTypes()) { classesNames.add(((Class<?>) type).getName()); } Affirm.affirmEquals(MessageFormatter.format("Classes added/removed to {0} found[{1}]?!", packageName, classesNames), expectedClassesNames.length, classesNames.size()); for (String expectedClassName : classesNames) { Affirm.affirmTrue(MessageFormatter.format("Expected class[{0}] not found", expectedClassName), classesNames.contains(expectedClassName)); } }
Example 3
Source File: EnumRandomGeneratorTest.java From openpojo with Apache License 2.0 | 6 votes |
@Test @SuppressWarnings("ConstantConditions") public void shouldGenerateRandomEnum() { RandomGenerator randomGenerator = EnumRandomGenerator.getInstance(); Enum someEnum = (Enum) randomGenerator.doGenerate(Enum.class); Affirm.affirmTrue("should never generate null", someEnum != null); Enum anotherEnum = (Enum) randomGenerator.doGenerate(Enum.class); try { Affirm.affirmFalse("Enum's should be different", someEnum.equals(anotherEnum)); } catch (AssertionError error) { // on occasion they may be the same - 1% chance, try one more time. anotherEnum = (Enum) randomGenerator.doGenerate(Enum.class); Affirm.affirmFalse("Enum's should be different", someEnum.equals(anotherEnum)); } }
Example 4
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 5
Source File: EnumRandomGeneratorTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("ConstantConditions") public void endToEndTest() { Enum someEnum = RandomFactory.getRandomValue(Enum.class); Affirm.affirmNotNull("Should generate Enum", someEnum); Affirm.affirmTrue("Should use SomeEnum when generating", someEnum.getClass() == SomeEnum.class); }
Example 6
Source File: PojoPackageImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void shouldReturnAnnotationList() { final PojoPackage pojoPackage = PojoPackageFactory.getPojoPackage(this.getClass().getPackage().getName() + ".packagemanyannotations"); Affirm.affirmEquals(String.format("Annotations added/removed? [%s]", pojoPackage), 2, pojoPackage.getAnnotations().size()); final List<Class<?>> expectedAnnotations = new LinkedList<Class<?>>(); expectedAnnotations.add(SomeAnnotation.class); expectedAnnotations.add(AnotherAnnotation.class); for (final Annotation annotation : pojoPackage.getAnnotations()) { Affirm.affirmTrue(String.format("Expected annotations [%s] not found, instead found [%s]", expectedAnnotations, annotation.annotationType()), expectedAnnotations.contains(annotation.annotationType())); } }
Example 7
Source File: RandomInstanceFromInterfaceRandomGeneratorTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void shouldImplementAccuratetoStringAndhashCode() { final String toString = aSimpleInterface.toString(); Affirm.affirmNotNull("toString() on proxy returned null", toString); Affirm.affirmTrue(String.format("toString returned [%s] expected it to begin with [%s] and contain [@]", toString, "$Proxy"), toString.contains("$Proxy") && toString.contains("@")); Affirm.affirmTrue("toString() doesn't end with hashCode()", toString.endsWith(String.valueOf(aSimpleInterface.hashCode()))); final ASimpleInterface anotherSimpleInterface = proxyGenerator.doGenerate(ASimpleInterface.class); Affirm.affirmTrue("Generated Proxy hashCode() should not return equal values across instances", aSimpleInterface.hashCode() != anotherSimpleInterface.hashCode()); }
Example 8
Source File: PojoMethodImplTest.java From openpojo with Apache License 2.0 | 5 votes |
/** * Test method for {@link com.openpojo.reflection.impl.PojoMethodImpl#isFinal()}. */ @Test public void testIsFinal() { for (PojoMethod pojoMethod : pojoMethods) { if (pojoMethod.getName().equals("finalMethod")) { Affirm.affirmTrue("Failed to check final", pojoMethod.isFinal()); return; } } Affirm.fail("finalMethod missing!!"); }
Example 9
Source File: PojoClassImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void canGetEnclosingClass() { PojoClass aClassWithNested = PojoClassFactory.getPojoClass(AClassWithNestedClass.class); PojoClass nestedClass = PojoClassFactory.getPojoClass(AClassWithNestedClass.NestedClass.class); Affirm.affirmTrue("Class should be nested", nestedClass.isNestedClass()); PojoClass enclosingClass = nestedClass.getEnclosingClass(); Affirm.affirmNotNull("Enclosing should not be null", enclosingClass); Affirm.affirmTrue("Invalid enclosing class", enclosingClass.getClazz().equals(aClassWithNested.getClazz())); }
Example 10
Source File: PojoClassImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void isPrivateClass() { PojoClass pojoclass = getClass(SAMPLE_CLASSES_PKG + ".AccessibilityClass$PrivateClass"); Affirm.affirmNotNull("class not found", pojoclass); Affirm.affirmTrue("isPrivate() check on class=[" + pojoclass + "] returned true!!", pojoclass.isPrivate()); Affirm.affirmFalse("isPackagePrivate() check on class=[" + pojoclass + "] returned true!!", pojoclass.isPackagePrivate()); Affirm.affirmFalse("isProtected() check on class=[" + pojoclass + "] returned true!!", pojoclass.isProtected()); Affirm.affirmFalse("isPublic() check on class=[" + pojoclass + "] returned true!!", pojoclass.isPublic()); }
Example 11
Source File: PojoClassImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void testExtendz() { final Class<?> aClassExtendingAnInterfaceAndAbstract = AClassExtendingAnInterface.class; final Class<?> anInterface = AnInterfaceClass.class; final PojoClass pojoClass = getPojoClassImplForClass(aClassExtendingAnInterfaceAndAbstract); Affirm.affirmTrue(String.format("Failed to validate Class=[%s] extending an interface=[%s]" + " for PojoClass " + "Implementation=[%s]", aClassExtendingAnInterfaceAndAbstract, anInterface, pojoClass), pojoClass.extendz(anInterface)); }
Example 12
Source File: PojoFieldImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void canAccessGetter() { boolean found = false; for (PojoField pojoField : pojoClass.getPojoFields()) { if (pojoField.hasGetter()) { PojoMethod getter = pojoField.getGetter(); Affirm.affirmNotNull("Getter can't be retrieved", getter); Object randomInstance = RandomFactory.getRandomValue(pojoField.getType()); pojoField.set(pojoClassInstance, randomInstance); Affirm.affirmSame("Expected same object in and out", randomInstance, getter.invoke(pojoClassInstance)); found = true; } } Affirm.affirmTrue("No getters were found!", found); }
Example 13
Source File: PojoClassImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void isPublicClass() { PojoClass pojoclass = getClass(SAMPLE_CLASSES_PKG + ".AccessibilityClass$PublicClass"); Affirm.affirmNotNull("class not found", pojoclass); Affirm.affirmTrue("isPublic() check on class=[" + pojoclass + "] returned false!!", pojoclass.isPublic()); Affirm.affirmFalse("isProtected() check on class=[" + pojoclass + "] returned true!!", pojoclass.isProtected()); Affirm.affirmFalse("isPrivate() check on class=[" + pojoclass + "] returned true!!", pojoclass.isPrivate()); Affirm.affirmFalse("isPackagePrivate() check on class=[" + pojoclass + "] returned true!!", pojoclass.isPackagePrivate()); }
Example 14
Source File: JavaLoggerTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void testToString() { Logger log = LoggerFactory.getLogger(getCategory()); Affirm.affirmTrue(String.format("toString() failed on [%s] got [%s]!", JavaLogger.class.getName(), log.toString()), log .toString().startsWith("com.openpojo.log.impl.JavaLogger [@") && log.toString().contains(": logger=java.util" + "" + ".logging.Logger@") && log.toString().endsWith("]")); }
Example 15
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 16
Source File: InstanceFactoryTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("RedundantArrayCreation") public void shouldCreateUsingDefaultConstructor() { final Class<?> clazz = ClassWithNoDeclaredConstructor.class; final Object obj1 = getInstance(clazz, (Object[]) null); Affirm.affirmNotNull("Should have created an object", obj1); final Object obj2 = getInstance(clazz, new Object[] {}); Affirm.affirmTrue("Should have created a different object", obj1 != obj2); }
Example 17
Source File: LoggerFactoryTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test @SuppressWarnings("unchecked") public final void shouldReturnSetLogger() throws ClassNotFoundException { for (String logger : supportedLoggers) { Class<Logger> loggerClass = (Class<Logger>) Class.forName(logger); LoggerFactory.setActiveLogger(loggerClass); Affirm.affirmTrue(String.format("Expected LoggerFactory to be set to [%s] but was [%s]", loggerClass, LoggerFactory.getLogger((String) null)), LoggerFactory.getLogger((String) null).getClass().equals(loggerClass)); } }
Example 18
Source File: PojoFieldImplTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public void testIsTransient() { for (PojoField pojoField : pojoClass.getPojoFields()) { if (pojoField.getName().equals("transientString")) { Affirm.affirmTrue(String.format("isTransient() check on field=[%s] returned false!!", pojoField), pojoField.isTransient ()); } } }
Example 19
Source File: JARPackageLoaderTest.java From openpojo with Apache License 2.0 | 5 votes |
@Test public final void shouldGetJarSubPackages() { JARPackageLoader jarPackage = getJarPackageLoader(packageName); Set<String> subPackagesNames = jarPackage.getSubPackages(); Affirm.affirmEquals(MessageFormatter.format("SubPackages added/removed to {0} found[{1}]?!", packageName, subPackagesNames) , expectedSubPackagesNames.length, subPackagesNames.size()); for (String expectedPackageName : expectedSubPackagesNames) { Affirm.affirmTrue(MessageFormatter.format("Expected package[{0}] not found", expectedPackageName), subPackagesNames.contains(expectedPackageName)); } }
Example 20
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()); }