### Question:
AnnotationFactory { @SuppressWarnings("unchecked") public static <T extends Annotation> T create(AnnotationDescriptor<T> descriptor) { boolean isSecured = System.getSecurityManager() != null; GetClassLoader action = GetClassLoader.fromContext(); ClassLoader classLoader = isSecured ? AccessController.doPrivileged( action ) : action.run(); Class<T> proxyClass = (Class<T>) Proxy.getProxyClass( classLoader, descriptor.type() ); InvocationHandler handler = new AnnotationProxy( descriptor ); try { return getProxyInstance( proxyClass, handler ); } catch (RuntimeException e) { throw e; } catch (Exception e) { throw new RuntimeException( e ); } }  @SuppressWarnings("unchecked") static T create(AnnotationDescriptor<T> descriptor);  }### Answer:
@Test public void createAnnotationProxy() { AnnotationDescriptor<Size> descriptor = new AnnotationDescriptor<Size>( Size.class ); descriptor.setValue( "min", 5 ); descriptor.setValue( "max", 10 ); Size size = AnnotationFactory.create( descriptor ); assertEquals( size.min(), 5, "Wrong parameter value" ); assertEquals( size.max(), 10, "Wrong parameter value" ); }
@Test(expectedExceptions = IllegalArgumentException.class) public void createAnnotationProxyMissingRequiredParamter() { AnnotationDescriptor<Pattern> descriptor = new AnnotationDescriptor<Pattern>( Pattern.class ); AnnotationFactory.create( descriptor ); }
@Test public void createAnnotationProxyWithRequiredParamter() { AnnotationDescriptor<Pattern> descriptor = new AnnotationDescriptor<Pattern>( Pattern.class ); descriptor.setValue( "regexp", ".*" ); Pattern pattern = AnnotationFactory.create( descriptor ); assertEquals( ".*", pattern.regexp(), "Wrong parameter value" ); }