@Test public void processesConstructors() { ResourceDescriptor resource = new AbstractResourceDescriptor(SampleRootResource.class); assertEquals(3, resource.getConstructorDescriptors().size()); List<ConstructorDescriptor> constructors = resource.getConstructorDescriptors(); assertEquals(2, constructors.get(0).getParameters().size()); assertEquals(1, constructors.get(1).getParameters().size()); assertEquals(0, constructors.get(2).getParameters().size()); ConstructorDescriptor constructorWithTheMostParameters = constructors.get(0); List<Parameter> constructorParameters = constructorWithTheMostParameters.getParameters(); assertEquals(int.class, constructorParameters.get(0).getParameterClass()); assertEquals(String.class, constructorParameters.get(1).getParameterClass()); assertEquals(QueryParam.class, constructorParameters.get(0).getAnnotation().annotationType()); assertEquals(PathParam.class, constructorParameters.get(1).getAnnotation().annotationType()); assertEquals("test", ((QueryParam)constructorParameters.get(0).getAnnotation()).value()); assertEquals("b", ((PathParam)constructorParameters.get(1).getAnnotation()).value()); assertFalse(constructorParameters.get(0).isEncoded()); assertTrue(constructorParameters.get(1).isEncoded()); }
private <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T>[] annotationClasses) { T annotation = null; for (int i = 0; annotation == null && i < annotationClasses.length; i++) { annotation = clazz.getAnnotation(annotationClasses[i]); } return annotation; }
AbstractResourceDescriptor extends BaseObjectModel implements ResourceDescriptor { private <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T>[] annotationClasses) { T annotation = null; for (int i = 0; annotation == null && i < annotationClasses.length; i++) { annotation = clazz.getAnnotation(annotationClasses[i]); } return annotation; } }
AbstractResourceDescriptor extends BaseObjectModel implements ResourceDescriptor { private <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T>[] annotationClasses) { T annotation = null; for (int i = 0; annotation == null && i < annotationClasses.length; i++) { annotation = clazz.getAnnotation(annotationClasses[i]); } return annotation; } AbstractResourceDescriptor(Class<?> resourceClass);  AbstractResourceDescriptor(String path, Class<?> resourceClass);  AbstractResourceDescriptor(Object resource);  AbstractResourceDescriptor(String path, Object resource); }
AbstractResourceDescriptor extends BaseObjectModel implements ResourceDescriptor { private <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T>[] annotationClasses) { T annotation = null; for (int i = 0; annotation == null && i < annotationClasses.length; i++) { annotation = clazz.getAnnotation(annotationClasses[i]); } return annotation; } AbstractResourceDescriptor(Class<?> resourceClass);  AbstractResourceDescriptor(String path, Class<?> resourceClass);  AbstractResourceDescriptor(Object resource);  AbstractResourceDescriptor(String path, Object resource); @Override PathValue getPathValue(); @Override Map<String, List<ResourceMethodDescriptor>> getResourceMethods(); @Override Map<UriPattern, SubResourceLocatorDescriptor> getSubResourceLocators(); @Override Map<UriPattern, Map<String, List<SubResourceMethodDescriptor>>> getSubResourceMethods(); @Override UriPattern getUriPattern(); @Override boolean isRootResource(); @Override String toString(); }
AbstractResourceDescriptor extends BaseObjectModel implements ResourceDescriptor { private <T extends Annotation> T getAnnotation(Class<?> clazz, Class<T>[] annotationClasses) { T annotation = null; for (int i = 0; annotation == null && i < annotationClasses.length; i++) { annotation = clazz.getAnnotation(annotationClasses[i]); } return annotation; } AbstractResourceDescriptor(Class<?> resourceClass);  AbstractResourceDescriptor(String path, Class<?> resourceClass);  AbstractResourceDescriptor(Object resource);  AbstractResourceDescriptor(String path, Object resource); @Override PathValue getPathValue(); @Override Map<String, List<ResourceMethodDescriptor>> getResourceMethods(); @Override Map<UriPattern, SubResourceLocatorDescriptor> getSubResourceLocators(); @Override Map<UriPattern, Map<String, List<SubResourceMethodDescriptor>>> getSubResourceMethods(); @Override UriPattern getUriPattern(); @Override boolean isRootResource(); @Override String toString();  }