
package com.exedio.cope.lib;

import java.io.IOException;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import junit.framework.TestCase;

public abstract class AbstractLibTest extends TestCase
{
	
	public AbstractLibTest()
	{}
	
	protected void assertUnmodifiable(final Collection c)
	{
		try
		{
			c.add(new Object());
			fail("should have thrown UnsupportedOperationException");
		}
		catch(UnsupportedOperationException e) {}
		try
		{
			c.addAll(Collections.singleton(new Object()));
			fail("should have thrown UnsupportedOperationException");
		}
		catch(UnsupportedOperationException e) {}
		
		if(!c.isEmpty())
		{
			final Object o = c.iterator().next();
			try
			{
				c.clear();
				fail("should have thrown UnsupportedOperationException");
			}
			catch(UnsupportedOperationException e) {}
			try
			{
				c.remove(o);
				fail("should have thrown UnsupportedOperationException");
			}
			catch(UnsupportedOperationException e) {}
			try
			{
				c.removeAll(Collections.singleton(o));
				fail("should have thrown UnsupportedOperationException");
			}
			catch(UnsupportedOperationException e) {}
			try
			{
				c.retainAll(Collections.EMPTY_LIST);
				fail("should have thrown UnsupportedOperationException");
			}
			catch(UnsupportedOperationException e) {}

			final Iterator iterator = c.iterator();
			try
			{
				iterator.remove();
				fail("should have thrown UnsupportedOperationException");
			}
			catch(UnsupportedOperationException e) {}
		}
	}
	
	protected Set toSet(final Collection collection)
	{
		return new HashSet(collection);
	}

	protected Set set()
	{
		return Collections.EMPTY_SET;
	}

	protected Set set(final Object o)
	{
		return Collections.singleton(o);
	}

	protected Set set(final Object o1, final Object o2)
	{
		return new HashSet(Arrays.asList(new Object[]{o1, o2}));
	}

	protected Set set(final Object o1, final Object o2, final Object o3)
	{
		return new HashSet(Arrays.asList(new Object[]{o1, o2, o3}));
	}

	protected List list()
	{
		return Collections.EMPTY_LIST;
	}

	protected List list(final Object o)
	{
		return Collections.singletonList(o);
	}
	
	protected List list(final Object o1, final Object o2)
	{
		return Arrays.asList(new Object[]{o1, o2});
	}
	
	protected List list(final Object o1, final Object o2, final Object o3)
	{
		return Arrays.asList(new Object[]{o1, o2, o3});
	}
	
	protected Object waitForKey(final Object o)
	{
		System.out.println("WAITING FOR KEY");
		try
		{
			System.in.read();
		}
		catch(IOException e)
		{
			throw new SystemException(e);
		}
		return o;
	}

	protected void waitForKey()
	{
		waitForKey(null);
	}

}

@@ -2474,32 +2474,355 @@
  o2, o3%7D);%0A%09%7D%0A%09%0A
+%09protected List list(final Object o1, final Object o2, final Object o3, final Object o4)%0A%09%7B%0A%09%09return Arrays.asList(new Object%5B%5D%7Bo1, o2, o3, o4%7D);%0A%09%7D%0A%09%0A%09protected List list(final Object o1, final Object o2, final Object o3, final Object o4, final Object o5)%0A%09%7B%0A%09%09return Arrays.asList(new Object%5B%5D%7Bo1, o2, o3, o4, o5%7D);%0A%09%7D%0A%09%0A
 %09protected Objec

add list methods