コード例 #1
0
  @Test
  public void testClassAnnotationIsAccessible() {
    PricingDataBean bean = new PricingDataBean();

    boolean foundAnnotation = false;
    for (Field field : bean.getClass().getDeclaredFields()) {

      foundAnnotation |= field.isAnnotationPresent(DataValueGenerator.class);
    }

    assertTrue(foundAnnotation);
  }
コード例 #2
0
  // TODO The following test probably has a race condition - test
  // non-deterministic
  @Test
  public void testClassAnnotationDataCanBeAccessed() throws Exception {
    final Random random = new Random();
    final PricingDataBean bean = new PricingDataBean();

    for (Field field : bean.getClass().getDeclaredFields()) {
      if (field.isAnnotationPresent(DataValueGenerator.class)) {
        field.setAccessible(true);
        try {
          Class<? extends IValueGenerator> generatorClass =
              field.getAnnotation(DataValueGenerator.class).value();
          IValueGenerator generator = generatorClass.newInstance();
          Object newValue = generator.newValue(random);
          // System.out.println("newValue: "+newValue + "\t" + generator.getClass().getName());
          assertNotNull(newValue);
        } catch (InstantiationException e) {
          e.printStackTrace();
        } catch (IllegalAccessException e) {
          e.printStackTrace();
        }
      }
    }
  }