package nl.siegmann.ehcachetag.cachetagmodifier;

import junit.framework.Assert;

import nl.siegmann.ehcachetag.cachetagmodifier.CompositeCacheKey;

import org.junit.Test;

public class CompositeCacheKeyTest {

	@Test
	public void test1() {
		CompositeCacheKey cacheKey1 = new CompositeCacheKey("foo");
		CompositeCacheKey cacheKey2 = new CompositeCacheKey("foo", "bar");
		
		Assert.assertFalse(cacheKey1.hashCode() == cacheKey2.hashCode());
		Assert.assertFalse(cacheKey1.equals(cacheKey2));
	}
	
	
	@Test
	public void test_swap() {
		CompositeCacheKey cacheKey1 = new CompositeCacheKey("foo", "bar");
		CompositeCacheKey cacheKey2 = new CompositeCacheKey("bar", "foo");
		
		Assert.assertFalse(cacheKey1.hashCode() == cacheKey2.hashCode());
		Assert.assertFalse(cacheKey1.equals(cacheKey2));
	}
	
	
	@Test
	public void test2() {
		CompositeCacheKey cacheKey1 = new CompositeCacheKey("bar", "foo");
		CompositeCacheKey cacheKey2 = new CompositeCacheKey("bar", "foo");
		
		Assert.assertTrue(cacheKey1.hashCode() == cacheKey2.hashCode());
		Assert.assertTrue(cacheKey1.equals(cacheKey2));
	}

	@Test
	public void test_hash_null_element() {
		// given
		CompositeCacheKey key = new CompositeCacheKey("hi", null, "bye");
		
		// when
		key.hashCode();
		
		// then
		// just checking that a null value doesn't throw any exceptions
	}

	@Test
	public void test_toString_null_value() {
		// given
		CompositeCacheKey key = new CompositeCacheKey("hi", null, "bye");
		
		// when
		String toStringValue = key.toString();
		
		// then
		Assert.assertEquals("nl.siegmann.ehcachetag.cachetagmodifier.CompositeCacheKey@62d13a01[keyComponents={hi,<null>,bye}]", toStringValue);
	}
}

@@ -1541,129 +1541,146 @@
 sert
-Equals(%22nl.siegmann.ehcachetag.cachetagmodifier.CompositeCacheKey@62d13a01%5BkeyComponents=%7Bhi,%3Cnull%3E,bye%7D%5D%22, toStringValue
+True(toStringValue.contains(%22null%22));%0A%09%09Assert.assertTrue(toStringValue.contains(%22hi%22));%0A%09%09Assert.assertTrue(toStringValue.contains(%22bye%22)
 );%0A%09

fix unit test