180c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson/* Licensed to the Apache Software Foundation (ASF) under one or more 280c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * contributor license agreements. See the NOTICE file distributed with 380c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * this work for additional information regarding copyright ownership. 480c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * The ASF licenses this file to You under the Apache License, Version 2.0 580c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * (the "License"); you may not use this file except in compliance with 680c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * the License. You may obtain a copy of the License at 780c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * 880c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * http://www.apache.org/licenses/LICENSE-2.0 980c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * 1080c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * Unless required by applicable law or agreed to in writing, software 1180c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * distributed under the License is distributed on an "AS IS" BASIS, 1280c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1380c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * See the License for the specific language governing permissions and 1480c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson * limitations under the License. 1580c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson */ 1680c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 1780c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilsonpackage libcore.java.util.prefs; 1880c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 1980c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilsonimport java.util.prefs.Preferences; 2080c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilsonimport junit.framework.TestCase; 2180c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 2280c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilsonpublic final class OldFilePreferencesImplTest extends TestCase { 2380c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 2480c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson // AndroidOnly: the RI can't remove nodes created in the system root. 2580c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson public void testSystemChildNodes() throws Exception { 2680c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson Preferences sroot = Preferences.systemRoot().node("test"); 2780c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 2880c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson Preferences child1 = sroot.node("child1"); 2980c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson Preferences child2 = sroot.node("child2"); 3080c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson Preferences grandchild = child1.node("grand"); 3180c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 3280c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson String[] childNames = sroot.childrenNames(); 3380c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson assertContains(childNames, "child1"); 3480c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson assertContains(childNames, "child2"); 3580c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson assertNotContains(childNames, "grand"); 3680c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 3780c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson childNames = child1.childrenNames(); 3880c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson assertEquals(1, childNames.length); 3980c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 4080c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson childNames = child2.childrenNames(); 4180c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson assertEquals(0, childNames.length); 4280c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 4380c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson child1.removeNode(); 4480c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson childNames = sroot.childrenNames(); 4580c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson assertNotContains(childNames, "child1"); 4680c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson assertContains(childNames, "child2"); 4780c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson assertNotContains(childNames, "grand"); 4880c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 4980c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson child2.removeNode(); 5080c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson childNames = sroot.childrenNames(); 5180c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson assertNotContains(childNames, "child1"); 5280c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson assertNotContains(childNames, "child2"); 5380c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson assertNotContains(childNames, "grand"); 5480c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson sroot.removeNode(); 5580c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson } 5680c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 5780c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson private void assertContains(String[] childNames, String name) { 5880c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson for (String childName : childNames) { 5980c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson if (childName == name) { 6080c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson return; 6180c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson } 6280c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson } 6380c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson fail("No child with name " + name + " was found. It was expected to exist."); 6480c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson } 6580c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson 6680c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson private void assertNotContains(String[] childNames, String name) { 6780c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson for (String childName : childNames) { 6880c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson if (childName == name) { 6980c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson fail("Child with name " + name + " was found. This was unexpected."); 7080c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson } 7180c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson } 7280c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson } 7380c9f71990a6655b7b2b43dc1946487e917f0f9dJesse Wilson} 74