/**
 * License Agreement.
 *
 *  JBoss RichFaces - Ajax4jsf Component Library
 *
 * Copyright (C) 2007  Exadel, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License version 2.1 as published by the Free Software Foundation.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA
 */

package org.richfaces.renderkit;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;

import org.richfaces.model.ListRowKey;

import junit.framework.TestCase;

/**
 * 
 * <br /><br />
 * 
 * Created 22.08.2007
 * @author Nick Belaevski
 * @since 3.1
 */

public class TreeRowKeyComparatorTest extends TestCase {

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
	}

	public void testComparator() throws Exception {
		Comparator comparator = TreeRendererBase.treeRowKeyComparator;
	
		ListRowKey emptyKey = new ListRowKey();
		ListRowKey key = new ListRowKey(new Integer(23));
		ListRowKey eqkey = new ListRowKey(new Integer(23));
		ListRowKey supKey = new ListRowKey(new ListRowKey(new Integer(23)), new Integer(34));
	
		ListRowKey predLongKey = new ListRowKey(new ListRowKey(new ListRowKey(new Integer(22)), new Integer(0)), new Integer(8));
		ListRowKey predKey = new ListRowKey(new Integer(22));
		ListRowKey predSupKey = new ListRowKey(new ListRowKey(new Integer(22)), new Integer(34));
		ListRowKey succKey = new ListRowKey(new ListRowKey(new Integer(25)), new Integer(34));
		ListRowKey succSupKey = new ListRowKey(new ListRowKey(new ListRowKey(new Integer(25)), new Integer(34)), new Integer(2));
	
		ArrayList list = new ArrayList();
		list.add(eqkey);
		list.add(succSupKey);
		list.add(succKey);
		list.add(predSupKey);
		list.add(predKey);
		list.add(supKey);
		list.add(key);
		list.add(null);
		list.add(emptyKey);
		list.add(null);
		list.add(predLongKey);
		
		Collections.sort(list, comparator);
		
		Iterator iterator = list.iterator();
		assertNull(iterator.next());
		assertNull(iterator.next());
		assertEquals(emptyKey, iterator.next());
		assertEquals(predKey, iterator.next());
		assertEquals(predLongKey, iterator.next());
		assertEquals(predSupKey, iterator.next());
		assertEquals(eqkey, iterator.next());
		assertEquals(key, iterator.next());
		assertEquals(supKey, iterator.next());
		assertEquals(succKey, iterator.next());
		assertEquals(succSupKey, iterator.next());
	
	}
}
