Author: nextgens
Date: 2006-12-23 14:23:34 +0000 (Sat, 23 Dec 2006)
New Revision: 11518
Added:
trunk/freenet/test/freenet/config/ConfigTest.java
Modified:
trunk/freenet/src/freenet/config/Config.java
Log:
Use a LinkedHashMap insteed of a HashMap for freenet.config.Config; Add a basic
junit test for that class
Modified: trunk/freenet/src/freenet/config/Config.java
===================================================================
--- trunk/freenet/src/freenet/config/Config.java 2006-12-23 14:23:30 UTC
(rev 11517)
+++ trunk/freenet/src/freenet/config/Config.java 2006-12-23 14:23:34 UTC
(rev 11518)
@@ -4,6 +4,7 @@
package freenet.config;
import java.util.HashMap;
+import java.util.LinkedHashMap;
/** Global configuration object for a node. SubConfig's register here.
* Handles writing to a file etc.
@@ -13,7 +14,7 @@
protected final HashMap configsByPrefix;
public Config() {
- configsByPrefix = new HashMap();
+ configsByPrefix = new LinkedHashMap();
}
public void register(SubConfig sc) {
Added: trunk/freenet/test/freenet/config/ConfigTest.java
===================================================================
--- trunk/freenet/test/freenet/config/ConfigTest.java
(rev 0)
+++ trunk/freenet/test/freenet/config/ConfigTest.java 2006-12-23 14:23:34 UTC
(rev 11518)
@@ -0,0 +1,69 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+package freenet.config;
+
+import freenet.config.Config;
+import freenet.config.SubConfig;
+import junit.framework.TestCase;
+
+/**
+ * Test case for the {@link freenet.config.Config} class.
+ *
+ * @author Florent Daignière <nextgens at freenetproject.org>
+ */
+public class ConfigTest extends TestCase {
+ Config conf;
+ SubConfig sc;
+
+ public ConfigTest(String name) {
+ super(name);
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ conf = new Config();
+ sc = new SubConfig("testing", conf);
+ }
+
+ public void testConfig() {
+ assertNotNull(new Config());
+ }
+
+ public void testRegister() {
+ /* test if we can register */
+ assertNotNull(new SubConfig("testing1%?~#{[|`^@??&?", conf));
+
+ /* test if it prevents multiple registrations */
+ try{
+ conf.register(sc);
+ }catch (IllegalArgumentException ie){
+ return;
+ }
+ fail();
+ }
+
+ public void testGetConfigs() {
+ assertNotNull(conf.getConfigs());
+ assertFalse(new Config().getConfigs().equals(conf));
+ assertEquals(1 , conf.getConfigs().length);
+ assertSame(sc, conf.getConfigs()[0]);
+ }
+
+ public void testGet() {
+ assertSame(sc, conf.get("testing"));
+ }
+
+}