summaryrefslogtreecommitdiffstats
path: root/test/jrummikub/util/PairTest.java
blob: dd34d42ec676d6810a2270c5a377964bd1e5ce10 (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
package jrummikub.util;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.HashSet;
import java.util.Set;

import org.junit.Test;

/** */
public class PairTest {
	/** */
	@Test
	public void testPairToString() {
		assertEquals("Pair [first=1, second=Foobar]", new Pair<Integer, String>(1, "Foobar").toString());
	}
	
	/** */
	@Test
	public void testEqualsAndHash() {
		assertFalse(new Pair<Integer, String>(1, "Foobar").equals(null));
		assertFalse(new Pair<Integer, String>(1, "Foobar").equals("Foobar"));
		assertTrue(new Pair<Integer, String>(1, null).equals(new Pair<Integer, String>(1, null)));
		Set<Pair<Integer, String>> set = new HashSet<Pair<Integer, String>>();
		set.add(new Pair<Integer, String>(1, "Foobar"));
		set.add(new Pair<Integer, String>(2, "Baz"));
		assertTrue(set.contains(new Pair<Integer, String>(1, "Foobar")));
		assertFalse(set.contains(new Pair<Integer, String>(2, "Foobar")));
	}
}