FeatureEnumTest.java 文件源码

java
阅读 28 收藏 0 点赞 0 评论 0

项目:guava-libraries 作者:
private static void assertGoodTesterAnnotation(
    Class<? extends Annotation> annotationClass) {
  assertNotNull(
      String.format("%s must be annotated with @TesterAnnotation.",
          annotationClass),
      annotationClass.getAnnotation(TesterAnnotation.class));
  final Retention retentionPolicy =
      annotationClass.getAnnotation(Retention.class);
  assertNotNull(
      String.format("%s must have a @Retention annotation.", annotationClass),
      retentionPolicy);
  assertEquals(
      String.format("%s must have RUNTIME RetentionPolicy.", annotationClass),
      RetentionPolicy.RUNTIME, retentionPolicy.value());
  assertNotNull(
      String.format("%s must be inherited.", annotationClass),
      annotationClass.getAnnotation(Inherited.class));

  for (String propertyName : new String[]{"value", "absent"}) {
    Method method = null;
    try {
      method = annotationClass.getMethod(propertyName);
    } catch (NoSuchMethodException e) {
      fail(String.format("%s must have a property named '%s'.",
          annotationClass, propertyName));
    }
    final Class<?> returnType = method.getReturnType();
    assertTrue(String.format("%s.%s() must return an array.",
        annotationClass, propertyName),
        returnType.isArray());
    assertSame(String.format("%s.%s() must return an array of %s.",
        annotationClass, propertyName, annotationClass.getDeclaringClass()),
        annotationClass.getDeclaringClass(), returnType.getComponentType());
  }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号