Package util

Source Code of util.CollectUtils

/*
* Danet GmbH
* Beratung und Software-Entwicklung
* Gesch�ftstelle AN
*
* $Id: CollectUtils.java 2548 2007-10-22 14:00:52Z  $
*
* $Log$
* Revision 1.1  2002/11/05 10:16:49  schlue
* Tracked map added.
*
*
*/
package util;

import java.util.HashMap;
import java.util.Map;

import de.danet.an.util.CollectionsUtil;

import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;

/**
* Tests the CollectionsUtil
* @version 1.0
*/
public class CollectUtils extends TestCase {
    /**
     * Konstruktor zum Erzeugen eines TestCase
     * @param name a <code>String</code> value
     */
    public CollectUtils(String name) {
  super (name);
    }

    /**
     * Assembling the test suite
     * @return a <code>Test</code> value
     * @exception Exception if an error occurs
     */
    public static Test suite() throws Exception {
        TestSuite suite = new TestSuite();
     suite.addTest(new CollectUtils("createMap"));
     suite.addTest(new CollectUtils("modifyMap"));
 
        return suite;
    }
 
    /**
     * Test creation of a tracked map.
     * @exception Exception if an error occurs
     */
    public void createMap() throws Exception {
  Map map = new HashMap();
  assertTrue(!CollectionsUtil.isTracked(map));
  boolean noValidModificationTest = false;
  try {
      CollectionsUtil.hasBeenModified(map);
  } catch(IllegalArgumentException ia) {
      noValidModificationTest = true;
  }
  assertTrue(noValidModificationTest);
  map = CollectionsUtil.trackedMap(map);
  assertTrue(CollectionsUtil.isTracked(map));
  assertTrue(!CollectionsUtil.hasBeenModified(map));
    }

    /**
     * Test modification of a tracked map.
     * @exception Exception if an error occurs
     */
    public void modifyMap() throws Exception {
  Map map = new HashMap();
  map.put("a", "A");
  map.put("b", "B");
  map.put("c", "C");
  map = CollectionsUtil.trackedMap(map);
  assertTrue(!CollectionsUtil.hasBeenModified(map));
  map.put("a", "A");
  assertTrue(CollectionsUtil.hasBeenModified(map));
  assertTrue(!CollectionsUtil.hasBeenModified(map));
  map.remove("b");
  assertTrue(CollectionsUtil.hasBeenModified(map));
  assertTrue(!CollectionsUtil.hasBeenModified(map));
  assertTrue(!map.containsKey("b"));
  assertTrue(map.containsKey("c"));
  assertTrue(map.containsValue("C"));
  assertTrue(!map.containsValue("c"));
  assertTrue(map.size() == 2);
  Map map2 = new HashMap();
  map2.put("1", "eins");
  map2.put("2", "zwei");
  map2.put("3", "drei");
  assertTrue(!CollectionsUtil.hasBeenModified(map));
  map.putAll(map2);
  assertTrue(CollectionsUtil.hasBeenModified(map));
  assertTrue(!CollectionsUtil.hasBeenModified(map));
  assertTrue(map.size() == 5);
  try {
      map.putAll(null);
  } catch (NullPointerException exc) {
  }
  assertTrue(!CollectionsUtil.hasBeenModified(map));
  map.clear();
  assertTrue(CollectionsUtil.hasBeenModified(map));
  assertTrue(!CollectionsUtil.hasBeenModified(map));
  assertTrue(map.size() == 0);
    }
}
TOP

Related Classes of util.CollectUtils

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.