View Javadoc
1   package org.junit.tests.description;
2   
3   import static org.junit.Assert.assertEquals;
4   import static org.junit.Assert.assertFalse;
5   
6   import org.junit.Test;
7   import org.junit.runner.Description;
8   
9   public class SuiteDescriptionTest {
10      Description childless = Description.createSuiteDescription("a");
11      Description anotherChildless = Description.createSuiteDescription("a");
12      Description namedB = Description.createSuiteDescription("b");
13  
14      Description twoKids = descriptionWithTwoKids("foo", "bar");
15      Description anotherTwoKids = descriptionWithTwoKids("foo", "baz");
16  
17      @Test
18      public void equalsIsCorrect() {
19          assertEquals(childless, anotherChildless);
20          assertFalse(childless.equals(namedB));
21          assertEquals(childless, twoKids);
22          assertEquals(twoKids, anotherTwoKids);
23          assertFalse(twoKids.equals(new Integer(5)));
24      }
25  
26      @Test
27      public void hashCodeIsReasonable() {
28          assertEquals(childless.hashCode(), anotherChildless.hashCode());
29          assertFalse(childless.hashCode() == namedB.hashCode());
30      }
31  
32      private Description descriptionWithTwoKids(String first, String second) {
33          Description twoKids = Description.createSuiteDescription("a");
34          twoKids.addChild(Description.createTestDescription(getClass(), first));
35          twoKids.addChild(Description.createTestDescription(getClass(), second));
36          return twoKids;
37      }
38  }