summaryrefslogtreecommitdiffstats
path: root/junit4/src/test/java/org/junit/tests/description/SuiteDescriptionTest.java
blob: 8124b0164317088088645ba788ddaf013e8e15ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package org.junit.tests.description;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.Test;
import org.junit.runner.Description;

public class SuiteDescriptionTest {
	Description childless = Description.createSuiteDescription("a");
	Description anotherChildless = Description.createSuiteDescription("a");
	Description namedB = Description.createSuiteDescription("b");
	
	Description twoKids = descriptionWithTwoKids("foo", "bar");
	Description anotherTwoKids = descriptionWithTwoKids("foo", "baz");

	@Test public void equalsIsCorrect() {	
		assertEquals(childless, anotherChildless);
		assertFalse(childless.equals(namedB));
		assertEquals(childless, twoKids);
		assertEquals(twoKids, anotherTwoKids);
		assertFalse(twoKids.equals(new Integer(5)));
	}

	@Test public void hashCodeIsReasonable() {
		assertEquals(childless.hashCode(), anotherChildless.hashCode());
		assertFalse(childless.hashCode() == namedB.hashCode());
	}
	
	private Description descriptionWithTwoKids(String first, String second) {
		Description twoKids = Description.createSuiteDescription("a");
		twoKids.addChild(Description.createTestDescription(getClass(), first));
		twoKids.addChild(Description.createTestDescription(getClass(), second));
		return twoKids;
	}
}