<commit_before>/*
 * Copyright 2012 The Netty Project
 *
 * The Netty Project 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 io.netty.util;

import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertSame;
import org.junit.Before;
import org.junit.Test;

public class UniqueNameTest {

    /**
     * A {@link ConcurrentHashMap} of registered names.
     * This is set up before each test
     */
    private ConcurrentHashMap<String, Boolean> names;
    
    /**
     * Registers a {@link UniqueName}
     *
     * @param name the name being registered
     * @return the unique name
     */
    public UniqueName registerName(String name) {
        return new UniqueName(names, name);
    }

    @Before
    public void initializeTest() {
        this.names = new ConcurrentHashMap<String, Boolean>();
    }

    @Test(expected=NullPointerException.class)
    public void testCannnotProvideNullMap() {
        UniqueName nullName = new UniqueName(null, "Nothing");
    }

    @Test(expected=NullPointerException.class)
    public void testCannotProvideNullName() {
        UniqueName nullName = new UniqueName(this.names, null);
    }

    @Test
    public void testArgsCanBePassed() {
        UniqueName nullName = new UniqueName(this.names, "<NAME>!", 2, 5, new Object());
    }

    @Test
    public void testRegisteringName() {
        registerName("Abcedrian");

        assertTrue(this.names.get("Abcedrian"));
        assertTrue(this.names.get("Hellyes") == null);
    }

    @Test
    public void testNameUniqueness() {
        registerName("Leroy");
        boolean failed = false;
        try {
            registerName("Leroy");
        } catch (IllegalArgumentException ex) {
            failed = true;
        }
        assertTrue(failed);
    }

    @Test
    public void testIDUniqueness() {
        UniqueName one = registerName("one");
        UniqueName two = registerName("two");
        assertNotSame(one.id(), two.id());

        ArrayList<UniqueName> nameList = new ArrayList<UniqueName>();

        for (int index = 0; index < 2500; index++) {
            UniqueName currentName = registerName("test" + index);
            nameList.add(currentName);
            for (UniqueName otherName : nameList) {
                if (!currentName.name().equals(otherName.name())) {
                    assertNotSame(currentName, otherName);
                    assertNotSame(currentName.hashCode(), otherName.hashCode());
                    assertFalse(currentName.equals(otherName));
                    assertNotSame(currentName.compareTo(otherName), 0);
                    assertNotSame(currentName.toString(), otherName.toString());
                }
            }
        }
    }
    
    @Test
    public void testCompareNames() {
        UniqueName one = registerName("One");
        UniqueName two = registerName("Two");

        ConcurrentHashMap<String, Boolean> mapTwo = new ConcurrentHashMap<String, Boolean>();

        UniqueName three = new UniqueName(mapTwo, "One");

        assertSame(one.compareTo(one), 0);
        assertSame(one.compareTo(two), -5);
        assertSame(one.compareTo(three), -1);
        assertSame(three.compareTo(one), 1);
    }

}<commit_msg>Removes an unneeded assertion in UniqueNameTest<commit_after>/*
 * Copyright 2012 The Netty Project
 *
 * The Netty Project 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 io.netty.util;

import java.util.ArrayList;
import java.util.concurrent.ConcurrentHashMap;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertSame;
import org.junit.Before;
import org.junit.Test;

public class UniqueNameTest {

    /**
     * A {@link ConcurrentHashMap} of registered names.
     * This is set up before each test
     */
    private ConcurrentHashMap<String, Boolean> names;
    
    /**
     * Registers a {@link UniqueName}
     *
     * @param name the name being registered
     * @return the unique name
     */
    public UniqueName registerName(String name) {
        return new UniqueName(names, name);
    }

    @Before
    public void initializeTest() {
        this.names = new ConcurrentHashMap<String, Boolean>();
    }

    @Test(expected=NullPointerException.class)
    public void testCannnotProvideNullMap() {
        UniqueName nullName = new UniqueName(null, "Nothing");
    }

    @Test(expected=NullPointerException.class)
    public void testCannotProvideNullName() {
        UniqueName nullName = new UniqueName(this.names, null);
    }

    @Test
    public void testArgsCanBePassed() {
        UniqueName nullName = new UniqueName(this.names, "<NAME>!", 2, 5, new Object());
    }

    @Test
    public void testRegisteringName() {
        registerName("Abcedrian");

        assertTrue(this.names.get("Abcedrian"));
        assertTrue(this.names.get("Hellyes") == null);
    }

    @Test
    public void testNameUniqueness() {
        registerName("Leroy");
        boolean failed = false;
        try {
            registerName("Leroy");
        } catch (IllegalArgumentException ex) {
            failed = true;
        }
        assertTrue(failed);
    }

    @Test
    public void testIDUniqueness() {
        UniqueName one = registerName("one");
        UniqueName two = registerName("two");
        assertNotSame(one.id(), two.id());

        ArrayList<UniqueName> nameList = new ArrayList<UniqueName>();

        for (int index = 0; index < 2500; index++) {
            UniqueName currentName = registerName("test" + index);
            nameList.add(currentName);
            for (UniqueName otherName : nameList) {
                if (!currentName.name().equals(otherName.name())) {
                    assertNotSame(currentName, otherName);
                    assertNotSame(currentName.hashCode(), otherName.hashCode());
                    assertFalse(currentName.equals(otherName));
                    assertNotSame(currentName.toString(), otherName.toString());
                }
            }
        }
    }
    
    @Test
    public void testCompareNames() {
        UniqueName one = registerName("One");
        UniqueName two = registerName("Two");

        ConcurrentHashMap<String, Boolean> mapTwo = new ConcurrentHashMap<String, Boolean>();

        UniqueName three = new UniqueName(mapTwo, "One");

        assertSame(one.compareTo(one), 0);
        assertSame(one.compareTo(two), -5);
        assertSame(one.compareTo(three), -1);
        assertSame(three.compareTo(one), 1);
    }

}
{'fraction_non_alphanumeric': 0.10559404670259173, 'fraction_numerical': 0.0050038491147036184, 'mean_word_length': 2.7136731777036682, 'pattern_counts': {'":': 0, '<': 19, '<?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': '5932109', 'n_tokens_mistral': 2166, 'n_tokens_neox': 2075, 'n_words': 583}