summaryrefslogtreecommitdiffstats
path: root/prefs/src
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-01-09 17:50:54 -0800
committerThe Android Open Source Project <initial-contribution@android.com>2009-01-09 17:50:54 -0800
commita0881d052ee72e3f7e773374e9b1aa75fbd6be4c (patch)
tree8a9462436077d0d906368cb21f521f1bf8a25500 /prefs/src
parentdd828f42a5c83b4270d4fbf6fce2da1878f1e84a (diff)
downloadlibcore-a0881d052ee72e3f7e773374e9b1aa75fbd6be4c.zip
libcore-a0881d052ee72e3f7e773374e9b1aa75fbd6be4c.tar.gz
libcore-a0881d052ee72e3f7e773374e9b1aa75fbd6be4c.tar.bz2
auto import from //branches/cupcake/...@125939
Diffstat (limited to 'prefs/src')
-rw-r--r--prefs/src/test/java/java/util/prefs/FilePreferencesFactoryTestImpl.java44
-rw-r--r--prefs/src/test/java/java/util/prefs/FilePreferencesTestImpl.java236
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java3514
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AllTests.java2
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/BackingStoreExceptionTest.java64
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java116
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java79
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockNodeChangeListener.java59
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferenceChangeListener.java16
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferencesFactory.java42
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeEventTest.java83
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeListenerTest.java34
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeEventTest.java109
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeListenerTest.java19
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesFactoryTest.java34
-rw-r--r--prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java1047
-rw-r--r--prefs/src/test/java/tests/prefs/AllTests.java2
17 files changed, 1998 insertions, 3502 deletions
diff --git a/prefs/src/test/java/java/util/prefs/FilePreferencesFactoryTestImpl.java b/prefs/src/test/java/java/util/prefs/FilePreferencesFactoryTestImpl.java
deleted file mode 100644
index bb6f2dd..0000000
--- a/prefs/src/test/java/java/util/prefs/FilePreferencesFactoryTestImpl.java
+++ /dev/null
@@ -1,44 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.util.prefs;
-
-/**
- * Default implementation of <code>PreferencesFactory</code> for Linux
- * platform, using file system as back end.
- *
- * @since 1.4
- */
-class FilePreferencesFactoryTestImpl implements PreferencesFactory {
- // user root preferences
- private static final Preferences USER_ROOT = new FilePreferencesTestImpl(true);
-
- // system root preferences
- private static final Preferences SYSTEM_ROOT = new FilePreferencesTestImpl(false);
-
- public FilePreferencesFactoryTestImpl() {
- super();
- }
-
- public Preferences userRoot() {
- return USER_ROOT;
- }
-
- public Preferences systemRoot() {
- return SYSTEM_ROOT;
- }
-
-}
diff --git a/prefs/src/test/java/java/util/prefs/FilePreferencesTestImpl.java b/prefs/src/test/java/java/util/prefs/FilePreferencesTestImpl.java
deleted file mode 100644
index b31563b..0000000
--- a/prefs/src/test/java/java/util/prefs/FilePreferencesTestImpl.java
+++ /dev/null
@@ -1,236 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package java.util.prefs;
-
-import java.io.File;
-import java.io.FilenameFilter;
-import java.security.AccessController;
-import java.security.PrivilegedAction;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.Properties;
-import java.util.Set;
-
-import org.apache.harmony.prefs.internal.nls.Messages;
-
-/**
- * Default implementation of <code>AbstractPreferences</code> for Linux platform,
- * using file system as back end.
- *
- * TODO some sync mechanism with backend, Performance - check file edit date
- *
- * @since 1.4
- */
-class FilePreferencesTestImpl extends AbstractPreferences {
-
- /*
- * --------------------------------------------------------------
- * Class fields
- * --------------------------------------------------------------
- */
-
- //prefs file name
- private static final String PREFS_FILE_NAME = "prefs.xml"; //$NON-NLS-1$
-
- //home directory for user prefs
- private static String USER_HOME;
-
- //home directory for system prefs
- private static String SYSTEM_HOME;
-
- /*
- * --------------------------------------------------------------
- * Class initializer
- * --------------------------------------------------------------
- */
- static {
- AccessController.doPrivileged(new PrivilegedAction<Void>() {
- public Void run() {
- USER_HOME = System.getProperty("java.io.tmpdir") + "/.userPrefsTest";//$NON-NLS-1$ //$NON-NLS-2$
- SYSTEM_HOME = System.getProperty("java.io.tmpdir") + "/.systemPrefsTest";//$NON-NLS-1$//$NON-NLS-2$
- return null;
- }
-
- });
- }
-
- /*
- * --------------------------------------------------------------
- * Instance fields
- * --------------------------------------------------------------
- */
-
- //file path for this preferences node
- private String path;
-
- //internal cache for prefs key-value pair
- private Properties prefs;
-
- //file represents this preferences node
- private File prefsFile;
-
- //parent dir for this preferences node
- private File dir;
-
- //cache for removed prefs key-value pair
- private Set<String> removed = new HashSet<String>();
-
- //cache for updated prefs key-value pair
- private Set<String> updated = new HashSet<String>();
-
- /*
- * --------------------------------------------------------------
- * Constructors
- * --------------------------------------------------------------
- */
-
- /**
- * Construct root <code>FilePreferencesTestImpl</code> instance, construct
- * user root if userNode is true, system root otherwise
- */
- FilePreferencesTestImpl(boolean userNode) {
- super(null, ""); //$NON-NLS-1$
- this.userNode = userNode;
- path = userNode ? USER_HOME : SYSTEM_HOME;
- initPrefs();
- }
-
- /**
- * Construct a prefs using given parent and given name
- */
- private FilePreferencesTestImpl(AbstractPreferences parent, String name) {
- super(parent, name);
- path = ((FilePreferencesTestImpl) parent).path + File.separator + name;
- initPrefs();
- }
-
- private void initPrefs() {
- dir = new File(path);
- newNode = (AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
- public Boolean run() {
- return Boolean.valueOf(!dir.exists());
- }
- })).booleanValue();
- prefsFile = new File(path + File.separator + PREFS_FILE_NAME);
- prefs = XMLParser.loadFilePrefs(prefsFile);
- }
-
- @Override
- protected String[] childrenNamesSpi() throws BackingStoreException {
- String[] names = AccessController
- .doPrivileged(new PrivilegedAction<String[]>() {
- public String[] run() {
- return dir.list(new FilenameFilter() {
- public boolean accept(File parent, String name) {
- return new File(path + File.separator + name).isDirectory();
- }
- });
-
- }
- });
- if (null == names) {// file is not a directory, exception case
- // prefs.3=Cannot get children names for {0}!
- throw new BackingStoreException(
- Messages.getString("prefs.3", toString())); //$NON-NLS-1$
- }
- return names;
- }
-
- @Override
- protected AbstractPreferences childSpi(String name) {
- FilePreferencesTestImpl child = new FilePreferencesTestImpl(this, name);
- return child;
- }
-
- @Override
- protected void flushSpi() throws BackingStoreException {
- try {
- //if removed, return
- if(isRemoved()){
- return;
- }
- // reload
- Properties currentPrefs = XMLParser.loadFilePrefs(prefsFile);
- // merge
- Iterator<String> it = removed.iterator();
- while (it.hasNext()) {
- currentPrefs.remove(it.next());
- }
- removed.clear();
- it = updated.iterator();
- while (it.hasNext()) {
- Object key = it.next();
- currentPrefs.put(key, prefs.get(key));
- }
- updated.clear();
- // flush
- prefs = currentPrefs;
- XMLParser.flushFilePrefs(prefsFile, prefs);
- } catch (Exception e) {
- throw new BackingStoreException(e);
- }
- }
-
- @Override
- protected String getSpi(String key) {
- try {
- if (null == prefs) {
- prefs = XMLParser.loadFilePrefs(prefsFile);
- }
- return prefs.getProperty(key);
- } catch (Exception e) {// if Exception happened, return null
- return null;
- }
- }
-
- @Override
- protected String[] keysSpi() throws BackingStoreException {
- return prefs.keySet().toArray(new String[0]);
- }
-
- @Override
- protected void putSpi(String name, String value) {
- prefs.setProperty(name, value);
- updated.add(name);
- }
-
- @Override
- protected void removeNodeSpi() throws BackingStoreException {
- boolean removeSucceed = (AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
- public Boolean run() {
- prefsFile.delete();
- return Boolean.valueOf(dir.delete());
- }
- })).booleanValue();
- if (!removeSucceed) {
- // prefs.4=Cannot remove {0}!
- throw new BackingStoreException(Messages.getString("prefs.4", toString())); //$NON-NLS-1$
- }
- }
-
- @Override
- protected void removeSpi(String key) {
- prefs.remove(key);
- updated.remove(key);
- removed.add(key);
- }
-
- @Override
- protected void syncSpi() throws BackingStoreException {
- flushSpi();
- }
-}
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java
index 9fbe80d..f53a579 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AbstractPreferencesTest.java
@@ -1,2624 +1,1468 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
+ * Copyright (C) 2008 The Android Open Source Project
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
*
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
*/
package org.apache.harmony.prefs.tests.java.util.prefs;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargetClass;
+
+import junit.framework.TestCase;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
import java.util.prefs.AbstractPreferences;
import java.util.prefs.BackingStoreException;
+import java.util.prefs.InvalidPreferencesFormatException;
import java.util.prefs.NodeChangeEvent;
import java.util.prefs.NodeChangeListener;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
-
-import junit.framework.TestCase;
-
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.xml.sax.EntityResolver;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
-
-/**
- * TODO: refine this test to adapt all implementations
- *
- */
@TestTargetClass(AbstractPreferences.class)
public class AbstractPreferencesTest extends TestCase {
AbstractPreferences pref;
- static AbstractPreferences root = null;
+ static AbstractPreferences root = (AbstractPreferences) Preferences.userRoot();
+
+ static final String nodeName = "mock";
static AbstractPreferences parent = null;
- final static String longKey;
-
- final static String longValue;
-
- final static String longName;
-
- MockNodeChangeListener nl;
-
- MockPreferenceChangeListener pl;
-
- static {
- StringBuffer key = new StringBuffer(Preferences.MAX_KEY_LENGTH);
- for (int i = 0; i < Preferences.MAX_KEY_LENGTH; i++) {
- key.append('a');
- }
- longKey = key.toString();
- StringBuffer value = new StringBuffer(Preferences.MAX_VALUE_LENGTH);
- for (int i = 0; i < Preferences.MAX_VALUE_LENGTH; i++) {
- value.append('a');
- }
- longValue = value.toString();
-
- StringBuffer name = new StringBuffer(Preferences.MAX_NAME_LENGTH);
- for (int i = 0; i < Preferences.MAX_NAME_LENGTH; i++) {
- name.append('a');
- }
- longName = name.toString();
- }
-
protected void setUp() throws Exception {
super.setUp();
- root = (AbstractPreferences) Preferences.userRoot();
- parent = (AbstractPreferences) Preferences
- .userNodeForPackage(Preferences.class);
- // FIXME: change here is dangerous
- // pref = new MockAbstractPreferences((AbstractPreferences) parent,
- // "mock");
-
- pref = (AbstractPreferences) parent.node("mock");
+
+ parent = (AbstractPreferences) Preferences.userNodeForPackage(this.getClass());
+/*
+ String str[] = parent.childrenNames();
+ for (int i = 0; i < str.length; i++) {
+ System.out.print(str[i] + " ");
+ }
+ System.out.println();
+/**/
+ pref = (AbstractPreferences) parent.node(nodeName);
}
protected void tearDown() throws Exception {
- try {
- if (pref instanceof MockAbstractPreferences) {
- ((MockAbstractPreferences) pref)
- .setResult(MockAbstractPreferences.NORMAL);
- }
- pref.removeNode();
- } catch (Exception e) {
+/* String str[] = parent.childrenNames();
+ for (int i = 0; i < str.length; i++) {
+ System.out.print(str[i] + " ");
}
+ System.out.println();/**/
+ parent.removeNode();
super.tearDown();
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "AbstractPreferences",
- methodArgs = {java.util.prefs.AbstractPreferences.class, java.lang.String.class}
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "toString",
+ args = {}
+ )
+ public void testToString() {
+ assertTrue(pref.toString().contains(nodeName));
+ }
+
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Tests putSpi indirectly",
+ method = "put",
+ args = {java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Tests putSpi indirectly",
+ method = "putSpi",
+ args = {java.lang.String.class, java.lang.String.class}
)
})
- public void testConstructor() throws BackingStoreException {
+ public void testPut() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.flush();
+
+ assertEquals("String", pref.get("Value", ":"));
+
try {
- pref = new MockAbstractPreferences(
- (AbstractPreferences) Preferences.userRoot(), "mo/ck");
- fail();
- } catch (IllegalArgumentException e) {
+ pref.put(null, "Exception");
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
}
- try {
- pref = new MockAbstractPreferences(null, "mock");
- fail();
- } catch (IllegalArgumentException e) {
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
}
+
try {
- new MockAbstractPreferences(null, " ");
- fail();
+ pref.put(new String(sb), "Exception");
+ fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
+ //expected
+ }
+
+ sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_VALUE_LENGTH + 1; i++) {
+ sb.append('c');
}
+
try {
- new MockAbstractPreferences(pref, "");
- fail();
+ pref.put("DoubleValue", new String(sb));
+ fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
+ //expected
}
+
+ pref.removeNode();
+
try {
- new MockAbstractPreferences(pref, null);
- fail();
- } catch (NullPointerException e) {
- }
- if (!(pref instanceof MockAbstractPreferences)) {
- return;
- }
- new MockAbstractPreferences(pref, " ");
-
- Preferences p2 = new MockAbstractPreferences(null, "");
- assertNotSame(p2, Preferences.systemRoot());
- assertNotSame(p2, Preferences.userRoot());
- assertFalse(p2.isUserNode());
-
- p2 = new MockAbstractPreferences((AbstractPreferences) Preferences
- .userRoot(), "mock");
- assertNotSame(p2, pref);
- p2.removeNode();
- }
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "!Constants",
- targets = {
- @TestTarget(
- methodName = "absolutePath",
- methodArgs = {}
- )
- })
- public void testProtectedFields() throws BackingStoreException {
- if (!(pref instanceof MockAbstractPreferences)) {
- return;
+ pref.put("DoubleValue", "Exception");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
- MockAbstractPreferences p = new MockAbstractPreferences(pref, "newNode");
- assertFalse(p.getNewNode());
- assertSame(p.getLock().getClass(), Object.class);
-
- p = (MockAbstractPreferences) pref.node("child");
- assertTrue(p.getNewNode());
-
- p = (MockAbstractPreferences) ((MockAbstractPreferences) pref)
- .publicChildSpi("child2");
- assertTrue(p.getNewNode());
- }
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "toString",
- methodArgs = {}
- )
- })
- public void testToString() {
- assertEquals("User Preference Node: " + pref.absolutePath(), pref
- .toString());
-
- pref = new MockAbstractPreferences((AbstractPreferences) Preferences
- .systemRoot(), "mock");
- assertEquals("System Preference Node: " + pref.absolutePath(), pref
- .toString());
- }
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "absolutePath",
- methodArgs = {}
- )
- })
- public void testAbsolutePath() {
- assertEquals("/java/util/prefs/mock", pref.absolutePath());
-
- pref = new MockAbstractPreferences(pref, " ");
- assertEquals("/java/util/prefs/mock/ ", pref.absolutePath());
- }
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Exceptions checking missed.",
- targets = {
- @TestTarget(
- methodName = "childrenNames",
- methodArgs = {}
- )
- })
- public void testChildrenNames() throws BackingStoreException {
- assertEquals(0, pref.childrenNames().length);
-
- Preferences child1 = pref.node("child1");
-
- pref.node("child2");
- pref.node("child3");
- child1.node("subchild1");
-
- assertSame(pref, child1.parent());
- assertEquals(3, pref.childrenNames().length);
- assertEquals("child1", pref.childrenNames()[0]);
- assertEquals(1, child1.childrenNames().length);
- assertEquals("subchild1", child1.childrenNames()[0]);
- }
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Exceptions checking missed.",
- targets = {
- @TestTarget(
- methodName = "clear",
- methodArgs = {}
- )
- })
- public void testClear() throws BackingStoreException {
- pref.put("testClearKey", "testClearValue");
- pref.put("testClearKey1", "testClearValue1");
- assertEquals("testClearValue", pref.get("testClearKey", null));
- assertEquals("testClearValue1", pref.get("testClearKey1", null));
- pref.clear();
- assertNull(pref.get("testClearKey", null));
- assertNull(pref.get("testClearKey1", null));
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "get",
- methodArgs = {java.lang.String.class, java.lang.String.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "getSpi tested indirectly.",
+ method = "get",
+ args = {java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "getSpi tested indirectly.",
+ method = "getSpi",
+ args = {java.lang.String.class}
)
})
public void testGet() throws BackingStoreException {
- assertNull(pref.get("", null));
- assertEquals("default", pref.get("key", "default"));
- assertNull(pref.get("key", null));
- pref.put("testGetkey", "value");
- assertNull(pref.get("testGetKey", null));
- assertEquals("value", pref.get("testGetkey", null));
-
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+
+ assertEquals("String", pref.get("Value", ":"));
+ assertEquals("true", pref.get("BoolValue", ":"));
+ assertEquals("9.10938188E-31", pref.get("DoubleValue", null));
+
try {
- pref.get(null, "abc");
- fail();
+ pref.get(null, "Exception");
+ fail("NullPointerException expected");
} catch (NullPointerException e) {
+ //expected
}
- pref.get("", "abc");
- pref.get("key", null);
- pref.get("key", "");
- pref.putFloat("floatKey", 1.0f);
- assertEquals("1.0", pref.get("floatKey", null));
-
+
pref.removeNode();
+
try {
- pref.get("key", "abc");
- fail();
+ pref.get("DoubleValue", "Exception");
+ fail("IllegalStateException expected");
} catch (IllegalStateException e) {
- }
- try {
- pref.get(null, "abc");
- fail();
- } catch (NullPointerException e) {
+ //expected
}
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed.",
- targets = {
- @TestTarget(
- methodName = "getBoolean",
- methodArgs = {java.lang.String.class, boolean.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Indirectly checks removeSpi",
+ method = "remove",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Indirectly checks removeSpi",
+ method = "removeSpi",
+ args = {java.lang.String.class}
)
})
- public void testGetBoolean() {
+ public void testRemove() throws BackingStoreException {
+ String[] keyArray = new String[]{"Value", "DoubleValue", "LongValue", "IntValue"};
+ pref.put(keyArray[0], "String");
+ pref.putDouble(keyArray[1], new Double(9.10938188e-31));
+ pref.putLong(keyArray[2], new Long(Long.MIN_VALUE));
+ pref.putInt(keyArray[3], 299792458);
+ pref.node("New node");
+ pref.flush();
+
+ String[] str = pref.keys();
+ assertEquals(keyArray.length, str.length);
+ for(int i = 0; i < keyArray.length; i++) {
+ pref.remove(keyArray[i]);
+ str = pref.keys();
+ assertEquals(keyArray.length - i - 1, str.length);
+ }
+ assertEquals(1, pref.childrenNames().length);
+ pref.remove("New node");
+ assertEquals(1, pref.childrenNames().length);
+
+ pref.removeNode();
+
try {
- pref.getBoolean(null, false);
- fail();
- } catch (NullPointerException e) {
+ pref.remove("New node");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
-
- pref.put("testGetBooleanKey", "false");
- pref.put("testGetBooleanKey2", "value");
- assertFalse(pref.getBoolean("testGetBooleanKey", true));
- assertTrue(pref.getBoolean("testGetBooleanKey2", true));
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed.",
- targets = {
- @TestTarget(
- methodName = "putByteArray",
- methodArgs = {java.lang.String.class, byte[].class}
- )
- })
- public void testPutByteArray() {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "clear",
+ args = {}
+ )
+ public void testClear() throws BackingStoreException {
+ AbstractPreferences ap = (AbstractPreferences) pref.node("New node");
+ pref.putInt("IntValue", 33);
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertEquals(33, pref.getInt("IntValue", 22));
+ assertEquals(1, pref.childrenNames().length);
+ pref.clear();
+ assertFalse(pref.getBoolean("BoolValue", false));
+ assertEquals(22, pref.getInt("IntValue", 22));
+ assertEquals(1, pref.childrenNames().length);
+
+ pref.removeNode();
+
try {
- pref.putByteArray(null, new byte[0]);
- fail();
- } catch (NullPointerException e) {
+ pref.clear();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
+
try {
- pref.putByteArray("testPutByteArrayKey4", null);
- fail();
- } catch (NullPointerException e) {
+ ap.clear();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
+ }
- pref.putByteArray(longKey, new byte[0]);
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "putInt",
+ args = {java.lang.String.class, int.class}
+ )
+ public void testPutInt() throws BackingStoreException {
+ pref.putInt("IntValue", 299792458);
+ pref.flush();
+
+ assertEquals(299792458, pref.getInt("IntValue", new Integer(1)));
+
try {
- pref.putByteArray(longKey + "a", new byte[0]);
- fail();
- } catch (IllegalArgumentException e) {
+ pref.putInt(null, new Integer(1));
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
}
- byte[] longArray = new byte[(int) (Preferences.MAX_VALUE_LENGTH * 0.74)];
- byte[] longerArray = new byte[(int) (Preferences.MAX_VALUE_LENGTH * 0.75) + 1];
- pref.putByteArray(longKey, longArray);
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
+ }
+
try {
- pref.putByteArray(longKey, longerArray);
- fail();
+ pref.putInt(new String(sb), new Integer(1));
+ fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
+ //expected
}
-
- pref.putByteArray("testPutByteArrayKey", new byte[0]);
- assertEquals("", pref.get("testPutByteArrayKey", null));
- assertTrue(Arrays.equals(new byte[0], pref.getByteArray(
- "testPutByteArrayKey", null)));
-
- pref.putByteArray("testPutByteArrayKey3", new byte[] { 'a', 'b', 'c' });
- assertEquals("YWJj", pref.get("testPutByteArrayKey3", null));
- assertTrue(Arrays.equals(new byte[] { 'a', 'b', 'c' }, pref
- .getByteArray("testPutByteArrayKey3", null)));
- }
-
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed.",
- targets = {
- @TestTarget(
- methodName = "getByteArray",
- methodArgs = {java.lang.String.class, byte[].class}
- )
- })
- public void testGetByteArray() throws UnsupportedEncodingException {
+
+ pref.removeNode();
+
try {
- pref.getByteArray(null, new byte[0]);
- fail();
- } catch (NullPointerException e) {
+ pref.putInt("IntValue", new Integer(1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
- byte[] b64Array = new byte[] { 0x59, 0x57, 0x4a, 0x6a };// BASE64
- // encoding for
- // "abc"
-
- pref.put("testGetByteArrayKey", "abc=");
- pref.put("testGetByteArrayKey2", new String(b64Array));
- pref.put("invalidKey", "<>?");
- // assertTrue(Arrays.equals(new byte[0], p.getByteArray(
- // "testGetByteArrayKey", new byte[0])));
- assertTrue(Arrays.equals(new byte[] { 105, -73 }, pref.getByteArray(
- "testGetByteArrayKey", new byte[0])));
- assertTrue(Arrays.equals(new byte[] { 'a', 'b', 'c' }, pref
- .getByteArray("testGetByteArrayKey2", new byte[0])));
- assertTrue(Arrays.equals(new byte[0], pref.getByteArray("invalidKey",
- new byte[0])));
-
- pref.putByteArray("testGetByteArrayKey3", b64Array);
- pref.putByteArray("testGetByteArrayKey4", "abc".getBytes());
- assertTrue(Arrays.equals(b64Array, pref.getByteArray(
- "testGetByteArrayKey3", new byte[0])));
- assertTrue(Arrays.equals("abc".getBytes(), pref.getByteArray(
- "testGetByteArrayKey4", new byte[0])));
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed.",
- targets = {
- @TestTarget(
- methodName = "getDouble",
- methodArgs = {java.lang.String.class, double.class}
- )
- })
- public void testGetDouble() {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getInt",
+ args = {java.lang.String.class, int.class}
+ )
+ public void testGetInt() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putLong("LongValue", new Long(Long.MIN_VALUE));
+ pref.putInt("IntValue", 299792458);
+ pref.flush();
+
+ assertEquals(1, pref.getInt("Value", new Integer(1)));
+ assertEquals(1, pref.getInt("LongValue", new Integer(1)));
+ assertEquals(1, pref.getInt("DoubleValue", new Integer(1)));
+ assertEquals(299792458, pref.getInt("IntValue", new Integer(1)));
+
try {
- pref.getDouble(null, 0);
- fail();
+ pref.getInt(null, new Integer(1));
+ fail("NullPointerException expected");
} catch (NullPointerException e) {
+ //expected
}
-
- pref.put("testGetDoubleKey", "1");
- pref.put("testGetDoubleKey2", "value");
- pref.putDouble("testGetDoubleKey3", 1);
- pref.putInt("testGetDoubleKey4", 1);
- assertEquals(1.0, pref.getDouble("testGetDoubleKey", 0.0), 0);
- assertEquals(0.0, pref.getDouble("testGetDoubleKey2", 0.0), 0);
- assertEquals(1.0, pref.getDouble("testGetDoubleKey3", 0.0), 0);
- assertEquals(1.0, pref.getDouble("testGetDoubleKey4", 0.0), 0);
- }
-
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed.",
- targets = {
- @TestTarget(
- methodName = "getFloat",
- methodArgs = {java.lang.String.class, float.class}
- )
- })
- public void testGetFloat() {
+
+ pref.removeNode();
+
try {
- pref.getFloat(null, 0f);
- fail();
- } catch (NullPointerException e) {
+ pref.getInt("IntValue", new Integer(1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
- pref.put("testGetFloatKey", "1");
- pref.put("testGetFloatKey2", "value");
- assertEquals(1f, pref.getFloat("testGetFloatKey", 0f), 0); //$NON-NLS-1$
- assertEquals(0f, pref.getFloat("testGetFloatKey2", 0f), 0);
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed.",
- targets = {
- @TestTarget(
- methodName = "getInt",
- methodArgs = {java.lang.String.class, int.class}
- )
- })
- public void testGetInt() {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "putLong",
+ args = {java.lang.String.class, long.class}
+ )
+ public void testPutLong() throws BackingStoreException {
+ pref.putLong("LongValue", new Long(299792458));
+ pref.flush();
+
+ assertEquals(299792458L, pref.getLong("LongValue", new Long(1)));
+
try {
- pref.getInt(null, 0);
- fail();
+ pref.putLong(null, new Long(1));
+ fail("NullPointerException expected");
} catch (NullPointerException e) {
+ //expected
}
-
- pref.put("testGetIntKey", "1");
- pref.put("testGetIntKey2", "value");
- assertEquals(1, pref.getInt("testGetIntKey", 0));
- assertEquals(0, pref.getInt("testGetIntKey2", 0));
- }
-
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed.",
- targets = {
- @TestTarget(
- methodName = "getLong",
- methodArgs = {java.lang.String.class, long.class}
- )
- })
- public void testGetLong() {
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
+ }
+
try {
- pref.getLong(null, 0);
- fail();
- } catch (NullPointerException e) {
+ pref.putLong(new String(sb), new Long(1));
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
}
-
- pref.put("testGetLongKey", "1");
- pref.put("testGetLongKey2", "value");
- assertEquals(1, pref.getInt("testGetLongKey", 0));
- assertEquals(0, pref.getInt("testGetLongKey2", 0));
- }
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "isUserNode",
- methodArgs = {}
- )
- })
- public void testIsUserNode() {
- assertTrue(pref.isUserNode());
-
- pref = new MockAbstractPreferences((AbstractPreferences) Preferences
- .systemRoot(), "mock");
- assertFalse(pref.isUserNode());
- }
-
- // TODO, how to test the "stored defaults"
- // TODO, how to test the multi-thread
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Exceptions checking missed. Probably todo list reasonable for functional stress test.",
- targets = {
- @TestTarget(
- methodName = "keys",
- methodArgs = {}
- )
- })
- public void testKeys() throws BackingStoreException {
- assertEquals(0, pref.keys().length);
-
- pref.put("key0", "value");
- pref.put("key1", "value1");
- pref.put("key2", "value2");
- pref.put("key3", "value3");
-
- String[] keys = pref.keys();
- assertEquals(4, keys.length);
- for (int i = 0; i < keys.length; i++) {
- assertEquals(0, keys[i].indexOf("key"));
- assertEquals(4, keys[i].length());
+
+ pref.removeNode();
+
+ try {
+ pref.putLong("LongValue", new Long(1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "name",
- methodArgs = {}
- )
- })
- public void testName() {
- assertEquals("mock", pref.name());
-
- pref = new MockAbstractPreferences(pref, " ");
- assertEquals(" ", pref.name());
- }
-
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Functional test for keys with special symbols. No exceptions were checked.",
- targets = {
- @TestTarget(
- methodName = "put",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- ), @TestTarget(
- methodName = "keys",
- methodArgs = {}
- ), @TestTarget(
- methodName = "get",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- )
- })
- public void testCharCase() throws BackingStoreException {
- assertSame(pref.node("samechild"), pref.node("samechild"));
- assertNotSame(pref.node("sameChild"), pref.node("samechild"));
- assertNotSame(pref.node("child"), pref.node("Child"));
- assertNotSame(pref.node("child"), pref.node("Child"));
- assertNotSame(pref.node("child"), pref.node(" child"));
- String[] names = pref.childrenNames();
- assertEquals(5, names.length);
- for (int i = 0; i < names.length; i++) {
- String name = names[i];
- assertTrue("samechild".equals(name) || "sameChild".equals(name)
- || "child".equals(name) || "Child".equals(name)
- || " child".equals(name));
- }
-
- Preferences mock1 = pref.node("mock1");
- mock1.put("key", "1value");
- mock1.put("KEY", "2value");
- mock1.put("/K/E/Y", "7value");
- mock1.put("/K/E\\Y\\abc~@!#$%^&*(\\", "8value");
-
- assertEquals("8value", mock1.get("/K/E\\Y\\abc~@!#$%^&*(\\", null));
- assertNull(mock1.get("/k/e/y", null));
- assertEquals("7value", mock1.get("/K/E/Y", null));
- assertEquals("1value", mock1.get("key", null));
-
- String[] keys = mock1.keys();
- assertEquals(4, keys.length);
- for (int i = 0; i < keys.length; i++) {
- String key = keys[i];
- assertTrue("key".equals(key) || "KEY".equals(key)
- || "/K/E/Y".equals(key)
- || "/K/E\\Y\\abc~@!#$%^&*(\\".equals(key));
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getLong",
+ args = {java.lang.String.class, long.class}
+ )
+ public void testGetLong() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putLong("LongValue", new Long(Long.MIN_VALUE));
+ pref.putInt("IntValue", 299792458);
+ pref.flush();
+
+ assertEquals(1L, pref.getLong("Value", new Long(1)));
+ assertEquals(Long.MIN_VALUE, pref.getLong("LongValue", new Long(1)));
+ assertEquals(1L, pref.getLong("DoubleValue", new Long(1)));
+ assertEquals(299792458L, pref.getLong("IntValue", new Long(1)));
+
+ try {
+ pref.getLong(null, new Long(1));
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
+ }
+
+ pref.removeNode();
+
+ try {
+ pref.getLong("LongValue", new Long(1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "node",
- methodArgs = {java.lang.String.class}
- )
- })
- public void testNode() throws BackingStoreException {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "putBoolean",
+ args = {java.lang.String.class, boolean.class}
+ )
+ public void testPutBoolean() throws BackingStoreException {
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+
+ assertTrue(pref.getBoolean("BoolValue", false));
+
try {
- pref.node(null);
- fail();
+ pref.putBoolean(null, true);
+ fail("NullPointerException expected");
} catch (NullPointerException e) {
+ //expected
}
- try {
- pref.node("/java/util/prefs/");
- fail();
- } catch (IllegalArgumentException e) {
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
}
+
try {
- pref.node("/java//util/prefs");
- fail();
+ pref.putBoolean(new String(sb), true);
+ fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
+ //expected
}
+
+ pref.removeNode();
+
try {
- pref.node(longName + "a");
- fail();
- } catch (IllegalArgumentException e) {
+ pref.putBoolean("DoubleValue", true);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
- assertNotNull(pref.node(longName));
-
- assertSame(root, pref.node("/"));
-
- Preferences prefs = pref.node("/java/util/prefs");
- assertSame(prefs, parent);
-
- assertSame(pref, pref.node(""));
+ }
- if (!(pref instanceof MockAbstractPreferences)) {
- return;
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getBoolean",
+ args = {java.lang.String.class, boolean.class}
+ )
+ public void testGetBoolean() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+
+ assertFalse(pref.getBoolean("Value", false));
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertFalse(pref.getBoolean("DoubleValue", false));
+
+ try {
+ pref.getBoolean(null, true);
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
}
- MockAbstractPreferences child = (MockAbstractPreferences) ((MockAbstractPreferences) pref)
- .publicChildSpi("child");
- assertSame(child, pref.node("child"));
-
- Preferences child2 = pref.node("child2");
- assertSame(child2, ((MockAbstractPreferences) pref)
- .publicChildSpi("child2"));
-
- Preferences grandchild = pref.node("child/grandchild");
- assertSame(grandchild, child.childSpi("grandchild"));
- assertSame(grandchild, child.cachedChildrenImpl()[0]);
- grandchild.removeNode();
- assertNotSame(grandchild, pref.node("child/grandchild"));
-
- grandchild = pref.node("child3/grandchild");
- AbstractPreferences[] childs = ((MockAbstractPreferences) pref)
- .cachedChildrenImpl();
- Preferences child3 = child;
- for (int i = 0; i < childs.length; i++) {
- if (childs[i].name().equals("child3")) {
- child3 = childs[i];
- break;
- }
+
+ pref.removeNode();
+
+ try {
+ pref.getBoolean("DoubleValue", true);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
- assertSame(child3, grandchild.parent());
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "nodeExists",
- methodArgs = {java.lang.String.class}
- )
- })
- public void testNodeExists() throws BackingStoreException {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "putFloat",
+ args = {java.lang.String.class, float.class}
+ )
+ public void testPutFloat() throws BackingStoreException {
+ pref.putFloat("FloatValue", new Float(1.602e-19));
+ pref.flush();
+
+ assertEquals(new Float(1.602e-19), pref.getFloat("FloatValue", new Float(0.2)));
+
try {
- pref.nodeExists(null);
- fail();
+ pref.putFloat(null, new Float(0.1));
+ fail("NullPointerException expected");
} catch (NullPointerException e) {
+ //expected
}
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
+ }
+
try {
- pref.nodeExists("/java/util/prefs/");
- fail();
+ pref.putFloat(new String(sb), new Float(0.1));
+ fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
+ //expected
}
+
+ pref.removeNode();
+
try {
- pref.nodeExists("/java//util/prefs");
- fail();
- } catch (IllegalArgumentException e) {
+ pref.putFloat("FloatValue", new Float(0.1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
-
- assertTrue(pref.nodeExists("/"));
-
- assertTrue(pref.nodeExists("/java/util/prefs"));
-
- assertTrue(pref.nodeExists(""));
-
- assertFalse(pref.nodeExists("child"));
- Preferences grandchild = pref.node("child/grandchild");
- assertTrue(pref.nodeExists("child"));
- assertTrue(pref.nodeExists("child/grandchild"));
- grandchild.removeNode();
- assertTrue(pref.nodeExists("child"));
- assertFalse(pref.nodeExists("child/grandchild"));
- assertFalse(grandchild.nodeExists(""));
-
- assertFalse(pref.nodeExists("child2/grandchild"));
- pref.node("child2/grandchild");
- assertTrue(pref.nodeExists("child2/grandchild"));
- }
-
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "parent",
- methodArgs = {}
- )
- })
- public void testParent() {
- assertSame(parent, pref.parent());
- AbstractPreferences child1 = new MockAbstractPreferences(pref, "child1");
- assertSame(pref, child1.parent());
- assertNull(root.parent());
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Missed check for max values: MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH",
- targets = {
- @TestTarget(
- methodName = "put",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- )
- })
- public void testPut() throws BackingStoreException {
- pref.put("", "emptyvalue");
- assertEquals("emptyvalue", pref.get("", null));
- pref.put("testPutkey", "value1");
- assertEquals("value1", pref.get("testPutkey", null));
- pref.put("testPutkey", "value2");
- assertEquals("value2", pref.get("testPutkey", null));
-
- pref.put("", "emptyvalue");
- assertEquals("emptyvalue", pref.get("", null));
-
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getFloat",
+ args = {java.lang.String.class, float.class}
+ )
+ public void testGetFloat() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putFloat("FloatValue", new Float(-0.123));
+ pref.putInt("IntValue", 299792458);
+ pref.flush();
+
+ assertEquals(new Float(0.1), pref.getFloat("Value", new Float(0.1)));
+ assertEquals(new Float(-0.123), pref.getFloat("FloatValue", new Float(0.2)));
+ assertEquals(new Float(9.109382e-31), pref.getFloat("DoubleValue", new Float(2.14)));
+ assertEquals(new Float(2.99792448e8), pref.getFloat("IntValue", new Float(5)));
+
try {
- pref.put(null, "value");
- fail();
+ pref.getFloat(null, new Float(0.1));
+ fail("NullPointerException expected");
} catch (NullPointerException e) {
+ //expected
}
+
+ pref.removeNode();
+
try {
- pref.put("key", null);
- fail();
- } catch (NullPointerException e) {
+ pref.getFloat("FloatValue", new Float(0.1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
- pref.put(longKey, longValue);
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "putDouble",
+ args = {java.lang.String.class, double.class}
+ )
+ public void testPutDouble() throws BackingStoreException {
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.flush();
+
+ assertEquals(new Double(9.10938188e-31), pref.getDouble("DoubleValue", new Double(2.14)));
+
try {
- pref.put(longKey + 1, longValue);
- fail();
- } catch (IllegalArgumentException e) {
+ pref.putDouble(null, new Double(0.1));
+ fail("NullPointerException expected");
+ } catch (NullPointerException e) {
+ //expected
}
- try {
- pref.put(longKey, longValue + 1);
- fail();
- } catch (IllegalArgumentException e) {
+
+ int i;
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
}
-
- pref.removeNode();
+
try {
- pref.put(longKey, longValue + 1);
- fail();
+ pref.putDouble(new String(sb), new Double(0.1));
+ fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
+ //expected
}
-
+
+ pref.removeNode();
+
try {
- pref.put(longKey, longValue);
- fail();
+ pref.putDouble("DoubleValue", new Double(0.1));
+ fail("IllegalStateException expected");
} catch (IllegalStateException e) {
+ //expected
}
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "putBoolean",
- methodArgs = {java.lang.String.class, boolean.class}
- )
- })
- public void testPutBoolean() {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getDouble",
+ args = {java.lang.String.class, double.class}
+ )
+ public void testGetDouble() throws BackingStoreException {
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putBoolean("BoolValue", true);
+ pref.putInt("IntValue", 299792458);
+ pref.flush();
+
+ assertEquals(new Double(0.1), pref.getDouble("Value", new Double(0.1)));
+ assertEquals(new Double(0.2), pref.getDouble("BoolValue", new Double(0.2)));
+ assertEquals(new Double(9.10938188e-31), pref.getDouble("DoubleValue", new Double(2.14)));
+ assertEquals(new Double(2.99792458e8), pref.getDouble("IntValue", new Double(5)));
+
try {
- pref.putBoolean(null, false);
- fail();
+ pref.getDouble(null, new Double(0.1));
+ fail("NullPointerException expected");
} catch (NullPointerException e) {
+ //expected
}
- pref.putBoolean(longKey, false);
+
+ pref.removeNode();
+
try {
- pref.putBoolean(longKey + "a", false);
- fail();
- } catch (IllegalArgumentException e) {
+ pref.getDouble("DoubleValue", new Double(0.1));
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
- pref.putBoolean("testPutBooleanKey", false);
- assertEquals("false", pref.get("testPutBooleanKey", null));
- assertFalse(pref.getBoolean("testPutBooleanKey", true));
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "putDouble",
- methodArgs = {java.lang.String.class, double.class}
- )
- })
- public void testPutDouble() {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "putByteArray",
+ args = {java.lang.String.class, byte[].class}
+ )
+ public void testPutByteArray() throws BackingStoreException {
+ byte[] bArray = new byte[]{1, 2, 3, 4, 5};
+ byte[] array = null;
+ int i;
+ pref.putByteArray("Array", bArray);
+ pref.flush();
+
+ array = pref.getByteArray("Array", null);
+ assertEquals(bArray.length, array.length);
+ for(i = 0; i < bArray.length; i++) {
+ assertEquals(bArray[i], array[i]);
+ }
+
try {
- pref.putDouble(null, 3);
- fail();
+ pref.putByteArray(null, bArray);
+ fail("NullPointerException expected");
} catch (NullPointerException e) {
+ //expected
+ }
+
+ StringBuffer sb = new StringBuffer();
+
+ for (i = 0; i < Preferences.MAX_KEY_LENGTH + 1; i++) {
+ sb.append('c');
}
- pref.putDouble(longKey, 3);
+
try {
- pref.putDouble(longKey + "a", 3);
- fail();
+ pref.putByteArray(new String(sb), bArray);
+ fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
+ //expected
}
- pref.putDouble("testPutDoubleKey", 3);
- assertEquals("3.0", pref.get("testPutDoubleKey", null));
- assertEquals(3, pref.getDouble("testPutDoubleKey", 0), 0);
- }
-
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "putFloat",
- methodArgs = {java.lang.String.class, float.class}
- )
- })
- public void testPutFloat() {
+
+ bArray = new byte[Preferences.MAX_VALUE_LENGTH * 3 / 4 + 1];
+
try {
- pref.putFloat(null, 3f);
- fail();
- } catch (NullPointerException e) {
+ pref.putByteArray("Big array", bArray);
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
}
- pref.putFloat(longKey, 3f);
+
+ pref.removeNode();
+
try {
- pref.putFloat(longKey + "a", 3f);
- fail();
- } catch (IllegalArgumentException e) {
+ pref.putByteArray("Array", new byte[10]);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
- pref.putFloat("testPutFloatKey", 3f);
- assertEquals("3.0", pref.get("testPutFloatKey", null));
- assertEquals(3f, pref.getFloat("testPutFloatKey", 0), 0);
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "putInt",
- methodArgs = {java.lang.String.class, int.class}
- )
- })
- public void testPutInt() {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "getByteArray",
+ args = {java.lang.String.class, byte[].class}
+ )
+ public void testGetByteArray() throws BackingStoreException {
+ byte[] bArray = new byte[]{1, 2, 3, 4, 5};
+ byte[] tmp = new byte[]{5};
+ byte[] array = null;
+ int i;
+ pref.put("Value", "String");
+ pref.putDouble("DoubleValue", new Double(9.10938188e-31));
+ pref.putByteArray("Array", bArray);
+ pref.flush();
+
+ array = pref.getByteArray("Value", tmp);
+ assertEquals(tmp.length, array.length);
+ for(i = 0; i < tmp.length; i++) {
+ assertEquals(tmp[i], array[i]);
+ }
+
+ array = pref.getByteArray("DoubleValue", tmp);
+ assertEquals(tmp.length, array.length);
+ for(i = 0; i < tmp.length; i++) {
+ assertEquals(tmp[i], array[i]);
+ }
+
+ array = pref.getByteArray("Array", tmp);
+ assertEquals(bArray.length, array.length);
+ for(i = 0; i < bArray.length; i++) {
+ assertEquals(bArray[i], array[i]);
+ }
+
try {
- pref.putInt(null, 3);
- fail();
+ pref.getByteArray(null, tmp);
+ fail("NullPointerException expected");
} catch (NullPointerException e) {
+ //expected
}
- pref.putInt(longKey, 3);
+
+ pref.removeNode();
+
try {
- pref.putInt(longKey + "a", 3);
- fail();
- } catch (IllegalArgumentException e) {
+ pref.getByteArray("Array", tmp);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
- pref.putInt("testPutIntKey", 3);
- assertEquals("3", pref.get("testPutIntKey", null));
- assertEquals(3, pref.getInt("testPutIntKey", 0));
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed",
- targets = {
- @TestTarget(
- methodName = "putLong",
- methodArgs = {java.lang.String.class, long.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "keysSpi tested indirectly",
+ method = "keys",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "keysSpi tested indirectly",
+ method = "keysSpi",
+ args = {}
)
})
- public void testPutLong() {
- try {
- pref.putLong(null, 3L);
- fail();
- } catch (NullPointerException e) {
+ public void testKeys() throws BackingStoreException {
+ String[] keyArray = new String[]{"Value", "DoubleValue", "BoolValue", "IntValue"};
+ String nodeStr = "New node";
+ pref.node(nodeStr);
+ pref.put(keyArray[0], "String");
+ pref.putDouble(keyArray[1], new Double(9.10938188e-31));
+ pref.putBoolean(keyArray[2], true);
+ pref.putInt(keyArray[3], 299792458);
+ pref.flush();
+
+ String[] str = pref.keys();
+ assertEquals(keyArray.length, str.length);
+ for(int i = 0; i < str.length; i++) {
+ boolean flag = false;
+ for(int j = 0; j < keyArray.length; j++) {
+ if (str[i].compareTo(keyArray[j]) == 0) {
+ flag = true;
+ break;
+ }
+ }
+ assertTrue(str[i].compareTo(nodeStr) != 0);
+ assertTrue(flag);
}
- pref.putLong(longKey, 3L);
+
+ pref.removeNode();
+
try {
- pref.putLong(longKey + "a", 3L);
- fail();
- } catch (IllegalArgumentException e) {
+ pref.keys();
+ fail("IllegalStateException expected");
+ } catch(IllegalStateException e) {
+ //expected
}
- pref.putLong("testPutLongKey", 3L);
- assertEquals("3", pref.get("testPutLongKey", null));
- assertEquals(3L, pref.getLong("testPutLongKey", 0));
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "remove",
- methodArgs = {java.lang.String.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "BackingStoreException can not be checked. childrenNamesSpi checked indirectly.",
+ method = "childrenNames",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "BackingStoreException can not be checked. childrenNamesSpi checked indirectly.",
+ method = "childrenNamesSpi",
+ args = {}
)
})
- public void testRemove() throws BackingStoreException {
- pref.remove("key");
-
- pref.put("key", "value");
- assertEquals("value", pref.get("key", null));
- pref.remove("key");
- assertNull(pref.get("key", null));
-
- pref.remove("key");
-
+ public void testChildrenNames() throws BackingStoreException {
+ AbstractPreferences first = (AbstractPreferences) pref.node("First node");
+ AbstractPreferences second = (AbstractPreferences) pref.node("Second node");
+
+ assertEquals(2, pref.childrenNames().length);
+ assertEquals(0, first.childrenNames().length);
+ assertEquals(0, second.childrenNames().length);
+
+ second.removeNode();
+
try {
- pref.remove(null);
- } catch (NullPointerException e) {
+ second.childrenNames();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
pref.removeNode();
+
try {
- pref.remove("key");
- fail();
+ first.childrenNames();
+ fail("IllegalStateException expected");
} catch (IllegalStateException e) {
+ //expected
}
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Exceptions checking missed",
- targets = {
- @TestTarget(
- methodName = "removeNode",
- methodArgs = {}
- )
- })
- public void testRemoveNode() throws BackingStoreException {
- Preferences child = pref.node("child");
- Preferences child1 = pref.node("child1");
- Preferences grandchild = child.node("grandchild");
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "parent",
+ args = {}
+ )
+ public void testParent() throws BackingStoreException {
+ AbstractPreferences node = (AbstractPreferences) pref.node("First node/sub node");
+
+ assertTrue(node.parent().name().compareTo("First node") == 0);
pref.removeNode();
- assertFalse(child.nodeExists(""));
- assertFalse(child1.nodeExists(""));
- assertFalse(grandchild.nodeExists(""));
- assertFalse(pref.nodeExists(""));
+ try {
+ node.parent();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Also checks event flow.",
- targets = {
- @TestTarget(
- methodName = "addNodeChangeListener",
- methodArgs = {java.util.prefs.NodeChangeListener.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Indirecly checks childSpi",
+ method = "node",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Indirecly checks childSpi",
+ method = "childSpi",
+ args = {java.lang.String.class}
)
})
- public void _testAddNodeChangeListener() throws BackingStoreException {
+ public void testNode() throws BackingStoreException {
+ AbstractPreferences first = (AbstractPreferences) pref.node("First node");
+ AbstractPreferences second = (AbstractPreferences) pref.node("Second node");
+
try {
- pref.addNodeChangeListener(null);
- fail();
- } catch (NullPointerException e) {
+ first.node("blabla/");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
}
-
- Preferences child1 = null;
- Preferences child2 = null;
- Preferences child3 = null;
- // To get existed node doesn't create the change event
- try {
- nl = new MockNodeChangeListener();
- pref.addNodeChangeListener(nl);
- child1 = pref.node("mock1");
- assertEquals(1, nl.getAdded());
- nl.reset();
- child2 = pref.node("mock1");
- assertEquals(0, nl.getAdded());
- nl.reset();
- } finally {
- pref.removeNodeChangeListener(nl);
- child1.removeNode();
- }
- // same listener can be added twice, and must be removed twice
- try {
- nl = new MockNodeChangeListener();
- pref.addNodeChangeListener(nl);
- pref.addNodeChangeListener(nl);
- child1 = pref.node("mock2");
- assertEquals(2, nl.getAdded());
- nl.reset();
- } finally {
- pref.removeNodeChangeListener(nl);
- pref.removeNodeChangeListener(nl);
- child1.removeNode();
- }
- // test remove event
- try {
- nl = new MockNodeChangeListener();
- pref.addNodeChangeListener(nl);
- child1 = pref.node("mock3");
- child1.removeNode();
- assertEquals(1, nl.getRemoved());
- nl.reset();
- } finally {
- pref.removeNodeChangeListener(nl);
- }
- // test remove event with two listeners
- try {
- nl = new MockNodeChangeListener();
- pref.addNodeChangeListener(nl);
- pref.addNodeChangeListener(nl);
- child1 = pref.node("mock6");
- child1.removeNode();
- assertEquals(2, nl.getRemoved());
- nl.reset();
- } finally {
- pref.removeNodeChangeListener(nl);
- pref.removeNodeChangeListener(nl);
- }
- // test add/remove indirect children, or remove several children at the
- // same time
+
try {
- nl = new MockNodeChangeListener();
- child1 = pref.node("mock4");
- child1.addNodeChangeListener(nl);
- child2 = pref.node("mock4/mock5");
- assertEquals(1, nl.getAdded());
- nl.reset();
- child3 = pref.node("mock4/mock5/mock6");
- assertEquals(0, nl.getAdded());
- nl.reset();
-
- child3.removeNode();
- assertEquals(0, nl.getRemoved());
- nl.reset();
-
- child3 = pref.node("mock4/mock7");
- assertEquals(1, nl.getAdded());
- nl.reset();
-
- child1.removeNode();
- assertEquals(2, nl.getRemoved());
- nl.reset();
- } finally {
- try {
- child1.removeNode();
- } catch (Exception e) {
- }
+ first.node("///invalid");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
}
-
- }
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Also checks event flow.",
- targets = {
- @TestTarget(
- methodName = "addPreferenceChangeListener",
- methodArgs = {java.util.prefs.PreferenceChangeListener.class}
- )
- })
- public void _testAddPreferenceChangeListener() {
- // TODO: start from here
+
+ StringBuffer sb = new StringBuffer();
+
+ for (int i = 0; i < Preferences.MAX_NAME_LENGTH; i++) {
+ sb.append('c');
+ }
+ first.node(new String(sb));
+ sb.append('c');
+
try {
- pref.addPreferenceChangeListener(null);
- fail();
- } catch (NullPointerException e) {
+ first.node(new String(sb));
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
}
- // To get existed node doesn't create the change event
+ second.removeNode();
+
try {
- pl = new MockPreferenceChangeListener();
- pref.addPreferenceChangeListener(pl);
- pref.putInt("mock1", 123);
- assertEquals(1, pl.getChanged());
- pref.putLong("long_key", Long.MAX_VALUE);
- assertEquals(2, pl.getChanged());
- pl.reset();
-
- } finally {
- pref.removePreferenceChangeListener(pl);
- //child1.removeNode();
- }
-
- // same listener can be added twice, and must be removed twice
+ second.node("");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
+ }
+ pref.removeNode();
try {
- pl = new MockPreferenceChangeListener();
- pref.addPreferenceChangeListener(pl);
- pref.addPreferenceChangeListener(pl);
- pref.putFloat("float_key", Float.MIN_VALUE);
- assertEquals(2, pl.getChanged());
- pl.reset();
- } finally {
- pref.removePreferenceChangeListener(pl);
- pref.removePreferenceChangeListener(pl);
-
+ first.node("");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "removeNodeChangeListener",
- methodArgs = {java.util.prefs.NodeChangeListener.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "getChild tested indirectly",
+ method = "nodeExists",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "getChild tested indirectly",
+ method = "getChild",
+ args = {java.lang.String.class}
)
})
- public void testRemoveNodeChangeListener() {
- try {
- pref.removeNodeChangeListener(null);
- fail();
- } catch (IllegalArgumentException e) {
- }
- MockNodeChangeListener l1 = new MockNodeChangeListener();
- MockNodeChangeListener l2 = new MockNodeChangeListener();
- pref.addNodeChangeListener(l1);
- pref.addNodeChangeListener(l1);
-
- pref.removeNodeChangeListener(l1);
- pref.removeNodeChangeListener(l1);
+ public void testNodeExists() throws BackingStoreException {
+ AbstractPreferences ap1 = (AbstractPreferences) pref.node("First node");
+ AbstractPreferences ap2 = (AbstractPreferences) pref.node("Second node");
+ pref.putInt("IntegerValue", 33);
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+
+ assertTrue(pref.nodeExists("First node"));
+ assertTrue(pref.nodeExists("Second node"));
+ assertFalse(pref.nodeExists("IntegerValue"));
+ assertFalse(pref.nodeExists("BoolValue"));
+ assertFalse(pref.nodeExists("Value"));
+ assertFalse(pref.nodeExists(nodeName));
+
try {
- pref.removeNodeChangeListener(l1);
- fail();
+ pref.nodeExists("///invalid");
+ fail("IllegalArgumentException expected");
} catch (IllegalArgumentException e) {
+ //expected
}
+
+ pref.removeNode();
+
try {
- pref.removeNodeChangeListener(l2);
- fail();
- } catch (IllegalArgumentException e) {
+ pref.nodeExists("Exception");
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "removePreferenceChangeListener",
- methodArgs = {java.util.prefs.PreferenceChangeListener.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "removeNode",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "removeNodeSpi",
+ args = {}
)
})
- public void testRemovePreferenceChangeListener() {
- try {
- pref.removePreferenceChangeListener(null);
- fail();
- } catch (IllegalArgumentException e) {
+ public void testRemoveNode() throws BackingStoreException {
+ String[] nodeArray = new String[]{"First node", "Second node", "Last node"};
+ int i;
+ pref.put("Key", "String");
+ for (i = 0; i < nodeArray.length; i++) {
+ pref.node(nodeArray[i]);
}
- MockPreferenceChangeListener l1 = new MockPreferenceChangeListener();
- MockPreferenceChangeListener l2 = new MockPreferenceChangeListener();
- pref.addPreferenceChangeListener(l1);
- pref.addPreferenceChangeListener(l1);
+ pref.flush();
+
+ String[] str = pref.childrenNames();
+ assertEquals(nodeArray.length, str.length);
+ for(i = 0; i < nodeArray.length; i++) {
+ pref.node(nodeArray[i]).removeNode();
+ str = pref.childrenNames();
+ assertEquals(nodeArray.length - i - 1, str.length);
+ }
+ assertEquals(1, pref.keys().length);
+ pref.node("Key").removeNode();
+ assertEquals(1, pref.keys().length);
+
+ pref.removeNode();
+
try {
- pref.removePreferenceChangeListener(l2);
- fail();
- } catch (IllegalArgumentException e) {
+ pref.removeNode();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
- pref.removePreferenceChangeListener(l1);
- pref.removePreferenceChangeListener(l1);
+
try {
- pref.removePreferenceChangeListener(l1);
- fail();
- } catch (IllegalArgumentException e) {
+ root.removeNode();
+ fail("UnsupportedOperationException expected");
+ } catch (UnsupportedOperationException e) {
+ //expected
}
-
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Exceptions checking missed",
- targets = {
- @TestTarget(
- methodName = "sync",
- methodArgs = {}
- )
- })
- public void testSync() throws BackingStoreException {
-
- if (!(pref instanceof MockAbstractPreferences)) {
- return;
- }
- MockAbstractPreferences p = (MockAbstractPreferences) pref;
- p.resetSyncTimes();
- p.sync();
- assertEquals(1, p.getSyncTimes());
-
- p.resetSyncTimes();
- MockAbstractPreferences child = (MockAbstractPreferences) p
- .node("child");
- MockAbstractPreferences child2 = new MockAbstractPreferences(p,
- "child2");
- p.childs.put("child2", child2);
- assertEquals(1, p.cachedChildrenImpl().length);
- assertSame(child, p.cachedChildrenImpl()[0]);
- p.sync();
- assertEquals(1, p.getSyncTimes());
- assertEquals(1, child.getSyncTimes());
- assertEquals(0, child2.getSyncTimes());
-
- p.resetSyncTimes();
- child.resetSyncTimes();
- child.sync();
- assertEquals(0, p.getSyncTimes());
- assertEquals(1, child.getSyncTimes());
-
- p.resetSyncTimes();
- child.resetSyncTimes();
- MockAbstractPreferences grandson = (MockAbstractPreferences) child
- .node("grandson");
- child.sync();
- assertEquals(0, p.getSyncTimes());
- assertEquals(1, child.getSyncTimes());
- assertEquals(1, grandson.getSyncTimes());
- }
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "name",
+ args = {}
+ )
+ public void testName() {
+ AbstractPreferences first = (AbstractPreferences) pref.node("First node");
+ AbstractPreferences second = (AbstractPreferences) pref.node("Second node/sub node");
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "flush",
- methodArgs = {}
- )
- })
- public void testFlush() throws BackingStoreException {
-
- if (!(pref instanceof MockAbstractPreferences)) {
- return;
- }
- MockAbstractPreferences p = (MockAbstractPreferences) pref;
- p.resetFlushedTimes();
- p.flush();
- assertEquals(1, p.getFlushedTimes());
-
- p.resetFlushedTimes();
- MockAbstractPreferences child = (MockAbstractPreferences) p
- .node("child");
- MockAbstractPreferences child2 = new MockAbstractPreferences(p,
- "child2");
- p.childs.put("child2", child2);
- assertEquals(1, p.cachedChildrenImpl().length);
- assertSame(child, p.cachedChildrenImpl()[0]);
- p.flush();
- assertEquals(1, p.getFlushedTimes());
- assertEquals(1, child.getFlushedTimes());
- assertEquals(0, child2.getFlushedTimes());
-
- p.resetFlushedTimes();
- child.resetFlushedTimes();
- child.flush();
- assertEquals(0, p.getFlushedTimes());
- assertEquals(1, child.getFlushedTimes());
-
- p.resetFlushedTimes();
- child.resetFlushedTimes();
- MockAbstractPreferences grandson = (MockAbstractPreferences) child
- .node("grandson");
- child.flush();
- assertEquals(0, p.getFlushedTimes());
- assertEquals(1, child.getFlushedTimes());
- assertEquals(1, grandson.getFlushedTimes());
-
- p.resetFlushedTimes();
- child.resetFlushedTimes();
- grandson.resetFlushedTimes();
- child.removeNode();
- child.flush();
- assertEquals(0, p.getFlushedTimes());
- assertEquals(1, child.getFlushedTimes());
- assertEquals(0, grandson.getFlushedTimes());
+ assertTrue(first.name().compareTo("First node") == 0);
+ assertFalse(first.name().compareTo("Second node") == 0);
+ assertTrue(second.name().compareTo("sub node") == 0);
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getChild",
- methodArgs = {java.lang.String.class}
- )
- })
- public void testGetChild() throws BackingStoreException {
- if (!(pref instanceof MockAbstractPreferences)) {
- return;
- }
- MockAbstractPreferences p = (MockAbstractPreferences) pref;
- assertNull(p.getChildImpl("child"));
- MockAbstractPreferences child = new MockAbstractPreferences(p, "child");
- p.childs.put("child", child);
- assertSame(child, p.getChildImpl("child"));
- assertNull(p.getChildImpl("child "));
-
- assertNull(p.getChildImpl("child/grandson"));
- child.childs.put("grandson", new MockAbstractPreferences(child,
- "grandson"));
- assertNull(p.getChildImpl("child/grandson"));
-
- assertNull(p.getChildImpl(null));
- assertNull(p.getChildImpl(""));
- assertNull(p.getChildImpl(" "));
- assertNull(p.getChildImpl("abc//abc"));
- assertNull(p.getChildImpl("child/"));
- assertNull(p.getChildImpl(longName + "a"));
-
- child.removeNode();
- assertNull(p.getChildImpl("child"));
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "absolutePath",
+ args = {}
+ )
+ public void testAbsolutePath() {
+ assertEquals(parent.absolutePath() + "/" + nodeName, pref.absolutePath());
+ assertEquals(parent.absolutePath() + "/" + "new node", parent.node("new node").absolutePath());
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "isRemoved",
- methodArgs = {}
- )
- })
- public void testIsRemoved() throws BackingStoreException {
- if (!(pref instanceof MockAbstractPreferences)) {
- return;
- }
- MockAbstractPreferences p = (MockAbstractPreferences) pref;
- assertFalse(p.isRemovedImpl());
- p.removeNode();
- assertTrue(p.isRemovedImpl());
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "isUserNode",
+ args = {}
+ )
+ public void testIsUserNode() {
+ assertTrue(parent.isUserNode());
+ assertFalse(Preferences.systemRoot().isUserNode());
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IOException checking missed",
- targets = {
- @TestTarget(
- methodName = "exportNode",
- methodArgs = {java.io.OutputStream.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Indirectly checks syncSpi",
+ method = "sync",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Indirectly checks syncSpi",
+ method = "syncSpi",
+ args = {}
)
})
- public void _testExportNode() throws Exception {
+ public void testSync() throws BackingStoreException {
+ pref.node("new node/sub node");
+ pref.sync();
+
+ pref.removeNode();
+
try {
- pref.exportNode(null);
- fail();
- } catch (NullPointerException e) {
- // Expected
+ pref.sync();
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
-
- pref.putBoolean("key", false);
- Preferences child = pref.node("child<");
- child.put("key2", "value2<");
- Preferences grandson = child.node("grandson");
- grandson.put("key3", "value3");
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- child.exportNode(out);
-
- byte[] result = out.toString().getBytes();
- ByteArrayInputStream in = new ByteArrayInputStream(result);
-
- try {
- parseXmlStream(in, true);
- } catch (Exception ee) {
- fail("Exception " + ee + " does not expected");
- }
}
- private static Document parseXmlStream(InputStream input, boolean validating)
- throws SAXException, IOException, ParserConfigurationException {
- // Create a builder factory
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setValidating(validating);
-
- // Create the builder and parse the file
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(input);
- return doc;
- }
+ class MockPreferenceChangeListener implements PreferenceChangeListener {
+ private boolean flagChange = false;
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IOException checking missed",
- targets = {
- @TestTarget(
- methodName = "exportSubtree",
- methodArgs = {java.io.OutputStream.class}
- )
- })
- public void _testExportSubtree() throws Exception {
- try {
- pref.exportSubtree(null);
- fail();
- } catch (NullPointerException e) {
- // Expected
- }
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- pref.putBoolean("key", false);
- Preferences child = pref.node("child");
- child.put("key2", "value2");
- Preferences grandson = child.node("grandson");
- grandson.put("key3", "value3");
- child.node("grandson2");
- Preferences grandgrandson = grandson.node("grandgrandson");
- grandgrandson.put("key4", "value4");
- child.exportSubtree(out);
-
- byte[] result = out.toByteArray();
- // System.out.println(new String(result, "utf-8"));
- ByteArrayInputStream in = new ByteArrayInputStream(result);
-
- try {
- parseXmlStream(in, true);
- } catch (Exception ee) {
- fail("Exception " + ee + " does not expected");
- }
- }
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "cachedChildren",
- methodArgs = {}
- )
- })
- public void testCachedChildren() throws Exception {
- if (!(pref instanceof MockAbstractPreferences)) {
- return;
+ public void preferenceChange(PreferenceChangeEvent arg0) {
+ flagChange = true;
}
- MockAbstractPreferences p = (MockAbstractPreferences) pref;
- assertEquals(0, p.cachedChildrenImpl().length);
-
- MockAbstractPreferences child = (MockAbstractPreferences) p
- .getChildImpl("child");
- assertNull(child);
-
- child = new MockAbstractPreferences(p, "child");
- assertSame(child, p.getChildImpl("child"));
-
- assertEquals(0, p.cachedChildrenImpl().length);
-
- p.node("child");
- assertSame(child, p.cachedChildrenImpl()[0]);
-
- MockAbstractPreferences grandchild = new MockAbstractPreferences(child,
- "grandchild");
- assertSame(grandchild, child.getChildImpl("grandchild"));
- assertNull(p.getChildImpl("grandchild"));
-
- assertEquals(1, p.cachedChildrenImpl().length);
- assertEquals(0, child.cachedChildrenImpl().length);
-
- p.node("child/grandchild");
- assertSame(child, p.cachedChildrenImpl()[0]);
- assertSame(grandchild, child.cachedChildrenImpl()[0]);
- assertEquals(1, p.cachedChildrenImpl().length);
- assertEquals(1, child.cachedChildrenImpl().length);
-
- p.childs.put("child2", new MockAbstractPreferences(p, "child2"));
- p.nodeExists("child2/grandchild");
- assertSame(child, p.cachedChildrenImpl()[0]);
- assertSame(grandchild, child.cachedChildrenImpl()[0]);
- assertEquals(1, p.cachedChildrenImpl().length);
- assertEquals(1, child.cachedChildrenImpl().length);
- }
-
-@TestInfo(
- level = TestLevel.TODO,
- purpose = "Candidate for removal.",
- targets = {
- @TestTarget(
- methodName = "",
- methodArgs = {}
- )
- })
- public void testAbstractMethod() {
- if (!(pref instanceof MockAbstractPreferences)) {
- return;
+
+ public boolean isChanged () {
+ boolean retVal = flagChange;
+ flagChange = false;
+ return retVal;
}
- ((MockAbstractPreferences) pref).protectedAbstractMethod();
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "addPreferenceChangeListener",
+ args = {java.util.prefs.PreferenceChangeListener.class}
+ )
+ public void testAddPreferenceChangeListener() throws BackingStoreException {
+ MockPreferenceChangeListener mpcl = new MockPreferenceChangeListener();
+ parent.addPreferenceChangeListener(mpcl);
+ assertFalse(mpcl.isChanged());
+ pref.node("new node");
+ pref.flush();
+ parent.flush();
+ assertFalse(mpcl.isChanged());
+ parent.node("new node");
+ parent.flush();
+ assertFalse(mpcl.isChanged());
+ parent.putInt("IntValue", 33);
+ parent.flush();
+ parent.flush();
+ assertTrue(mpcl.isChanged());
+ assertEquals(33, parent.getInt("IntValue", 22));
+ parent.flush();
+ assertFalse(mpcl.isChanged());
+ assertEquals(22, parent.getInt("Missed Value", 22));
+ parent.flush();
+ assertFalse(mpcl.isChanged());
}
-@TestInfo(
- level = TestLevel.TODO,
- purpose = "Candidate for removal.",
- targets = {
- @TestTarget(
- methodName = "",
- methodArgs = {}
- )
- })
- public Object invokeNonPublicMethod(AbstractPreferences obj, String name,
- Class[] params, Object[] paramValues) throws SecurityException,
- NoSuchMethodException, IllegalArgumentException,
- IllegalAccessException, InvocationTargetException {
- Method method = obj.getClass().getMethod(name, params);
- method.setAccessible(true);
- return method.invoke(obj, paramValues);
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "removePreferenceChangeListener",
+ args = {java.util.prefs.PreferenceChangeListener.class}
+ )
+ public void testRemovePreferenceChangeListener() throws BackingStoreException {
+ MockPreferenceChangeListener mpcl = new MockPreferenceChangeListener();
+ parent.addPreferenceChangeListener(mpcl);
+ assertFalse(mpcl.isChanged());
+ parent.putInt("IntValue", 33);
+ parent.flush();
+ assertTrue(mpcl.isChanged());
+ parent.removePreferenceChangeListener(mpcl);
+ parent.putInt("IntValue", 33);
+ parent.flush();
+ assertFalse(mpcl.isChanged());
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Test checks BackingStoreException",
- targets = {
- @TestTarget(
- methodName = "childrenNames",
- methodArgs = {}
- ), @TestTarget(
- methodName = "clear",
- methodArgs = {}
- ), @TestTarget(
- methodName = "keys",
- methodArgs = {}
- ), @TestTarget(
- methodName = "removeNode",
- methodArgs = {}
- ), @TestTarget(
- methodName = "sync",
- methodArgs = {}
- ), @TestTarget(
- methodName = "flush",
- methodArgs = {}
- ), @TestTarget(
- methodName = "exportNode",
- methodArgs = {java.io.OutputStream.class}
- ), @TestTarget(
- methodName = "exportSubtree",
- methodArgs = {java.io.OutputStream.class}
- ), @TestTarget(
- methodName = "getChild",
- methodArgs = {java.lang.String.class}
- )
- })
- public void _testBackingStoreException() throws IOException,
- BackingStoreException {
- if (!(pref instanceof MockAbstractPreferences)) {
- fail();
- return;
- }
- MockAbstractPreferences p = (MockAbstractPreferences) pref;
- p.setResult(MockAbstractPreferences.backingException);
- try {
- p.childrenNames();
- fail();
- } catch (BackingStoreException e) {
- }
- p.put("exceptionkey", "value");
- p.absolutePath();
- p.toString();
- assertEquals("exception default", p.get("key", "exception default"));
- p.remove("key");
- try {
- p.clear();
- fail();
- } catch (BackingStoreException e) {
- }
- p.putInt("key", 3);
- p.getInt("key", 3);
- p.putLong("key", 3l);
- p.getLong("key", 3l);
- p.putDouble("key", 3);
- p.getDouble("key", 3);
- p.putBoolean("key", true);
- p.getBoolean("key", true);
- p.putFloat("key", 3f);
- p.getFloat("key", 3f);
- p.putByteArray("key", new byte[0]);
- p.getByteArray("key", new byte[0]);
- try {
- p.keys();
- fail();
- } catch (BackingStoreException e) {
- }
+ class MockNodeChangeListener implements NodeChangeListener {
+ private boolean flagAdded = false;
+ private boolean flagRemoved = false;
- try {
- p.keys();
- fail();
- } catch (BackingStoreException e) {
- }
- try {
- p.childrenNames();
- fail();
- } catch (BackingStoreException e) {
+ public void childAdded(NodeChangeEvent arg0) {
+ flagAdded = true;
}
- p.parent();
- p.node("");
- p.nodeExists("");
- try {
- p.removeNode();
- fail();
- } catch (BackingStoreException e) {
- }
- p.name();
- p.absolutePath();
- p.isUserNode();
- MockPreferenceChangeListener mockPreferenceChangeListener = new MockPreferenceChangeListener();
- p.addPreferenceChangeListener(mockPreferenceChangeListener);
- p.removePreferenceChangeListener(mockPreferenceChangeListener);
- MockNodeChangeListener mockNodeChangeListener = new MockNodeChangeListener();
- p.addNodeChangeListener(mockNodeChangeListener);
- p.removeNodeChangeListener(mockNodeChangeListener);
- p.toString();
- try {
- p.sync();
- fail();
- } catch (BackingStoreException e) {
- }
- try {
- p.flush();
- fail();
- } catch (BackingStoreException e) {
- }
- try {
- p.exportNode(new ByteArrayOutputStream());
- fail();
- } catch (BackingStoreException e) {
- }
- try {
- p.exportSubtree(new ByteArrayOutputStream());
- fail();
- } catch (BackingStoreException e) {
- }
- p.isRemovedImpl();
- try {
- p.getChildImpl(null);
- fail();
- } catch (BackingStoreException e) {
- }
- p.cachedChildrenImpl();
- }
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Test checks RuntimeException",
- targets = {
- @TestTarget(
- methodName = "childrenNames",
- methodArgs = {}
- ), @TestTarget(
- methodName = "put",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- ), @TestTarget(
- methodName = "remove",
- methodArgs = {java.lang.String.class}
- ), @TestTarget(
- methodName = "clear",
- methodArgs = {}
- ), @TestTarget(
- methodName = "putInt",
- methodArgs = {java.lang.String.class, int.class}
- ), @TestTarget(
- methodName = "putLong",
- methodArgs = {java.lang.String.class, long.class}
- ), @TestTarget(
- methodName = "putDouble",
- methodArgs = {java.lang.String.class, double.class}
- ), @TestTarget(
- methodName = "putBoolean",
- methodArgs = {java.lang.String.class, boolean.class}
- ), @TestTarget(
- methodName = "putFloat",
- methodArgs = {java.lang.String.class, float.class}
- ), @TestTarget(
- methodName = "putByteArray",
- methodArgs = {java.lang.String.class, byte[].class}
- ), @TestTarget(
- methodName = "keys",
- methodArgs = {}
- ), @TestTarget(
- methodName = "removeNode",
- methodArgs = {}
- ), @TestTarget(
- methodName = "sync",
- methodArgs = {}
- ), @TestTarget(
- methodName = "flush",
- methodArgs = {}
- ), @TestTarget(
- methodName = "exportNode",
- methodArgs = {java.io.OutputStream.class}
- ), @TestTarget(
- methodName = "exportSubtree",
- methodArgs = {java.io.OutputStream.class}
- ), @TestTarget(
- methodName = "getChild",
- methodArgs = {java.lang.String.class}
- )
- })
- public void _testRuntimeException() throws IOException,
- BackingStoreException {
- if (!(pref instanceof MockAbstractPreferences)) {
- fail();
- return;
- }
- MockAbstractPreferences p = (MockAbstractPreferences) pref;
- p.setResult(MockAbstractPreferences.runtimeException);
- try {
- p.childrenNames();
- fail();
- } catch (MockRuntimeException e) {
- }
- try {
- p.put("exceptionkey", "value");
- fail();
- } catch (MockRuntimeException e) {
- }
- p.absolutePath();
- p.toString();
- assertEquals("exception default", p.get("key", "exception default"));
- try {
- p.remove("key");
- fail();
- } catch (MockRuntimeException e) {
- }
- try {
- p.clear();
- fail();
- } catch (MockRuntimeException e) {
- }
- try {
- p.putInt("key", 3);
- fail();
- } catch (MockRuntimeException e) {
- }
- p.getInt("key", 3);
- try {
- p.putLong("key", 3l);
- fail();
- } catch (MockRuntimeException e) {
- }
- p.getLong("key", 3l);
- try {
- p.putDouble("key", 3);
- fail();
- } catch (MockRuntimeException e) {
- }
- p.getDouble("key", 3);
- try {
- p.putBoolean("key", true);
- fail();
- } catch (MockRuntimeException e) {
- }
- p.getBoolean("key", true);
- try {
- p.putFloat("key", 3f);
- fail();
- } catch (MockRuntimeException e) {
+ public void childRemoved(NodeChangeEvent arg0) {
+ flagRemoved = true;
}
- p.getFloat("key", 3f);
- try {
- p.putByteArray("key", new byte[0]);
- fail();
- } catch (MockRuntimeException e) {
- }
- p.getByteArray("key", new byte[0]);
- try {
- p.keys();
- fail();
- } catch (MockRuntimeException e) {
- }
- try {
- p.keys();
- fail();
- } catch (MockRuntimeException e) {
- }
- try {
- p.childrenNames();
- fail();
- } catch (MockRuntimeException e) {
- }
- p.parent();
- p.node("");
- p.nodeExists("");
- try {
- p.removeNode();
- fail();
- } catch (MockRuntimeException e) {
- }
- p.name();
- p.absolutePath();
- p.isUserNode();
- MockPreferenceChangeListener pcl = new MockPreferenceChangeListener();
- p.addPreferenceChangeListener(pcl);
- p.removePreferenceChangeListener(pcl);
- MockNodeChangeListener ncl = new MockNodeChangeListener();
- p.addNodeChangeListener(ncl);
- p.removeNodeChangeListener(ncl);
- p.toString();
- try {
- p.sync();
- fail();
- } catch (MockRuntimeException e) {
- }
- try {
- p.flush();
- fail();
- } catch (MockRuntimeException e) {
- }
- try {
- p.exportNode(new ByteArrayOutputStream());
- fail();
- } catch (MockRuntimeException e) {
- }
- try {
- p.exportSubtree(new ByteArrayOutputStream());
- fail();
- } catch (MockRuntimeException e) {
+
+ public boolean isAdded() {
+ return flagAdded;
}
- p.isRemovedImpl();
- try {
- p.getChildImpl(null);
- fail();
- } catch (MockRuntimeException e) {
+
+ public boolean isRemoved() {
+ return flagRemoved;
}
- p.cachedChildrenImpl();
+ }
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "addNodeChangeListener",
+ args = {java.util.prefs.NodeChangeListener.class}
+ )
+ public void testAddNodeChangeListener() throws BackingStoreException {
+ MockNodeChangeListener mncl = new MockNodeChangeListener();
+ parent.addNodeChangeListener(mncl);
+ pref.node("test");
+ pref.flush();
+ parent.flush();
+ assertFalse(mncl.isAdded());
+ assertFalse(mncl.isRemoved());
+ pref.removeNode();
+ parent.flush();
+ assertFalse(mncl.isAdded());
+ assertTrue(mncl.isRemoved());
+ parent.node("new node");
+ parent.flush();
+ assertTrue(mncl.isAdded());
+ assertTrue(mncl.isRemoved());
}
-@TestInfo(
- level = TestLevel.TODO,
- purpose = "Test is OK, but it verifies unspecified NullPointerException.",
- targets = {
- @TestTarget(
- methodName = "childrenNames",
- methodArgs = {}
- ), @TestTarget(
- methodName = "clear",
- methodArgs = {}
- ), @TestTarget(
- methodName = "removeNode",
- methodArgs = {}
- ), @TestTarget(
- methodName = "getChild",
- methodArgs = {java.lang.String.class}
- ), @TestTarget(
- methodName = "exportNode",
- methodArgs = {java.io.OutputStream.class}
- ), @TestTarget(
- methodName = "exportSubtree",
- methodArgs = {java.io.OutputStream.class}
- )
- })
- public void _testSPIReturnNull() throws IOException, BackingStoreException {
- if (!(pref instanceof MockAbstractPreferences)) {
- fail();
- return;
- }
- MockAbstractPreferences p = (MockAbstractPreferences) pref;
- p.setResult(MockAbstractPreferences.returnNull);
- try {
- p.childrenNames();
- fail();
- } catch (NullPointerException e) {
- }
- p.absolutePath();
- p.toString();
- p.put("nullkey", "value");
- assertEquals("null default", p.get("key", "null default"));
- p.remove("key");
- try {
- p.clear();
- fail();
- } catch (NullPointerException e) {
- }
- p.putInt("key", 3);
- p.getInt("key", 3);
- p.putLong("key", 3l);
- p.getLong("key", 3l);
- p.putDouble("key", 3);
- p.getDouble("key", 3);
- p.putBoolean("key", true);
- p.getBoolean("key", true);
- p.putFloat("key", 3f);
- p.getFloat("key", 3f);
- p.putByteArray("key", new byte[0]);
- p.getByteArray("key", new byte[0]);
- p.keys();
- try {
- p.childrenNames();
- fail();
- } catch (NullPointerException e) {
- }
- p.parent();
- p.node("");
- p.nodeExists("");
- try {
- p.removeNode();
- fail();
- } catch (NullPointerException e) {
- }
- p.name();
- p.absolutePath();
- p.isUserNode();
- MockPreferenceChangeListener mockPreferenceChangeListener = new MockPreferenceChangeListener();
- p.addPreferenceChangeListener(mockPreferenceChangeListener);
- p.removePreferenceChangeListener(mockPreferenceChangeListener);
- MockNodeChangeListener mockNodeChangeListener = new MockNodeChangeListener();
- p.addNodeChangeListener(mockNodeChangeListener);
- p.removeNodeChangeListener(mockNodeChangeListener);
- p.toString();
- p.sync();
- p.flush();
- try {
- p.exportNode(System.out);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- p.exportSubtree(System.out);
- fail();
- } catch (NullPointerException e) {
- }
- p.isRemovedImpl();
- try {
- p.getChildImpl("");
- fail();
- } catch (NullPointerException e) {
- }
- p.cachedChildrenImpl();
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "removeNodeChangeListener",
+ args = {java.util.prefs.NodeChangeListener.class}
+ )
+ public void testRemoveNodeChangeListener() throws BackingStoreException {
+ MockNodeChangeListener mncl = new MockNodeChangeListener();
+ parent.addNodeChangeListener(mncl);
+ pref.node("test");
+ pref.flush();
+ parent.flush();
+ assertFalse(mncl.isAdded());
+ assertFalse(mncl.isRemoved());
+ parent.removeNodeChangeListener(mncl);
+ pref.removeNode();
+ parent.flush();
+ assertFalse(mncl.isAdded());
+ assertFalse(mncl.isRemoved());
+ parent.node("new node");
+ parent.flush();
+ assertFalse(mncl.isAdded());
+ assertFalse(mncl.isRemoved());
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Test verifies IllegalStateException",
- targets = {
- @TestTarget(
- methodName = "nodeExists",
- methodArgs = {java.lang.String.class}
- ), @TestTarget(
- methodName = "childrenNames",
- methodArgs = {}
- ), @TestTarget(
- methodName = "remove",
- methodArgs = {java.lang.String.class}
- ), @TestTarget(
- methodName = "clear",
- methodArgs = {}
- ), @TestTarget(
- methodName = "get",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- ), @TestTarget(
- methodName = "put",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- ), @TestTarget(
- methodName = "getInt",
- methodArgs = {java.lang.String.class, int.class}
- ), @TestTarget(
- methodName = "putInt",
- methodArgs = {java.lang.String.class, int.class}
- ), @TestTarget(
- methodName = "getLong",
- methodArgs = {java.lang.String.class, long.class}
- ), @TestTarget(
- methodName = "putLong",
- methodArgs = {java.lang.String.class, long.class}
- ), @TestTarget(
- methodName = "putDouble",
- methodArgs = {java.lang.String.class, double.class}
- ), @TestTarget(
- methodName = "getDouble",
- methodArgs = {java.lang.String.class, double.class}
- ), @TestTarget(
- methodName = "putBoolean",
- methodArgs = {java.lang.String.class, boolean.class}
- ), @TestTarget(
- methodName = "getBoolean",
- methodArgs = {java.lang.String.class, boolean.class}
- ), @TestTarget(
- methodName = "putFloat",
- methodArgs = {java.lang.String.class, float.class}
- ), @TestTarget(
- methodName = "getFloat",
- methodArgs = {java.lang.String.class, float.class}
- ), @TestTarget(
- methodName = "putByteArray",
- methodArgs = {java.lang.String.class, byte[].class}
- ), @TestTarget(
- methodName = "getByteArray",
- methodArgs = {java.lang.String.class, byte[].class}
- ), @TestTarget(
- methodName = "keys",
- methodArgs = {}
- ), @TestTarget(
- methodName = "childrenNames",
- methodArgs = {}
- ), @TestTarget(
- methodName = "parent",
- methodArgs = {}
- ), @TestTarget(
- methodName = "node",
- methodArgs = {java.lang.String.class}
- ), @TestTarget(
- methodName = "removeNode",
- methodArgs = {}
- ), @TestTarget(
- methodName = "addNodeChangeListener",
- methodArgs = {java.util.prefs.NodeChangeListener.class}
- ), @TestTarget(
- methodName = "removeNodeChangeListener",
- methodArgs = {java.util.prefs.NodeChangeListener.class}
- ), @TestTarget(
- methodName = "addPreferenceChangeListener",
- methodArgs = {java.util.prefs.PreferenceChangeListener.class}
- ), @TestTarget(
- methodName = "removePreferenceChangeListener",
- methodArgs = {java.util.prefs.PreferenceChangeListener.class}
- ), @TestTarget(
- methodName = "sync",
- methodArgs = {}
- ), @TestTarget(
- methodName = "exportNode",
- methodArgs = {java.io.OutputStream.class}
- ), @TestTarget(
- methodName = "exportSubtree",
- methodArgs = {java.io.OutputStream.class}
- ), @TestTarget(
- methodName = "getChild",
- methodArgs = {java.lang.String.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "BackingStoreException, IOException can not be checked.",
+ method = "exportNode",
+ args = {java.io.OutputStream.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "BackingStoreException, IOException can not be checked.",
+ method = "flush",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "BackingStoreException, IOException can not be checked.",
+ method = "flushSpi",
+ args = {}
)
})
- public void _testIllegalStateException() throws IOException,
- BackingStoreException {
- if (!(pref instanceof MockAbstractPreferences)) {
- fail();
- return;
- }
- pref.removeNode();
- // after remove node, every methods, except name(), absolutePath(),
- // isUserNode(), flush() or nodeExists(""),
- // will throw illegal state exception
- pref.nodeExists("");
- pref.name();
- pref.absolutePath();
- pref.isUserNode();
- pref.toString();
+ public void testExportNode() throws BackingStoreException, IOException, InvalidPreferencesFormatException {
+ AbstractPreferences ap = (AbstractPreferences) pref.node("New node");
+ pref.putInt("IntValue", 33);
+ pref.putBoolean("BoolValue", true);
pref.flush();
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ pref.exportNode(baos);
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertEquals(33, pref.getInt("IntValue", 22));
+ assertEquals(1, pref.childrenNames().length);
+
+ String xmlData = new String(baos.toByteArray());
+
+ assertTrue(xmlData.contains("IntValue"));
+ assertTrue(xmlData.contains("BoolValue"));
+ assertTrue(xmlData.contains("33"));
+ assertTrue(xmlData.contains("true"));
+
+ pref.removeNode();
+
try {
- pref.nodeExists("child");
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.childrenNames();
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.remove(null);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.clear();
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.get("key", "null default");
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.put("nullkey", "value");
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.putInt("key", 3);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.getInt("key", 3);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.putLong("key", 3l);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.getLong("key", 3l);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.putDouble("key", 3);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.getDouble("key", 3);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.putBoolean("key", true);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.getBoolean("key", true);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.putFloat("key", 3f);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.getFloat("key", 3f);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.putByteArray("key", new byte[0]);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.getByteArray("key", new byte[0]);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.keys();
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.keys();
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.childrenNames();
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.parent();
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.node(null);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.removeNode();
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref
- .addPreferenceChangeListener(new MockPreferenceChangeListener());
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref
- .removePreferenceChangeListener(new MockPreferenceChangeListener());
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.addNodeChangeListener(new MockNodeChangeListener());
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.removeNodeChangeListener(new MockNodeChangeListener());
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.sync();
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.exportNode(null);
- fail();
- } catch (IllegalStateException e) {
- }
- try {
- pref.exportSubtree(null);
- fail();
+ pref.exportNode(new ByteArrayOutputStream());
+ fail("IllegalStateException expected");
} catch (IllegalStateException e) {
+ //expected
}
- if (!(pref instanceof MockAbstractPreferences)) {
- return;
- }
- MockAbstractPreferences p = (MockAbstractPreferences) pref;
- p.isRemovedImpl();
- p.cachedChildrenImpl();
+
try {
- p.getChildImpl(null);
- fail();
+ pref.getBoolean("BoolValue", false);
+ fail("IllegalStateException expected");
} catch (IllegalStateException e) {
+ //expected
}
+ pref = (AbstractPreferences) parent.node(nodeName);
+
+ pref.importPreferences(bais);
+
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertEquals(33, pref.getInt("IntValue", 22));
+ assertEquals(0, pref.childrenNames().length);
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Test verifies NullPointerException & IllegalStateException",
- targets = {
- @TestTarget(
- methodName = "get",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- ), @TestTarget(
- methodName = "put",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- ), @TestTarget(
- methodName = "putInt",
- methodArgs = {java.lang.String.class, int.class}
- ), @TestTarget(
- methodName = "getInt",
- methodArgs = {java.lang.String.class, int.class}
- ), @TestTarget(
- methodName = "putLong",
- methodArgs = {java.lang.String.class, long.class}
- ), @TestTarget(
- methodName = "getLong",
- methodArgs = {java.lang.String.class, long.class}
- ), @TestTarget(
- methodName = "putBoolean",
- methodArgs = {java.lang.String.class, boolean.class}
- ), @TestTarget(
- methodName = "getBoolean",
- methodArgs = {java.lang.String.class, boolean.class}
- ), @TestTarget(
- methodName = "putFloat",
- methodArgs = {java.lang.String.class, float.class}
- ), @TestTarget(
- methodName = "getFloat",
- methodArgs = {java.lang.String.class, float.class}
- ), @TestTarget(
- methodName = "putByteArray",
- methodArgs = {java.lang.String.class, byte[].class}
- ), @TestTarget(
- methodName = "getByteArray",
- methodArgs = {java.lang.String.class, byte[].class}
- ), @TestTarget(
- methodName = "addNodeChangeListener",
- methodArgs = {java.util.prefs.NodeChangeListener.class}
- ), @TestTarget(
- methodName = "removeNodeChangeListener",
- methodArgs = {java.util.prefs.NodeChangeListener.class}
- ), @TestTarget(
- methodName = "addPreferenceChangeListener",
- methodArgs = {java.util.prefs.PreferenceChangeListener.class}
- ), @TestTarget(
- methodName = "removePreferenceChangeListener",
- methodArgs = {java.util.prefs.PreferenceChangeListener.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "BackingStoreException, IOException can not be checked.",
+ method = "exportSubtree",
+ args = {java.io.OutputStream.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "BackingStoreException, IOException can not be checked.",
+ method = "flush",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "BackingStoreException, IOException can not be checked.",
+ method = "flushSpi",
+ args = {}
)
})
- public void _testNullAndIllegalStateException() throws Exception {
- if (!(pref instanceof MockAbstractPreferences)) {
- fail();
- return;
- }
- MockAbstractPreferences p = (MockAbstractPreferences) pref;
- p.removeNode();
- try {
- p.get(null, "null default");
- fail();
- } catch (NullPointerException e) {
- }
- try {
- p.put(null, "value");
- fail();
- } catch (NullPointerException e) {
- }
- try {
- p.putInt(null, 3);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- p.getInt(null, 3);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- p.putLong(null, 3l);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- p.getLong(null, 3l);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- p.putDouble(null, 3);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- p.getDouble(null, 3);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- p.putBoolean(null, true);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- p.getBoolean(null, true);
- fail();
- } catch (NullPointerException e) {
- }
- try {
- p.putFloat(null, 3f);
- fail();
- } catch (NullPointerException e) {
- }
+ public void testExportSubtree() throws BackingStoreException, IOException, InvalidPreferencesFormatException {
+ AbstractPreferences ap1 = (AbstractPreferences) pref.node("First node");
+ AbstractPreferences ap2 = (AbstractPreferences) pref.node("Second node");
+ pref.putInt("IntegerValue", 33);
+ pref.putBoolean("BoolValue", true);
+ pref.flush();
+
+ ap1.putInt("FirstIntValue", 11);
+ ap2.putDouble("DoubleValue", new Double(6.626e-34));
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+
+ pref.exportSubtree(baos);
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertEquals(33, pref.getInt("IntegerValue", 22));
+ assertEquals(2, pref.childrenNames().length);
+ assertEquals(11, ap1.getInt("FirstIntValue", 22));
+ assertEquals(new Double(6.626e-34), ap2.getDouble("DoubleValue", new Double (3.14)));
+
+ String xmlData = new String(baos.toByteArray());
+
+ assertTrue(xmlData.contains("IntegerValue"));
+ assertTrue(xmlData.contains("BoolValue"));
+ assertTrue(xmlData.contains("FirstIntValue"));
+ assertTrue(xmlData.contains("DoubleValue"));
+ assertTrue(xmlData.contains("33"));
+ assertTrue(xmlData.contains("true"));
+ assertTrue(xmlData.contains("11"));
+ assertTrue(xmlData.contains("6.626E-34"));
+
+ pref.removeNode();
+
try {
- p.getFloat(null, 3f);
- fail();
- } catch (NullPointerException e) {
+ pref.exportSubtree(new ByteArrayOutputStream());
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
+
try {
- p.putByteArray(null, new byte[0]);
- fail();
- } catch (NullPointerException e) {
+ pref.getBoolean("BoolValue", false);
+ fail("IllegalStateException expected");
+ } catch (IllegalStateException e) {
+ //expected
}
- try {
- p.getByteArray(null, new byte[0]);
- fail();
- } catch (NullPointerException e) {
+ pref = (AbstractPreferences) parent.node(nodeName);
+ pref.importPreferences(bais);
+
+ ap1 = (AbstractPreferences) pref.node("First node");
+ ap2 = (AbstractPreferences) pref.node("Second node");
+
+ assertTrue(pref.getBoolean("BoolValue", false));
+ assertEquals(33, pref.getInt("IntegerValue", 22));
+ assertEquals(2, pref.childrenNames().length);
+ assertEquals(11, ap1.getInt("FirstIntValue", 22));
+ assertEquals(new Double(6.626e-34), ap2.getDouble("DoubleValue", new Double (3.14)));
+ }
+
+ class MockAbstractPreferences extends AbstractPreferences {
+ protected MockAbstractPreferences(AbstractPreferences parent, String name) {
+ super(parent, name);
}
- try {
- p.addPreferenceChangeListener(null);
- fail();
- } catch (NullPointerException e) {
+
+ @Override
+ protected AbstractPreferences childSpi(String name) {
+ return null;
}
- try {
- p.removePreferenceChangeListener(null);
- fail();
- } catch (IllegalStateException e) {
+
+ @Override
+ protected String[] childrenNamesSpi() throws BackingStoreException {
+ return null;
}
- try {
- p.addNodeChangeListener(null);
- fail();
- } catch (NullPointerException e) {
+
+ @Override
+ protected void flushSpi() throws BackingStoreException {
}
- try {
- p.removeNodeChangeListener(null);
- fail();
- } catch (IllegalStateException e) {
+
+ @Override
+ protected String getSpi(String key) {
+ return null;
}
- }
-
- /**
- * @test java.util.prefs.AbstractPreferences#childrenNamesSpi()
- *
- */
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "childrenNamesSpi",
- methodArgs = {}
- )
- })
- public void testChildrenNamesSpi() {
- MockAbstractPreferences p = new MockAbstractPreferences(
- (AbstractPreferences) Preferences.userRoot(), "mock");
- try {
- assertEquals(0, p.childrenNamesSpi().length);
- } catch(java.util.prefs.BackingStoreException bse) {
- fail("java.util.prefs.BackingStoreException is thrown: " +
- bse.toString());
+
+ @Override
+ protected String[] keysSpi() throws BackingStoreException {
+ return null;
}
- }
-
- /**
- * @test java.util.prefs.AbstractPreferences#childSpi()
- *
- */
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "childSpi",
- methodArgs = {java.lang.String.class}
- )
- })
- public void testChildSpi() {
- MockAbstractPreferences p = new MockAbstractPreferences(
- (AbstractPreferences) Preferences.userRoot(), "mock");
- Preferences child = p.node("mock1");
- assertEquals(child, p.childSpi("mock1"));
- }
-
- /**
- * @test java.util.prefs.AbstractPreferences#flushSpi()
- *
- */
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "flushSpi",
- methodArgs = {}
- )
- })
- public void testFlushSpi() {
- MockAbstractPreferences p = new MockAbstractPreferences(
- (AbstractPreferences) Preferences.userRoot(), "mock");
- try {
- p.flushSpi();
- } catch(Exception e) {
- fail("Unexpected exception was thrown: " + e.getMessage());
+
+ @Override
+ protected void putSpi(String key, String value) {
}
- }
-
- /**
- * @test java.util.prefs.AbstractPreferences#getSpi()
- *
- */
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "getSpi",
- methodArgs = {java.lang.String.class}
- )
- })
- public void testGetSpi() {
- MockAbstractPreferences p = new MockAbstractPreferences(
- (AbstractPreferences) Preferences.userRoot(), "mock");
- try {
- assertNull(p.getSpi(""));
- p.put("key", "default");
- assertEquals("default", p.getSpi("key"));
- } catch(Exception e) {
- fail("Unexpected exception was thrown: " + e.getMessage());
+
+ @Override
+ protected void removeNodeSpi() throws BackingStoreException {
}
- }
-
- /**
- * @test java.util.prefs.AbstractPreferences#keysSpi()
- *
- */
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "keysSpi",
- methodArgs = {}
- )
- })
- public void testKeysSpi() {
- MockAbstractPreferences p = new MockAbstractPreferences(
- (AbstractPreferences) Preferences.userRoot(), "mock");
- try {
- p.put("key1", "default");
- p.putInt("key2", 123);
- assertEquals(2, p.keysSpi().length);
- assertEquals("key2", p.keysSpi()[0]);
- assertEquals("key1", p.keysSpi()[1]);
- } catch(Exception e) {
- fail("Unexpected exception was thrown: " + e.getMessage());
+
+ @Override
+ protected void removeSpi(String key) {
}
- }
-
- /**
- * @test java.util.prefs.AbstractPreferences#putSpi()
- *
- */
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "putSpi",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- )
- })
- public void testPutSpi() {
- MockAbstractPreferences p = new MockAbstractPreferences(
- (AbstractPreferences) Preferences.userRoot(), "mock");
- try {
- p.putSpi("key1", "default");
- p.putSpi("key2", "123");
- assertEquals(2, p.keysSpi().length);
- assertEquals("key2", p.keysSpi()[0]);
- assertEquals("key1", p.keysSpi()[1]);
- } catch(Exception e) {
- fail("Unexpected exception was thrown: " + e.getMessage());
+
+ @Override
+ protected void syncSpi() throws BackingStoreException {
}
}
-
- /**
- * @test java.util.prefs.AbstractPreferences#removeSpi()
- *
- */
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "removeNodeSpi",
- methodArgs = {}
- )
- })
- public void testRemoveSpi() {
- MockAbstractPreferences p = new MockAbstractPreferences(
- (AbstractPreferences) Preferences.userRoot(), "mock");
- p.put("key1", "value1");
- try {
- p.removeSpi("key1");
- assertNull(p.getSpi("key1"));
- } catch(Exception e) {
- fail("Unexpected exception was thrown: " + e.getMessage());
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "AbstractPreferences",
+ args = {java.util.prefs.AbstractPreferences.class, java.lang.String.class}
+ )
+ public void testAbstractPreferences() {
+ assertNotNull(new MockAbstractPreferences(pref, "node name"));
+ try {
+ new MockAbstractPreferences(pref, "node/name");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
}
- }
-
- /**
- * @test java.util.prefs.AbstractPreferences#syncSpi()
- *
- */
-
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "syncSpi",
- methodArgs = {}
- )
- })
- public void testSyncSpi() {
- MockAbstractPreferences p = new MockAbstractPreferences(
- (AbstractPreferences) Preferences.userRoot(), "mock");
- p.put("key1", "value1");
+
try {
- p.syncSpi();
- } catch(Exception e) {
- fail("Unexpected exception was thrown: " + e.getMessage());
+ new MockAbstractPreferences(null, "node");
+ fail("IllegalArgumentException expected");
+ } catch (IllegalArgumentException e) {
+ //expected
}
}
-
- /**
- * Regression for HARMONY-828
- */
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Regression test",
- targets = {
- @TestTarget(
- methodName = "nodeExists",
- methodArgs = {java.lang.String.class}
- )
- })
- public void testLongPath() throws Exception {
- assertFalse(pref
- .nodeExists("ddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd"));
+
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Tested indirectly",
+ method = "cachedChildren",
+ args = {}
+ )
+ public void testCachedChildren() throws BackingStoreException {
+ pref.node("First node");
+ pref.node("Second node");
+
+ assertEquals(2, pref.childrenNames().length);
}
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "No reason to check dummy implementation",
+ method = "isRemoved",
+ args = {}
+ )
+ public void testIsRemoved() {
+ }
}
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AllTests.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AllTests.java
index cbcc77c..29ff362 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AllTests.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/AllTests.java
@@ -30,7 +30,7 @@ public class AllTests {
}
public static Test suite() {
- TestSuite suite = new TestSuite("Suite for org.apache.harmony.prefs.tests.java.util.prefs");
+ TestSuite suite = tests.TestSuiteFactory.createTestSuite("Suite for org.apache.harmony.prefs.tests.java.util.prefs");
// $JUnit-BEGIN$
suite.addTestSuite(NodeChangeListenerTest.class);
suite.addTestSuite(PreferenceChangeListenerTest.class);
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/BackingStoreExceptionTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/BackingStoreExceptionTest.java
index c34853c..a98c3b4 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/BackingStoreExceptionTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/BackingStoreExceptionTest.java
@@ -17,9 +17,9 @@
package org.apache.harmony.prefs.tests.java.util.prefs;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.util.prefs.BackingStoreException;
@@ -37,15 +37,12 @@ public class BackingStoreExceptionTest extends TestCase {
/*
* Class under test for void BackingStoreException(String)
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "BackingStoreException",
- methodArgs = {java.lang.String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "BackingStoreException",
+ args = {java.lang.String.class}
+ )
public void testBackingStoreExceptionString() {
BackingStoreException e = new BackingStoreException("msg");
assertNull(e.getCause());
@@ -55,15 +52,12 @@ public class BackingStoreExceptionTest extends TestCase {
/*
* Class under test for void BackingStoreException(Throwable)
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "BackingStoreException",
- methodArgs = {java.lang.Throwable.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "BackingStoreException",
+ args = {java.lang.Throwable.class}
+ )
public void testBackingStoreExceptionThrowable() {
Throwable t = new Throwable("msg");
BackingStoreException e = new BackingStoreException(t);
@@ -75,15 +69,12 @@ public class BackingStoreExceptionTest extends TestCase {
/**
* @tests serialization/deserialization.
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Verifies serialization",
- targets = {
- @TestTarget(
- methodName = "!SerializationSelf",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization",
+ method = "!SerializationSelf",
+ args = {}
+ )
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new BackingStoreException("msg"));
@@ -92,15 +83,12 @@ public class BackingStoreExceptionTest extends TestCase {
/**
* @tests serialization/deserialization compatibility with RI.
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Verifies serialization",
- targets = {
- @TestTarget(
- methodName = "!SerializationGolden",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization",
+ method = "!SerializationGolden",
+ args = {}
+ )
public void testSerializationCompatibility() throws Exception {
SerializationTest.verifyGolden(this, new BackingStoreException("msg"));
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java
index 2b641ab..7f7c296 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/FilePreferencesImplTest.java
@@ -16,10 +16,11 @@
package org.apache.harmony.prefs.tests.java.util.prefs;
+import dalvik.annotation.BrokenTest;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.io.FilePermission;
import java.io.IOException;
@@ -51,26 +52,30 @@ public class FilePreferencesImplTest extends TestCase {
}
protected void tearDown() throws Exception {
- if (prevFactory != null)
- System.setProperty("java.util.prefs.PreferencesFactory", prevFactory);
-
+ // if (prevFactory != null)
+ // System.setProperty("java.util.prefs.PreferencesFactory", prevFactory);
uroot = null;
sroot = null;
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Exceptions checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "put",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- ), @TestTarget(
- methodName = "get",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- ), @TestTarget(
- methodName = "keys",
- methodArgs = {}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Exceptions checking missed, but method is abstract, probably it is OK",
+ method = "put",
+ args = {java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Exceptions checking missed, but method is abstract, probably it is OK",
+ method = "get",
+ args = {java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Exceptions checking missed, but method is abstract, probably it is OK",
+ method = "keys",
+ args = {}
)
})
public void testPutGet() throws IOException, BackingStoreException {
@@ -96,26 +101,26 @@ public class FilePreferencesImplTest extends TestCase {
assertEquals("\u4e2d value1", sroot.get("\u4e2d key1", null));
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Exceptions checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "childrenNames",
- methodArgs = {}
- )
- })
- public void _testChildNodes() throws Exception {
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Exceptions checking missed, but method is abstract, probably it is OK",
+ method = "childrenNames",
+ args = {}
+ )
+ @BrokenTest("Checking of childNames.length is not valid because of " +
+ "it depends on .userPrefs")
+ public void testChildNodes() throws Exception {
+
Preferences child1 = uroot.node("child1");
Preferences child2 = uroot.node("\u4e2d child2");
Preferences grandchild = child1.node("grand");
assertNotNull(grandchild);
String[] childNames = uroot.childrenNames();
- assertEquals(4, childNames.length);
for (int i = 0; i < childNames.length; i++) {
- System.out.println(childNames[i]);
- }
+ System.out.println("test:" + childNames[i]);
+ }
+ assertEquals(4, childNames.length);
childNames = child1.childrenNames();
assertEquals(1, childNames.length);
@@ -163,25 +168,36 @@ public class FilePreferencesImplTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "SecurityException checking only, but methods are abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "node",
- methodArgs = {java.lang.String.class}
- ), @TestTarget(
- methodName = "removeNode",
- methodArgs = {}
- ), @TestTarget(
- methodName = "childrenNames",
- methodArgs = {}
- ), @TestTarget(
- methodName = "flush",
- methodArgs = {}
- ), @TestTarget(
- methodName = "sync",
- methodArgs = {}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "SecurityException checking only, but methods are abstract, probably it is OK",
+ method = "node",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "SecurityException checking only, but methods are abstract, probably it is OK",
+ method = "removeNode",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "SecurityException checking only, but methods are abstract, probably it is OK",
+ method = "childrenNames",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "SecurityException checking only, but methods are abstract, probably it is OK",
+ method = "flush",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "SecurityException checking only, but methods are abstract, probably it is OK",
+ method = "sync",
+ args = {}
)
})
public void testSecurityException() throws BackingStoreException {
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java
index 39ef9f3..28c953e 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/InvalidPreferencesFormatExceptionTest.java
@@ -17,9 +17,9 @@
package org.apache.harmony.prefs.tests.java.util.prefs;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.util.prefs.InvalidPreferencesFormatException;
@@ -36,15 +36,12 @@ public class InvalidPreferencesFormatExceptionTest extends TestCase {
/*
* Class under test for void InvalidPreferencesFormatException(String)
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "InvalidPreferencesFormatException",
- methodArgs = {java.lang.String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "InvalidPreferencesFormatException",
+ args = {java.lang.String.class}
+ )
public void testInvalidPreferencesFormatExceptionString() {
InvalidPreferencesFormatException e = new InvalidPreferencesFormatException(
"msg");
@@ -56,15 +53,12 @@ public class InvalidPreferencesFormatExceptionTest extends TestCase {
* Class under test for void InvalidPreferencesFormatException(String,
* Throwable)
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "InvalidPreferencesFormatException",
- methodArgs = {java.lang.String.class, java.lang.Throwable.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "InvalidPreferencesFormatException",
+ args = {java.lang.String.class, java.lang.Throwable.class}
+ )
public void testInvalidPreferencesFormatExceptionStringThrowable() {
Throwable t = new Throwable("root");
InvalidPreferencesFormatException e = new InvalidPreferencesFormatException(
@@ -78,15 +72,12 @@ public class InvalidPreferencesFormatExceptionTest extends TestCase {
/*
* Class under test for void InvalidPreferencesFormatException(Throwable)
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "InvalidPreferencesFormatException",
- methodArgs = {java.lang.Throwable.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "InvalidPreferencesFormatException",
+ args = {java.lang.Throwable.class}
+ )
public void testInvalidPreferencesFormatExceptionThrowable() {
Throwable t = new Throwable("root");
InvalidPreferencesFormatException e = new InvalidPreferencesFormatException(
@@ -99,15 +90,12 @@ public class InvalidPreferencesFormatExceptionTest extends TestCase {
/**
* @tests serialization/deserialization.
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Verifies serialization",
- targets = {
- @TestTarget(
- methodName = "!SerializationSelf",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization",
+ method = "!SerializationSelf",
+ args = {}
+ )
public void testSerializationSelf() throws Exception {
SerializationTest.verifySelf(new InvalidPreferencesFormatException(
@@ -117,15 +105,12 @@ public class InvalidPreferencesFormatExceptionTest extends TestCase {
/**
* @tests serialization/deserialization compatibility with RI.
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Verifies serialization",
- targets = {
- @TestTarget(
- methodName = "!SerializationGolden",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization",
+ method = "!SerializationGolden",
+ args = {}
+ )
public void testSerializationCompatibility() throws Exception {
SerializationTest.verifyGolden(this,
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockNodeChangeListener.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockNodeChangeListener.java
index 4902343..6e042fa 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockNodeChangeListener.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockNodeChangeListener.java
@@ -5,10 +5,6 @@ import java.util.prefs.NodeChangeListener;
import java.util.prefs.Preferences;
public class MockNodeChangeListener implements NodeChangeListener {
- private boolean addDispatched = false;
-
- private boolean removeDispatched = false;
-
private Object addLock = new Object();
private Object removeLock = new Object();
@@ -34,6 +30,15 @@ public class MockNodeChangeListener implements NodeChangeListener {
public MockNodeChangeListener() {
}
+
+ public void waitForEvent() {
+ try {
+ synchronized (addLock) {
+ addLock.wait(500);
+ }
+ } catch (InterruptedException e) {
+ }
+ }
public void childAdded(NodeChangeEvent e) {
@@ -62,7 +67,6 @@ public class MockNodeChangeListener implements NodeChangeListener {
break;
}
++added;
- addDispatched = true;
addLock.notifyAll();
}
}
@@ -93,69 +97,32 @@ public class MockNodeChangeListener implements NodeChangeListener {
break;
}
removed++;
- removeDispatched = true;
removeLock.notifyAll();
}
}
public boolean getAddResult() {
synchronized (addLock) {
- if (!addDispatched) {
- try {
- // TODO: don't know why must add limitation
- addLock.wait(100);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- addDispatched = false;
+ return addResult;
}
- return addResult;
}
public boolean getRemoveResult() {
synchronized (removeLock) {
- if (!removeDispatched) {
- try {
- // TODO: don't know why must add limitation
- removeLock.wait(100);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- removeDispatched = false;
+ return removeResult;
}
- return removeResult;
}
public int getAdded() {
synchronized (addLock) {
- if (!addDispatched) {
- try {
- // TODO: don't know why must add limitation
- addLock.wait(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- addDispatched = false;
+ return added;
}
- return added;
}
public int getRemoved() {
synchronized (removeLock) {
- if (!removeDispatched) {
- try {
- removeLock.wait(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- removeDispatched = false;
+ return removed;
}
- return removed;
-
}
public void reset() {
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferenceChangeListener.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferenceChangeListener.java
index 0e62daf..9d628a2 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferenceChangeListener.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferenceChangeListener.java
@@ -28,6 +28,22 @@ public class MockPreferenceChangeListener implements PreferenceChangeListener {
public MockPreferenceChangeListener(int test) {
testNum = test;
}
+
+ public void waitForEvent() {
+ waitForEvent(1);
+ }
+
+
+ public void waitForEvent(int count) {
+ for (int i = 0; i < count; i++) {
+ try {
+ synchronized (lock) {
+ lock.wait(500);
+ }
+ } catch (InterruptedException e) {
+ }
+ }
+ }
// private Object lock = new Object();
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferencesFactory.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferencesFactory.java
deleted file mode 100644
index 37db55d..0000000
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/MockPreferencesFactory.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/* Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.harmony.prefs.tests.java.util.prefs;
-
-import java.util.prefs.Preferences;
-import java.util.prefs.PreferencesFactory;
-
-/**
- *
- */
-public class MockPreferencesFactory implements PreferencesFactory {
- static MockAbstractPreferences userRoot = new MockAbstractPreferences(null,
- "");
-
- static MockAbstractPreferences systemRoot = new MockAbstractPreferences(
- null, "");
-
- public MockPreferencesFactory() {
- }
-
- public Preferences userRoot() {
- return userRoot;
- }
-
- public Preferences systemRoot() {
- return systemRoot;
- }
-}
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeEventTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeEventTest.java
index b565924..3260a04 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeEventTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeEventTest.java
@@ -17,9 +17,9 @@
package org.apache.harmony.prefs.tests.java.util.prefs;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.io.NotSerializableException;
import java.util.prefs.AbstractPreferences;
@@ -39,15 +39,12 @@ public class NodeChangeEventTest extends TestCase {
NodeChangeEvent event;
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "NodeChangeEvent",
- methodArgs = {java.util.prefs.Preferences.class, java.util.prefs.Preferences.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "NodeChangeEvent",
+ args = {java.util.prefs.Preferences.class, java.util.prefs.Preferences.class}
+ )
public void testConstructor() {
event = new NodeChangeEvent(Preferences.systemRoot(), Preferences
.userRoot());
@@ -56,15 +53,12 @@ public class NodeChangeEventTest extends TestCase {
assertSame(Preferences.systemRoot(), event.getSource());
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "NodeChangeEvent",
- methodArgs = {java.util.prefs.Preferences.class, java.util.prefs.Preferences.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "NodeChangeEvent",
+ args = {java.util.prefs.Preferences.class, java.util.prefs.Preferences.class}
+ )
public void testConstructorNullParam() {
try {
event = new NodeChangeEvent(null, Preferences.userRoot());
@@ -78,15 +72,12 @@ public class NodeChangeEventTest extends TestCase {
assertSame(Preferences.systemRoot(), event.getSource());
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Verifies serialization",
- targets = {
- @TestTarget(
- methodName = "!Serialization",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization",
+ method = "!Serialization",
+ args = {}
+ )
public void testSerialization() throws Exception {
event = new NodeChangeEvent(Preferences.systemRoot(), null);
@@ -98,15 +89,12 @@ public class NodeChangeEventTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Test is correct, functionality checked in separate Mock class.",
- targets = {
- @TestTarget(
- methodName = "getChild",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test is correct, functionality checked in separate Mock class.",
+ method = "getChild",
+ args = {}
+ )
public void testGetChild() throws BackingStoreException {
AbstractPreferences parent = (AbstractPreferences) Preferences
@@ -119,10 +107,12 @@ public class NodeChangeEventTest extends TestCase {
try {
pref.addNodeChangeListener(nl);
Preferences child1 = pref.node("mock1");
+ nl.waitForEvent();
assertEquals(1, nl.getAdded());
assertTrue(nl.getAddResult());
nl.reset();
child1.removeNode();
+ nl.waitForEvent();
assertEquals(1, nl.getRemoved());
assertTrue(nl.getRemoveResult());
nl.reset();
@@ -131,15 +121,12 @@ public class NodeChangeEventTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Test is correct, functionality checked in separate Mock class.",
- targets = {
- @TestTarget(
- methodName = "getParent",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test is correct, functionality checked in separate Mock class.",
+ method = "getParent",
+ args = {}
+ )
public void testGetParent() throws BackingStoreException {
AbstractPreferences parent = (AbstractPreferences) Preferences
@@ -152,10 +139,12 @@ public class NodeChangeEventTest extends TestCase {
try {
pref.addNodeChangeListener(nl);
Preferences child1 = pref.node("mock1");
+ nl.waitForEvent();
assertEquals(1, nl.getAdded());
assertTrue(nl.getAddResult());
nl.reset();
child1.removeNode();
+ nl.waitForEvent();
assertEquals(1, nl.getRemoved());
assertTrue(nl.getRemoveResult());
nl.reset();
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeListenerTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeListenerTest.java
index 5ef4f50..c5e3252 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeListenerTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/NodeChangeListenerTest.java
@@ -17,9 +17,9 @@
package org.apache.harmony.prefs.tests.java.util.prefs;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.util.prefs.NodeChangeEvent;
import java.util.prefs.NodeChangeListener;
@@ -50,29 +50,23 @@ public class NodeChangeListenerTest extends TestCase {
super.tearDown();
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Testing Interface",
- targets = {
- @TestTarget(
- methodName = "childAdded",
- methodArgs = {java.util.prefs.NodeChangeEvent.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Testing Interface",
+ method = "childAdded",
+ args = {java.util.prefs.NodeChangeEvent.class}
+ )
public void testChildAdded() {
l.childAdded(new NodeChangeEvent(Preferences.userRoot(), Preferences
.userRoot()));
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Testing Interface",
- targets = {
- @TestTarget(
- methodName = "childRemoved",
- methodArgs = {java.util.prefs.NodeChangeEvent.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Testing Interface",
+ method = "childRemoved",
+ args = {java.util.prefs.NodeChangeEvent.class}
+ )
public void testChildRemoved() {
l.childRemoved(new NodeChangeEvent(Preferences.userRoot(), Preferences
.userRoot()));
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeEventTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeEventTest.java
index 267ac28..4030b89 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeEventTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeEventTest.java
@@ -17,9 +17,9 @@
package org.apache.harmony.prefs.tests.java.util.prefs;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.io.NotSerializableException;
import java.util.prefs.AbstractPreferences;
@@ -38,15 +38,12 @@ public class PreferenceChangeEventTest extends TestCase {
PreferenceChangeEvent event;
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Checks exception.",
- targets = {
- @TestTarget(
- methodName = "PreferenceChangeEvent",
- methodArgs = {java.util.prefs.Preferences.class, java.lang.String.class, java.lang.String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Checks exception.",
+ method = "PreferenceChangeEvent",
+ args = {java.util.prefs.Preferences.class, java.lang.String.class, java.lang.String.class}
+ )
public void testPreferenceChangeEventException() {
try {
event = new PreferenceChangeEvent(null, "key", "value");
@@ -55,15 +52,12 @@ public class PreferenceChangeEventTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "PreferenceChangeEvent",
- methodArgs = {java.util.prefs.Preferences.class, java.lang.String.class, java.lang.String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "PreferenceChangeEvent",
+ args = {java.util.prefs.Preferences.class, java.lang.String.class, java.lang.String.class}
+ )
public void testConstructorNullValue() {
event = new PreferenceChangeEvent(Preferences.userRoot(), "key", null);
assertEquals("key", event.getKey());
@@ -90,15 +84,12 @@ public class PreferenceChangeEventTest extends TestCase {
assertSame(Preferences.userRoot(), event.getSource());
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "PreferenceChangeEvent",
- methodArgs = {java.util.prefs.Preferences.class, java.lang.String.class, java.lang.String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "PreferenceChangeEvent",
+ args = {java.util.prefs.Preferences.class, java.lang.String.class, java.lang.String.class}
+ )
public void testConstructor() {
event = new PreferenceChangeEvent(Preferences.userRoot(), "key",
"value");
@@ -108,15 +99,12 @@ public class PreferenceChangeEventTest extends TestCase {
assertSame(Preferences.userRoot(), event.getSource());
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Verifies serialization",
- targets = {
- @TestTarget(
- methodName = "!Serialization",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Verifies serialization",
+ method = "!Serialization",
+ args = {}
+ )
public void testSerialization() throws Exception {
event = new PreferenceChangeEvent(Preferences.userRoot(), "key",
"value");
@@ -127,15 +115,12 @@ public class PreferenceChangeEventTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Test is correct, functionality checked in separate Mock class.",
- targets = {
- @TestTarget(
- methodName = "getKey",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test is correct, functionality checked in separate Mock class.",
+ method = "getKey",
+ args = {}
+ )
public void testGetKey() {
AbstractPreferences parent = (AbstractPreferences) Preferences
.userNodeForPackage(Preferences.class);
@@ -155,15 +140,12 @@ public class PreferenceChangeEventTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Test is correct, functionality checked in separate Mock class.",
- targets = {
- @TestTarget(
- methodName = "getNewValue",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test is correct, functionality checked in separate Mock class.",
+ method = "getNewValue",
+ args = {}
+ )
public void testGetNewValue() {
AbstractPreferences parent = (AbstractPreferences) Preferences
.userNodeForPackage(Preferences.class);
@@ -188,15 +170,12 @@ public class PreferenceChangeEventTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Test is correct, functionality checked in separate Mock class.",
- targets = {
- @TestTarget(
- methodName = "getNode",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test is correct, functionality checked in separate Mock class.",
+ method = "getNode",
+ args = {}
+ )
public void testGetNode() {
AbstractPreferences parent = (AbstractPreferences) Preferences
.userNodeForPackage(Preferences.class);
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeListenerTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeListenerTest.java
index 3dd2b17..e4df9c4 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeListenerTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferenceChangeListenerTest.java
@@ -17,9 +17,9 @@
package org.apache.harmony.prefs.tests.java.util.prefs;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.util.prefs.PreferenceChangeEvent;
import java.util.prefs.PreferenceChangeListener;
@@ -43,15 +43,12 @@ public class PreferenceChangeListenerTest extends TestCase {
l = new PreferenceChangeListenerImpl();
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Testing Interface",
- targets = {
- @TestTarget(
- methodName = "preferenceChange",
- methodArgs = {java.util.prefs.PreferenceChangeEvent.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Testing Interface",
+ method = "preferenceChange",
+ args = {java.util.prefs.PreferenceChangeEvent.class}
+ )
public void testPreferenceChange() {
l.preferenceChange(new PreferenceChangeEvent(Preferences.userRoot(),
"", ""));
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesFactoryTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesFactoryTest.java
index 2badc99..818d5ad 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesFactoryTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesFactoryTest.java
@@ -17,9 +17,9 @@
package org.apache.harmony.prefs.tests.java.util.prefs;
import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.TestTargets;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetNew;
import java.util.prefs.Preferences;
import java.util.prefs.PreferencesFactory;
@@ -42,28 +42,22 @@ public class PreferencesFactoryTest extends TestCase {
f = new PreferencesFactoryImpl();
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Testing Interface",
- targets = {
- @TestTarget(
- methodName = "userRoot",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Testing Interface",
+ method = "userRoot",
+ args = {}
+ )
public void testUserRoot() {
f.userRoot();
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Testing Interface",
- targets = {
- @TestTarget(
- methodName = "userRoot",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Testing Interface",
+ method = "systemRoot",
+ args = {}
+ )
public void testSystemRoot() {
f.systemRoot();
}
diff --git a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java
index 25f891e..2221cc5 100644
--- a/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java
+++ b/prefs/src/test/java/org/apache/harmony/prefs/tests/java/util/prefs/PreferencesTest.java
@@ -16,12 +16,16 @@
package org.apache.harmony.prefs.tests.java.util.prefs;
-import dalvik.annotation.TestTargetClass;
-import dalvik.annotation.TestInfo;
+import dalvik.annotation.KnownFailure;
import dalvik.annotation.TestLevel;
-import dalvik.annotation.TestTarget;
+import dalvik.annotation.TestTargetClass;
+import dalvik.annotation.TestTargetNew;
+import dalvik.annotation.TestTargets;
+
+import junit.framework.TestCase;
import java.io.ByteArrayInputStream;
+import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -35,8 +39,6 @@ import java.util.prefs.NodeChangeListener;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;
-import junit.framework.TestCase;
-
/**
*
*/
@@ -75,6 +77,24 @@ public class PreferencesTest extends TestCase {
"<!DOCTYPE preferences SYSTEM \"http://java.sun.com/dtd/preferences.dtd\"><preferences><root type=\"user\"><map></map></root></preferences>"
.getBytes("UTF-8"));
stream = new MockInputStream(in);
+
+ String userHome = System.getProperty("user.home");
+ if (userHome != null) {
+ File userHomeDir = new File(userHome);
+ if (!userHomeDir.isDirectory() || !userHomeDir.canWrite()) {
+ userHome = null;
+ }
+ }
+ if (userHome == null) {
+ System.setProperty("user.home", System.getProperty("java.io.tmpdir"));
+ }
+
+ Preferences p = Preferences.userNodeForPackage(Preferences.class);
+ p.clear();
+ try {
+ p.removeNode();
+ } catch (BackingStoreException e) {
+ }
}
/*
@@ -83,18 +103,21 @@ public class PreferencesTest extends TestCase {
protected void tearDown() throws Exception {
super.tearDown();
stream.close();
+ Preferences p = Preferences.userNodeForPackage(Preferences.class);
+ p.clear();
+ try {
+ p.removeNode();
+ } catch (BackingStoreException e) {
+ }
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "systemNodeForPackage",
- methodArgs = {java.lang.Class.class}
- )
- })
- public void testSystemNodeForPackage() throws BackingStoreException {
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "systemNodeForPackage",
+ args = {java.lang.Class.class}
+ )
+ public void testSystemNodeForPackage() {
Preferences p = null;
try {
p = Preferences.systemNodeForPackage(Object.class);
@@ -130,16 +153,13 @@ public class PreferencesTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "SecurityException checking missed.",
- targets = {
- @TestTarget(
- methodName = "systemRoot",
- methodArgs = {}
- )
- })
- public void testSystemRoot() throws BackingStoreException {
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "SecurityException checking missed.",
+ method = "systemRoot",
+ args = {}
+ )
+ public void testSystemRoot() {
Preferences p = Preferences.systemRoot();
assertTrue(p instanceof AbstractPreferences);
assertEquals("/", p.absolutePath());
@@ -152,30 +172,24 @@ public class PreferencesTest extends TestCase {
// assertEquals(0, p.keys().length);
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Checks constant values",
- targets = {
- @TestTarget(
- methodName = "!Constants",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Checks constant values",
+ method = "!Constants",
+ args = {}
+ )
public void testConsts() {
assertEquals(80, Preferences.MAX_KEY_LENGTH);
assertEquals(80, Preferences.MAX_NAME_LENGTH);
assertEquals(8192, Preferences.MAX_VALUE_LENGTH);
}
-@TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "SecurityException checking missed.",
- targets = {
- @TestTarget(
- methodName = "userNodeForPackage",
- methodArgs = {java.lang.Class.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "SecurityException checking missed.",
+ method = "userNodeForPackage",
+ args = {java.lang.Class.class}
+ )
public void testUserNodeForPackage() throws BackingStoreException {
Preferences p = Preferences.userNodeForPackage(Object.class);
assertEquals("/java/lang", p.absolutePath());
@@ -196,16 +210,13 @@ public class PreferencesTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "SecurityException checking missed.",
- targets = {
- @TestTarget(
- methodName = "userRoot",
- methodArgs = {}
- )
- })
- public void testUserRoot() throws BackingStoreException {
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "SecurityException checking missed.",
+ method = "userRoot",
+ args = {}
+ )
+ public void testUserRoot() {
Preferences p = Preferences.userRoot();
assertTrue(p instanceof AbstractPreferences);
assertEquals("/", p.absolutePath());
@@ -217,16 +228,40 @@ public class PreferencesTest extends TestCase {
// assertEquals(p.keys().length, 0);
}
-@TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "SecurityException & IOException checking missed.",
- targets = {
- @TestTarget(
- methodName = "importPreferences",
- methodArgs = {java.io.InputStream.class}
+
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "SecurityException & IOException checking missed.",
+ method = "importPreferences",
+ args = {java.io.InputStream.class}
)
- })
- public void _testImportPreferences() throws Exception {
+ @KnownFailure("xml validation does not work")
+ public void testImportPreferences2() throws Exception {
+ InputStream in = PreferencesTest.class
+ .getResourceAsStream("/prefs/java/util/prefs/userprefs-badtype.xml");
+ try {
+ Preferences.importPreferences(in);
+ fail();
+ } catch (InvalidPreferencesFormatException e) {
+ }
+
+ in = PreferencesTest.class
+ .getResourceAsStream("/prefs/java/util/prefs/userprefs-badencoding.xml");
+ try {
+ Preferences.importPreferences(in);
+ fail();
+ } catch (InvalidPreferencesFormatException e) {
+ } catch (UnsupportedEncodingException e) {
+ }
+
+ }
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "SecurityException & IOException checking missed.",
+ method = "importPreferences",
+ args = {java.io.InputStream.class}
+ )
+ public void testImportPreferences() throws Exception {
Preferences prefs = null;
try {
prefs = Preferences.userNodeForPackage(PreferencesTest.class);
@@ -254,22 +289,6 @@ public class PreferencesTest extends TestCase {
}
in = PreferencesTest.class
- .getResourceAsStream("/prefs/java/util/prefs/userprefs-badtype.xml");
- try {
- Preferences.importPreferences(in);
- fail();
- } catch (InvalidPreferencesFormatException e) {
- }
-
- // in = PreferencesTest.class
- // .getResourceAsStream("/prefs/java/util/prefs/userprefs-badencoding.xml");
- // try {
- // Preferences.importPreferences(in);
- // fail();
- // } catch (InvalidPreferencesFormatException e) {
- // }
-
- in = PreferencesTest.class
.getResourceAsStream("/prefs/java/util/prefs/userprefs-higherversion.xml");
try {
Preferences.importPreferences(in);
@@ -290,15 +309,12 @@ public class PreferencesTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "Test for Exceptions only.",
- targets = {
- @TestTarget(
- methodName = "importPreferences",
- methodArgs = {java.io.InputStream.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "Test for Exceptions only.",
+ method = "importPreferences",
+ args = {java.io.InputStream.class}
+ )
public void testImportPreferencesException() throws Exception {
try {
Preferences.importPreferences(null);
@@ -329,25 +345,36 @@ public class PreferencesTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.PARTIAL_OK,
- purpose = "SecurityException checking.",
- targets = {
- @TestTarget(
- methodName = "userRoot",
- methodArgs = {}
- ), @TestTarget(
- methodName = "systemRoot",
- methodArgs = {}
- ), @TestTarget(
- methodName = "userNodeForPackage",
- methodArgs = {java.lang.Class.class}
- ), @TestTarget(
- methodName = "systemNodeForPackage",
- methodArgs = {java.lang.Class.class}
- ), @TestTarget(
- methodName = "importPreferences",
- methodArgs = {java.io.InputStream.class}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "SecurityException checking.",
+ method = "userRoot",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "SecurityException checking.",
+ method = "systemRoot",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "SecurityException checking.",
+ method = "userNodeForPackage",
+ args = {java.lang.Class.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "SecurityException checking.",
+ method = "systemNodeForPackage",
+ args = {java.lang.Class.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.PARTIAL_COMPLETE,
+ notes = "SecurityException checking.",
+ method = "importPreferences",
+ args = {java.io.InputStream.class}
)
})
public void testSecurity() throws InvalidPreferencesFormatException,
@@ -386,112 +413,210 @@ public class PreferencesTest extends TestCase {
}
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Test for abstract methods.",
- targets = {
- @TestTarget(
- methodName = "absolutePath",
- methodArgs = {}
- ), @TestTarget(
- methodName = "childrenNames",
- methodArgs = {}
- ), @TestTarget(
- methodName = "clear",
- methodArgs = {}
- ), @TestTarget(
- methodName = "exportNode",
- methodArgs = {java.io.OutputStream.class}
- ), @TestTarget(
- methodName = "exportSubtree",
- methodArgs = {java.io.OutputStream.class}
- ), @TestTarget(
- methodName = "flush",
- methodArgs = {}
- ), @TestTarget(
- methodName = "get",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- ), @TestTarget(
- methodName = "getBoolean",
- methodArgs = {java.lang.String.class, boolean.class}
- ), @TestTarget(
- methodName = "getByteArray",
- methodArgs = {java.lang.String.class, byte[].class}
- ), @TestTarget(
- methodName = "getFloat",
- methodArgs = {java.lang.String.class, float.class}
- ), @TestTarget(
- methodName = "getDouble",
- methodArgs = {java.lang.String.class, double.class}
- ), @TestTarget(
- methodName = "getInt",
- methodArgs = {java.lang.String.class, int.class}
- ), @TestTarget(
- methodName = "getLong",
- methodArgs = {java.lang.String.class, long.class}
- ), @TestTarget(
- methodName = "isUserNode",
- methodArgs = {}
- ), @TestTarget(
- methodName = "keys",
- methodArgs = {}
- ), @TestTarget(
- methodName = "name",
- methodArgs = {}
- ), @TestTarget(
- methodName = "node",
- methodArgs = {java.lang.String.class}
- ), @TestTarget(
- methodName = "nodeExists",
- methodArgs = {java.lang.String.class}
- ), @TestTarget(
- methodName = "parent",
- methodArgs = {}
- ), @TestTarget(
- methodName = "put",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- ), @TestTarget(
- methodName = "putBoolean",
- methodArgs = {java.lang.String.class, boolean.class}
- ), @TestTarget(
- methodName = "putByteArray",
- methodArgs = {java.lang.String.class, byte[].class}
- ), @TestTarget(
- methodName = "putDouble",
- methodArgs = {java.lang.String.class, double.class}
- ), @TestTarget(
- methodName = "putFloat",
- methodArgs = {java.lang.String.class, float.class}
- ), @TestTarget(
- methodName = "putInt",
- methodArgs = {java.lang.String.class, int.class}
- ), @TestTarget(
- methodName = "putLong",
- methodArgs = {java.lang.String.class, long.class}
- ), @TestTarget(
- methodName = "remove",
- methodArgs = {java.lang.String.class}
- ), @TestTarget(
- methodName = "removeNode",
- methodArgs = {}
- ), @TestTarget(
- methodName = "addNodeChangeListener",
- methodArgs = {java.util.prefs.NodeChangeListener.class}
- ), @TestTarget(
- methodName = "addPreferenceChangeListener",
- methodArgs = {java.util.prefs.PreferenceChangeListener.class}
- ), @TestTarget(
- methodName = "removeNodeChangeListener",
- methodArgs = {java.util.prefs.NodeChangeListener.class}
- ), @TestTarget(
- methodName = "removePreferenceChangeListener",
- methodArgs = {java.util.prefs.PreferenceChangeListener.class}
- ), @TestTarget(
- methodName = "sync",
- methodArgs = {}
- ), @TestTarget(
- methodName = "toString",
- methodArgs = {}
+ @TestTargets({
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "absolutePath",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "childrenNames",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "clear",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "exportNode",
+ args = {java.io.OutputStream.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "exportSubtree",
+ args = {java.io.OutputStream.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "flush",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "get",
+ args = {java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "getBoolean",
+ args = {java.lang.String.class, boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "getByteArray",
+ args = {java.lang.String.class, byte[].class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "getFloat",
+ args = {java.lang.String.class, float.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "getDouble",
+ args = {java.lang.String.class, double.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "getInt",
+ args = {java.lang.String.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "getLong",
+ args = {java.lang.String.class, long.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "isUserNode",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "keys",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "name",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "node",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "nodeExists",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "parent",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "put",
+ args = {java.lang.String.class, java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "putBoolean",
+ args = {java.lang.String.class, boolean.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "putByteArray",
+ args = {java.lang.String.class, byte[].class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "putDouble",
+ args = {java.lang.String.class, double.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "putFloat",
+ args = {java.lang.String.class, float.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "putInt",
+ args = {java.lang.String.class, int.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "putLong",
+ args = {java.lang.String.class, long.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "remove",
+ args = {java.lang.String.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "removeNode",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "addNodeChangeListener",
+ args = {java.util.prefs.NodeChangeListener.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "addPreferenceChangeListener",
+ args = {java.util.prefs.PreferenceChangeListener.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "removeNodeChangeListener",
+ args = {java.util.prefs.NodeChangeListener.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "removePreferenceChangeListener",
+ args = {java.util.prefs.PreferenceChangeListener.class}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "sync",
+ args = {}
+ ),
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Test for abstract methods.",
+ method = "toString",
+ args = {}
)
})
public void testAbstractMethods() {
@@ -561,29 +686,23 @@ public class PreferencesTest extends TestCase {
p.toString();
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "Preferences",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "Preferences",
+ args = {}
+ )
public void testConstructor() {
MockPreferences mp = new MockPreferences();
assertEquals(mp.getClass(), MockPreferences.class);
}
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "Check existed implementation",
- targets = {
- @TestTarget(
- methodName = "toString",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "Check existed implementation",
+ method = "toString",
+ args = {}
+ )
public void testToString() {
Preferences p1 = Preferences.userNodeForPackage(Preferences.class);
assertNotNull(p1.toString());
@@ -598,15 +717,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#absolutePath()
*
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "absolutePath",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "absolutePath",
+ args = {}
+ )
public void testAbsolutePath() {
Preferences p = Preferences.userNodeForPackage(Preferences.class);
assertEquals("/java/util/prefs", p.absolutePath());
@@ -617,15 +733,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#childrenNames()
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "childrenNames",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "childrenNames",
+ args = {}
+ )
public void testChildrenNames() throws BackingStoreException {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
@@ -636,7 +749,7 @@ public class PreferencesTest extends TestCase {
child1.node("subchild1");
assertSame(pref, child1.parent());
- assertEquals(4, pref.childrenNames().length);
+ assertEquals(3, pref.childrenNames().length);
assertEquals("child1", pref.childrenNames()[0]);
assertEquals(1, child1.childrenNames().length);
assertEquals("subchild1", child1.childrenNames()[0]);
@@ -646,15 +759,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#clear()
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "clear",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "clear",
+ args = {}
+ )
public void testClear() throws BackingStoreException {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
pref.put("testClearKey", "testClearValue");
@@ -670,15 +780,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#get(String key, String def)
*
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "get",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "get",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void testGet() throws BackingStoreException {
Preferences root = Preferences.userNodeForPackage(Preferences.class);
Preferences pref = root.node("mock");
@@ -717,15 +824,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#getBoolean(String key, boolean def)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "getBoolean",
- methodArgs = {java.lang.String.class, boolean.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "getBoolean",
+ args = {java.lang.String.class, boolean.class}
+ )
public void testGetBoolean() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
@@ -744,16 +848,13 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#getByteArray(String key, byte[] def)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "getByteArray",
- methodArgs = {java.lang.String.class, byte[].class}
- )
- })
- public void testGetByteArray() throws UnsupportedEncodingException {
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "getByteArray",
+ args = {java.lang.String.class, byte[].class}
+ )
+ public void testGetByteArray() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
pref.getByteArray(null, new byte[0]);
@@ -784,15 +885,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#getDouble(String key, double def)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "getDouble",
- methodArgs = {java.lang.String.class, double.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "getDouble",
+ args = {java.lang.String.class, double.class}
+ )
public void testGetDouble() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
@@ -815,15 +913,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#getFloat(String key, float def)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "getFloat",
- methodArgs = {java.lang.String.class, float.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "getFloat",
+ args = {java.lang.String.class, float.class}
+ )
public void testGetFloat() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
@@ -841,15 +936,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#getInt(String key, int def)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "getInt",
- methodArgs = {java.lang.String.class, int.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "getInt",
+ args = {java.lang.String.class, int.class}
+ )
public void testGetInt() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
@@ -868,15 +960,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#getLong(String key, long def)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "getLong",
- methodArgs = {java.lang.String.class, long.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "getLong",
+ args = {java.lang.String.class, long.class}
+ )
public void testGetLong() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
@@ -895,15 +984,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#isUserNode()
*
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "isUserNode",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "isUserNode",
+ args = {}
+ )
public void testIsUserNode() {
Preferences pref1 = Preferences.userNodeForPackage(Preferences.class);
assertTrue(pref1.isUserNode());
@@ -916,15 +1002,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#keys()
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Exceptions checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "keys",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Exceptions checking missed, but method is abstract, probably it is OK",
+ method = "keys",
+ args = {}
+ )
public void testKeys() throws BackingStoreException {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
pref.clear();
@@ -946,15 +1029,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#name()
*
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "name",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "name",
+ args = {}
+ )
public void testName() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
Preferences child = pref.node("mock");
@@ -965,15 +1045,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#node(String pathName)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "node",
- methodArgs = {java.lang.String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "node",
+ args = {java.lang.String.class}
+ )
public void testNode() throws BackingStoreException {
StringBuffer name = new StringBuffer(Preferences.MAX_NAME_LENGTH);
for (int i = 0; i < Preferences.MAX_NAME_LENGTH; i++) {
@@ -1049,15 +1126,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#nodeExists(String pathName)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException & BackingStoreException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "nodeExists",
- methodArgs = {java.lang.String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException & BackingStoreException checking missed, but method is abstract, probably it is OK",
+ method = "nodeExists",
+ args = {java.lang.String.class}
+ )
public void testNodeExists() throws BackingStoreException {
Preferences parent = Preferences
@@ -1104,15 +1178,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#parent()
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "parent",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "parent",
+ args = {}
+ )
public void testParent() {
Preferences parent = Preferences
.userNodeForPackage(Preferences.class);
@@ -1126,15 +1197,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#put(String key, String value)
*
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "put",
- methodArgs = {java.lang.String.class, java.lang.String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "put",
+ args = {java.lang.String.class, java.lang.String.class}
+ )
public void testPut() throws BackingStoreException {
Preferences pref = Preferences
.userNodeForPackage(Preferences.class);
@@ -1188,15 +1256,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#putBoolean(String key, boolean value)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "putBoolean",
- methodArgs = {java.lang.String.class, boolean.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "putBoolean",
+ args = {java.lang.String.class, boolean.class}
+ )
public void testPutBoolean() {
Preferences pref = Preferences
.userNodeForPackage(Preferences.class);
@@ -1220,15 +1285,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#putDouble(String key, double value)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "putDouble",
- methodArgs = {java.lang.String.class, double.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "putDouble",
+ args = {java.lang.String.class, double.class}
+ )
public void testPutDouble() {
Preferences pref = Preferences
.userNodeForPackage(Preferences.class);
@@ -1252,15 +1314,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#putFloat(String key, float value)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "putFloat",
- methodArgs = {java.lang.String.class, float.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "putFloat",
+ args = {java.lang.String.class, float.class}
+ )
public void testPutFloat() {
Preferences pref = Preferences
.userNodeForPackage(Preferences.class);
@@ -1284,15 +1343,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#putInt(String key, int value)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "putInt",
- methodArgs = {java.lang.String.class, int.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "putInt",
+ args = {java.lang.String.class, int.class}
+ )
public void testPutInt() {
Preferences pref = Preferences
.userNodeForPackage(Preferences.class);
@@ -1316,15 +1372,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#putLong(String key, long value)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "putLong",
- methodArgs = {java.lang.String.class, long.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "putLong",
+ args = {java.lang.String.class, long.class}
+ )
public void testPutLong() {
Preferences pref = Preferences
.userNodeForPackage(Preferences.class);
@@ -1348,15 +1401,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#putByteArray(String key, byte[] value)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "putByteArray",
- methodArgs = {java.lang.String.class, byte[].class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "putByteArray",
+ args = {java.lang.String.class, byte[].class}
+ )
public void testPutByteArray() {
Preferences pref = Preferences
.userNodeForPackage(Preferences.class);
@@ -1401,15 +1451,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#remove(String key)
*
*/
-@TestInfo(
- level = TestLevel.COMPLETE,
- purpose = "",
- targets = {
- @TestTarget(
- methodName = "remove",
- methodArgs = {java.lang.String.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.COMPLETE,
+ notes = "",
+ method = "remove",
+ args = {java.lang.String.class}
+ )
public void testRemove() throws BackingStoreException {
Preferences pref = Preferences
.userNodeForPackage(Preferences.class);
@@ -1440,15 +1487,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#removeNode()
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Exceptions checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "removeNode",
- methodArgs = {}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Exceptions checking missed, but method is abstract, probably it is OK",
+ method = "removeNode",
+ args = {}
+ )
public void testRemoveNode() throws BackingStoreException {
Preferences pref = Preferences
.userNodeForPackage(Preferences.class);
@@ -1469,16 +1513,13 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#addNodeChangeListener(NodeChangeListener ncl)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Only NullPointerException checked, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "addNodeChangeListener",
- methodArgs = {java.util.prefs.NodeChangeListener.class}
- )
- })
- public void _testAddNodeChangeListener() throws BackingStoreException {
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Only NullPointerException checked, but method is abstract, probably it is OK",
+ method = "addNodeChangeListener",
+ args = {java.util.prefs.NodeChangeListener.class}
+ )
+ public void testAddNodeChangeListener() throws BackingStoreException {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
pref.addNodeChangeListener(null);
@@ -1496,9 +1537,11 @@ public class PreferencesTest extends TestCase {
nl = new MockNodeChangeListener();
pref.addNodeChangeListener(nl);
child1 = pref.node("mock1");
+ nl.waitForEvent();
assertEquals(1, nl.getAdded());
nl.reset();
child2 = pref.node("mock1");
+ nl.waitForEvent();
assertEquals(0, nl.getAdded());
nl.reset();
} finally {
@@ -1511,6 +1554,7 @@ public class PreferencesTest extends TestCase {
pref.addNodeChangeListener(nl);
pref.addNodeChangeListener(nl);
child1 = pref.node("mock2");
+ nl.waitForEvent();
assertEquals(2, nl.getAdded());
nl.reset();
} finally {
@@ -1524,6 +1568,7 @@ public class PreferencesTest extends TestCase {
pref.addNodeChangeListener(nl);
child1 = pref.node("mock3");
child1.removeNode();
+ nl.waitForEvent();
assertEquals(1, nl.getRemoved());
nl.reset();
} finally {
@@ -1536,6 +1581,7 @@ public class PreferencesTest extends TestCase {
pref.addNodeChangeListener(nl);
child1 = pref.node("mock6");
child1.removeNode();
+ nl.waitForEvent();
assertEquals(2, nl.getRemoved());
nl.reset();
} finally {
@@ -1549,22 +1595,27 @@ public class PreferencesTest extends TestCase {
child1 = pref.node("mock4");
child1.addNodeChangeListener(nl);
child2 = pref.node("mock4/mock5");
+ nl.waitForEvent();
assertEquals(1, nl.getAdded());
nl.reset();
child3 = pref.node("mock4/mock5/mock6");
+ nl.waitForEvent();
assertEquals(0, nl.getAdded());
nl.reset();
child3.removeNode();
+ nl.waitForEvent();
assertEquals(0, nl.getRemoved());
nl.reset();
child3 = pref.node("mock4/mock7");
+ nl.waitForEvent();
assertEquals(1, nl.getAdded());
nl.reset();
child1.removeNode();
- assertEquals(2, nl.getRemoved());
+ nl.waitForEvent();
+ assertEquals(2, nl.getRemoved()); // fail 1
nl.reset();
} finally {
try {
@@ -1579,21 +1630,17 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#addPreferenceChangeListener(PreferenceChangeListener pcl)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "Only NullPointerException checked, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "addPreferenceChangeListener",
- methodArgs = {java.util.prefs.PreferenceChangeListener.class}
- )
- })
- public void _testAddPreferenceChangeListener() {
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "Only NullPointerException checked, but method is abstract, probably it is OK",
+ method = "addPreferenceChangeListener",
+ args = {java.util.prefs.PreferenceChangeListener.class}
+ )
+ public void testAddPreferenceChangeListener() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
MockPreferenceChangeListener pl = null;
- // TODO: start from here
try {
pref.addPreferenceChangeListener(null);
fail();
@@ -1605,13 +1652,16 @@ public class PreferencesTest extends TestCase {
pl = new MockPreferenceChangeListener();
pref.addPreferenceChangeListener(pl);
pref.putInt("mock1", 123);
+ pl.waitForEvent();
assertEquals(1, pl.getChanged());
pref.putLong("long_key", Long.MAX_VALUE);
+ pl.waitForEvent(2);
assertEquals(2, pl.getChanged());
pl.reset();
try {
pref.clear();
- assertEquals(2, pl.getChanged());
+ pl.waitForEvent(2);
+ assertEquals(2, pl.getChanged()); // fail 1
} catch(BackingStoreException bse) {
pl.reset();
fail("BackingStoreException is thrown");
@@ -1628,6 +1678,7 @@ public class PreferencesTest extends TestCase {
pref.addPreferenceChangeListener(pl);
pref.addPreferenceChangeListener(pl);
pref.putFloat("float_key", Float.MIN_VALUE);
+ pl.waitForEvent(2);
assertEquals(2, pl.getChanged());
pl.reset();
} finally {
@@ -1640,10 +1691,12 @@ public class PreferencesTest extends TestCase {
pl = new MockPreferenceChangeListener();
pref.addPreferenceChangeListener(pl);
pref.putDouble("double_key", Double.MAX_VALUE);
+ pl.waitForEvent();
assertEquals(1, pl.getChanged());
try {
pref.clear();
- assertEquals(3, pl.getChanged());
+ pl.waitForEvent(3);
+ assertEquals(3, pl.getChanged()); // fails
} catch(BackingStoreException bse) {
fail("BackingStoreException is thrown");
}
@@ -1659,6 +1712,7 @@ public class PreferencesTest extends TestCase {
pref.putByteArray("byte_array_key", new byte [] {1 ,2 , 3});
try {
pref.clear();
+ pl.waitForEvent(4);
assertEquals(4, pl.getChanged());
} catch(BackingStoreException bse) {
fail("BackingStoreException is thrown");
@@ -1675,15 +1729,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#removeNodeChangeListener(NodeChangeListener ncl)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "removeNodeChangeListener",
- methodArgs = {java.util.prefs.NodeChangeListener.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "removeNodeChangeListener",
+ args = {java.util.prefs.NodeChangeListener.class}
+ )
public void testRemoveNodeChangeListener() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
@@ -1714,15 +1765,12 @@ public class PreferencesTest extends TestCase {
* @test java.util.prefs.Preferences#removePreferenceChangeListener(PreferenceChangeListener pcl)
*
*/
-@TestInfo(
- level = TestLevel.PARTIAL,
- purpose = "IllegalStateException checking missed, but method is abstract, probably it is OK",
- targets = {
- @TestTarget(
- methodName = "removePreferenceChangeListener",
- methodArgs = {java.util.prefs.PreferenceChangeListener.class}
- )
- })
+ @TestTargetNew(
+ level = TestLevel.PARTIAL,
+ notes = "IllegalStateException checking missed, but method is abstract, probably it is OK",
+ method = "removePreferenceChangeListener",
+ args = {java.util.prefs.PreferenceChangeListener.class}
+ )
public void testRemovePreferenceChangeListener() {
Preferences pref = Preferences.userNodeForPackage(Preferences.class);
try {
@@ -1786,6 +1834,7 @@ public class PreferencesTest extends TestCase {
}
}
+ @SuppressWarnings("unused")
static class MockPreferences extends Preferences {
public MockPreferences() {
diff --git a/prefs/src/test/java/tests/prefs/AllTests.java b/prefs/src/test/java/tests/prefs/AllTests.java
index 97679c9..843d733 100644
--- a/prefs/src/test/java/tests/prefs/AllTests.java
+++ b/prefs/src/test/java/tests/prefs/AllTests.java
@@ -29,7 +29,7 @@ public class AllTests {
}
public static Test suite() {
- TestSuite suite = new TestSuite("All Prefs test suites");
+ TestSuite suite = tests.TestSuiteFactory.createTestSuite("All Prefs test suites");
// $JUnit-BEGIN$
suite.addTest(org.apache.harmony.prefs.tests.java.util.prefs.AllTests.suite());
// $JUnit-END$