View Javadoc

1   package com.atlassian.webdriver.rule;
2   
3   import org.junit.runner.Description;
4   import org.junit.runners.JUnit4;
5   import org.junit.runners.model.InitializationError;
6   
7   /**
8    * For creating JUnit test descriptions
9    *
10   * @since 2.1
11   */
12  public final class Descriptions
13  {
14  
15      private Descriptions()
16      {
17          throw new AssertionError("Don't instantiate me");
18      }
19  
20      public static Description forSuite(Class<?> clazz)
21      {
22          try
23          {
24              return new JUnit4(clazz).getDescription();
25          }
26          catch (InitializationError initializationError)
27          {
28              throw new IllegalArgumentException("Provided class is not a valid test class", initializationError);
29          }
30      }
31  
32      public static Description forTest(Class<?> clazz, String methodName)
33      {
34          for (Description test : forSuite(clazz).getChildren())
35          {
36              if (test.getMethodName().equals(methodName))
37              {
38                  return test;
39              }
40          }
41          throw new IllegalArgumentException("Class " + clazz.getName() + " does not contain a valid test method " + methodName);
42      }
43  }