1 package org.junit.runner; 2 3 import java.util.ArrayList ; 4 5 22 public class Description { 23 24 30 public static Description createSuiteDescription(String name) { 31 return new Description(name); 32 } 33 34 41 public static Description createTestDescription(Class <?> clazz, String name) { 42 return new Description(String.format("%s(%s)", name, clazz.getName())); 43 } 44 45 50 public static Description createSuiteDescription(Class <?> testClass) { 51 return new Description(testClass.getName()); 52 } 53 54 public static final Description EMPTY= new Description("No Tests"); 55 public static final Description TEST_MECHANISM= new Description("Test mechanism"); 56 57 private final ArrayList <Description> fChildren= new ArrayList <Description>(); 58 private final String fDisplayName; 59 60 63 @Deprecated 64 protected Description(final String displayName) { 65 fDisplayName= displayName; 66 } 67 68 71 public String getDisplayName() { 72 return fDisplayName; 73 } 74 75 79 public void addChild(Description description) { 80 getChildren().add(description); 81 } 82 83 86 public ArrayList <Description> getChildren() { 87 return fChildren; 88 } 89 90 93 public boolean isSuite() { 94 return !isTest(); 95 } 96 97 100 public boolean isTest() { 101 return getChildren().isEmpty(); 102 } 103 104 107 public int testCount() { 108 if (isTest()) 109 return 1; 110 int result= 0; 111 for (Description child : getChildren()) 112 result+= child.testCount(); 113 return result; 114 } 115 116 @Override 117 public int hashCode() { 118 return getDisplayName().hashCode(); 119 } 120 121 @Override 122 public boolean equals(Object obj) { 123 if (!(obj instanceof Description)) 124 return false; 125 Description d = (Description) obj; 126 return getDisplayName().equals(d.getDisplayName()) 127 && getChildren().equals(d.getChildren()); 128 } 129 130 @Override 131 public String toString() { 132 return getDisplayName(); 133 } 134 } | Popular Tags |