Java Code Examples for com.openpojo.validation.affirm.Affirm#affirmNull()

The following examples show how to use com.openpojo.validation.affirm.Affirm#affirmNull() . 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: DefaultValuesNullTester.java    From openpojo with Apache License 2.0 5 votes vote down vote up
public void run(final PojoClass pojoClass) {
  final Object classInstance = ValidationHelper.getBasicInstance(pojoClass);

  for (final PojoField fieldEntry : pojoClass.getPojoFields()) {
    if (!fieldEntry.isPrimitive() && !fieldEntry.isFinal() && fieldEntry.getAnnotation(BusinessKey.class) == null) {
      Affirm.affirmNull(String.format("Expected null value for for field=[%s]", fieldEntry), fieldEntry.get(classInstance));
    }
  }
}
 
Example 2
Source File: InstanceFactoryTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCreateUsingNullParameterDoubleConstructor() {
  final Class<?> clazz = ClassWithVariousDeclaredContructorsAndMethods.class;
  final String stringParam = RandomFactory.getRandomValue(String.class);
  final ClassWithVariousDeclaredContructorsAndMethods obj =
      (ClassWithVariousDeclaredContructorsAndMethods) getInstance(clazz, stringParam, null);

  Affirm.affirmNotNull("Should have created using two parameter constructor", obj);
  Affirm.affirmNull("Should have called using two parameter constructor", obj.doubleIntegerConstructor);
  Affirm.affirmEquals("Should have called using two parameter constructor", stringParam, obj.doubleStringConstructor);
}
 
Example 3
Source File: PojoPackageImplTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldReturnNullAnnotationNoPackageInfo() {
  final PojoPackage pojoPackage = PojoPackageFactory.getPojoPackage(this.getClass().getPackage().getName()
      + ".packagenopackageinfo");
  Affirm.affirmNull(String.format("package-info added to package [%s]?", pojoPackage),
      pojoPackage.getAnnotation(SomeAnnotation.class));
}
 
Example 4
Source File: PojoFieldImplTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for: {@link com.openpojo.reflection.impl.PojoFieldImpl#get(java.lang.Object)}.
 * {@link com.openpojo.reflection.impl.PojoFieldImpl#set(java.lang.Object, java.lang.Object)}.
 */
@Test
public void testSetAndGet() {
  for (PojoField pojoField : pojoClass.getPojoFields()) {
    if (!pojoField.isFinal() && !pojoField.isPrimitive()) {
      Affirm.affirmNull(String.format("Field=[%s] should have null default value", pojoField),
          pojoField.get(pojoClassInstance));
      Object randomValue = RandomFactory.getRandomValue(pojoField.getType());
      pojoField.set(pojoClassInstance, randomValue);
      Affirm.affirmEquals(String.format("PojoField.get() result=[%s] different from what was set=[%s] for " +
          "PojoFieldImpl=[%s]", pojoField.get(pojoClassInstance), randomValue, pojoField), randomValue, pojoField.get
          (pojoClassInstance));
    }
  }
}
 
Example 5
Source File: PojoMethodImplTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
/**
 * Test method for {@link com.openpojo.reflection.impl.PojoMethodImpl#getAnnotation(java.lang.Class)}.
 */
@Test
public void testGetAnnotation() {
  for (PojoMethod pojoMethod : pojoMethods) {
    if (pojoMethod.getName().equals("methodWithAnnotation")) {
      Affirm.affirmNotNull("removed SomeAnnotation annotation from methodWithAnnotation?",
          pojoMethod.getAnnotation(SomeAnnotation.class));
    }
    if (pojoMethod.getName().equals("methodWithoutAnnotation")) {
      Affirm.affirmNull("SomeAnnotation annotation added to methodWithoutAnnotation?",
          pojoMethod.getAnnotation(SomeAnnotation.class));
    }
  }
}
 
Example 6
Source File: DefaultRandomGeneratorServiceTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldGetTypeBasedOnRegisteredRandomGenerator() {
  final Class<?> type = DefaultRandomGeneratorServiceTest.class;

  Affirm.affirmNull("Should not have received a valid random generator for non registered type",
      defaultRandomGeneratorService.getRandomGeneratorByType(type));

  final DummyRandomGenerator dummyRandomGenerator = new DummyRandomGenerator();
  dummyRandomGenerator.setTypes(new Class<?>[] { type });
  defaultRandomGeneratorService.registerRandomGenerator(dummyRandomGenerator);

  Affirm.affirmEquals("Incorrect random generator returned", dummyRandomGenerator,
      defaultRandomGeneratorService.getRandomGeneratorByType(type));

}
 
Example 7
Source File: BasicRandomGeneratorTest.java    From openpojo with Apache License 2.0 5 votes vote down vote up
/**
 * Test unregisterd type.
 */
@Test
public void testUnregisteredType() {
  Affirm.affirmNull(String.format("Request to non-registered type [%s] must return null!!", this.getClass()),
      basicRandomGenerator.doGenerate(this.getClass()));

}
 
Example 8
Source File: PojoClassImplTest.java    From openpojo with Apache License 2.0 4 votes vote down vote up
@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 9
Source File: DefaultRandomGeneratorServiceTest.java    From openpojo with Apache License 2.0 4 votes vote down vote up
@Test
public void defaultRandomGeneratorMustNotBeInitialized() {
  Affirm.affirmNull(String.format("defaultRandomGenerator must be initialized to null for [%s]",
      defaultRandomGeneratorService), defaultRandomGeneratorService.getDefaultRandomGenerator());
}