title: Get custom method annotation value from junit test
body: <p>I have a junit test where I'd like to use an annotation on methods to define test settings.</p>
  
  <p>I have a super class of the test class where I have abstracted some processing and where I'd like to read the method annotation values.</p>
  
  <p>I have seen examples of reading method annotations by looping over a class.  I'm not sure this will work for what I need.  How do I find which test method was called and then read those specific annotation values (TrialMethod.name)?</p>
  
  <pre><code>public class MyUTest extends Processor{
  
      @Test
      @TrialMethod(name = "methodToBeTested")
      public void testMethod() throws Exception {
          //assert stuff
      }
  
  }
  
  
  public class Processor extends TestCase{
  
      private TrialMethodModel trialMethodModel = new TrialMethodModel();
  
      private void setMethodNameByAnnotation() {
          Class&lt;?&gt; clazz = this.getClass();
          Class&lt;TrialMethod&gt; trialMethodClass = TrialMethod.class;
  
          for (Method method : clazz.getDeclaredMethods()){
  
              if (method.isAnnotationPresent(trialMethodClass)){
                  trialMethodModel.setName(method.getAnnotation(trialMethodClass).name());
              }
          }
      }
  }
  
  @Documented
  @Target(ElementType.METHOD)
  @Retention(value=RetentionPolicy.RUNTIME)
  public @interface TrialMethod {
  
      String name();
  
  }
  </code></pre>