<commit_before>/* 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.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.util.prefs.AbstractPreferences;
import java.util.prefs.BackingStoreException;
import java.util.prefs.InvalidPreferencesFormatException;
import java.util.prefs.NodeChangeListener;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;

import junit.framework.TestCase;

/**
 * 
 */
public class PreferencesTest extends TestCase {

	MockSecurityManager manager = new MockSecurityManager();

	MockInputStream stream = null;

	InputStream in;

	/*
	 * @see TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
		in = new ByteArrayInputStream("<!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);
	}

	/*
	 * @see TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
		stream.close();
	}

	public void testSystemNodeForPackage() throws BackingStoreException {
		Preferences p = Preferences.systemNodeForPackage(Object.class);
		assertEquals("/java/lang", p.absolutePath());
		assertTrue(p instanceof AbstractPreferences);
		Preferences root = Preferences.systemRoot();
		Preferences parent = root.node("java");
		assertSame(parent, p.parent());
		assertFalse(p.isUserNode());
		assertEquals("lang", p.name());
		assertEquals("System Preference Node: " + p.absolutePath(), p
				.toString());
		assertEquals(0, p.childrenNames().length);
		assertEquals(p.keys().length, 0);
		parent.removeNode();
		try {
			p = Preferences.userNodeForPackage(null);
			fail();
		} catch (NullPointerException e) {
		}
	}

	public void testSystemRoot() throws BackingStoreException {
		Preferences p = Preferences.systemRoot();
		assertTrue(p instanceof AbstractPreferences);
		assertEquals("/", p.absolutePath());
		assertSame(null, p.parent());
		assertFalse(p.isUserNode());
		assertEquals("", p.name());
		assertEquals("System Preference Node: " + p.absolutePath(), p
				.toString());
		// assertEquals(0, p.childrenNames().length);
		// assertEquals(p.keys().length, 0);
	}

	public void testConsts() {
		assertEquals(80, Preferences.MAX_KEY_LENGTH);
		assertEquals(80, Preferences.MAX_NAME_LENGTH);
		assertEquals(8192, Preferences.MAX_VALUE_LENGTH);
	}

	public void testUserNodeForPackage() throws BackingStoreException {
		Preferences p = Preferences.userNodeForPackage(Object.class);
		assertEquals("/java/lang", p.absolutePath());
		assertTrue(p instanceof AbstractPreferences);
		Preferences root = Preferences.userRoot();
		Preferences parent = root.node("java");
		assertSame(parent, p.parent());
		assertTrue(p.isUserNode());
		assertEquals("lang", p.name());
		assertEquals("User Preference Node: " + p.absolutePath(), p.toString());
		assertEquals(0, p.childrenNames().length);
		assertEquals(p.keys().length, 0);

		try {
			p = Preferences.userNodeForPackage(null);
			fail();<commit_msg>Fixed order of actual and expected arguments to assertEquals.<commit_after>/* 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.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.util.prefs.AbstractPreferences;
import java.util.prefs.BackingStoreException;
import java.util.prefs.InvalidPreferencesFormatException;
import java.util.prefs.NodeChangeListener;
import java.util.prefs.PreferenceChangeListener;
import java.util.prefs.Preferences;

import junit.framework.TestCase;

/**
 * 
 */
public class PreferencesTest extends TestCase {

	MockSecurityManager manager = new MockSecurityManager();

	MockInputStream stream = null;

	InputStream in;

	/*
	 * @see TestCase#setUp()
	 */
	protected void setUp() throws Exception {
		super.setUp();
		in = new ByteArrayInputStream("<!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);
	}

	/*
	 * @see TestCase#tearDown()
	 */
	protected void tearDown() throws Exception {
		super.tearDown();
		stream.close();
	}

	public void testSystemNodeForPackage() throws BackingStoreException {
		Preferences p = Preferences.systemNodeForPackage(Object.class);
		assertEquals("/java/lang", p.absolutePath());
		assertTrue(p instanceof AbstractPreferences);
		Preferences root = Preferences.systemRoot();
		Preferences parent = root.node("java");
		assertSame(parent, p.parent());
		assertFalse(p.isUserNode());
		assertEquals("lang", p.name());
		assertEquals("System Preference Node: " + p.absolutePath(), p
				.toString());
		assertEquals(0, p.childrenNames().length);
		assertEquals(0, p.keys().length);
		parent.removeNode();
		try {
			p = Preferences.userNodeForPackage(null);
			fail();
		} catch (NullPointerException e) {
		}
	}

	public void testSystemRoot() throws BackingStoreException {
		Preferences p = Preferences.systemRoot();
		assertTrue(p instanceof AbstractPreferences);
		assertEquals("/", p.absolutePath());
		assertSame(null, p.parent());
		assertFalse(p.isUserNode());
		assertEquals("", p.name());
		assertEquals("System Preference Node: " + p.absolutePath(), p
				.toString());
		// assertEquals(0, p.childrenNames().length);
		// assertEquals(0, p.keys().length);
	}

	public void testConsts() {
		assertEquals(80, Preferences.MAX_KEY_LENGTH);
		assertEquals(80, Preferences.MAX_NAME_LENGTH);
		assertEquals(8192, Preferences.MAX_VALUE_LENGTH);
	}

	public void testUserNodeForPackage() throws BackingStoreException {
		Preferences p = Preferences.userNodeForPackage(Object.class);
		assertEquals("/java/lang", p.absolutePath());
		assertTrue(p instanceof AbstractPreferences);
		Preferences root = Preferences.userRoot();
		Preferences parent = root.node("java");
		assertSame(parent, p.parent());
		assertTrue(p.isUserNode());
		assertEquals("lang", p.name());
		assertEquals("User Preference Node: " + p.absolutePath(), p.toString());
		assertEquals(0, p.childrenNames().length);
		assertEquals(0, p.keys().length);

		try {
			p = Preferences.userNodeForPackage(null);
			fail();
{'fraction_non_alphanumeric': 0.12525025025025024, 'fraction_numerical': 0.004754754754754755, 'mean_word_length': 5.018825301204819, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5048818', 'n_tokens_mistral': 2360, 'n_tokens_neox': 2196, 'n_words': 599}