/*
 * 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.commons.text.names;

import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;

import org.junit.Before;
import org.junit.Test;

/**
 * Tests for {@code Name} and {@code HumanNameParser}. Utilizes the same
 * input file as the PHP library 0.2 version.
 */
public class NameStringTest {

    private NameString nameString;

    @Before
    public void setUp() {
        nameString = new NameString("Björn O'Malley");
    }

    @Test
    public void testChopWithRegexReturnsChoppedSubstring() {
        NameString nameString = new NameString("Björn O'Malley");

        assertThat(nameString.chopWithRegex("(^([^ ]+))(.+)", 1), equalTo("Björn"));
    }

    @Test
    public void testChopWithRegexChopsStartOffNameStr() {
        NameString nameString = new NameString("Björn O'Malley");
        nameString.chopWithRegex("(^[^ ]+)", 0);

        assertThat(nameString.getWrappedString(), equalTo("O'Malley"));
    }

    @Test
    public void testChopWithRegexChopsEndOffNameStr() {
        NameString nameString = new NameString("Björn O'Malley");
        nameString.chopWithRegex("( (.+)$)", 1);

        assertThat(nameString.getWrappedString(), equalTo("Björn"));
    }

    @Test
    public void testChopWithRegexChopsMiddleFromNameStr() {
        NameString nameString = new NameString("Björn 'Bill' O'Malley");
        nameString.chopWithRegex("( '[^']+' )", 0);

        assertThat(nameString.getWrappedString(), equalTo("Björn O'Malley"));
    }

    @Test
    public void testFlip() {
        NameString nameString = new NameString("O'Malley, Björn");
        nameString.flip(",");

        assertThat(nameString.getWrappedString(), equalTo("Björn O'Malley"));
    }

}

@@ -1343,75 +1343,8 @@
 ) %7B%0A
-        NameString nameString = new NameString(%22Bj%C3%B6rn O'Malley%22);%0A%0A
     
@@ -1416,32 +1416,32 @@
 alTo(%22Bj%C3%B6rn%22));%0A
+
     %7D%0A%0A    @Test
@@ -1503,74 +1503,8 @@
 ) %7B%0A
-        NameString nameString = new NameString(%22Bj%C3%B6rn O'Malley%22);%0A
     
@@ -1698,74 +1698,8 @@
 ) %7B%0A
-        NameString nameString = new NameString(%22Bj%C3%B6rn O'Malley%22);%0A
     
@@ -1894,81 +1894,8 @@
 ) %7B%0A
-        NameString nameString = new NameString(%22Bj%C3%B6rn 'Bill' O'Malley%22);%0A
     
@@ -2030,32 +2030,32 @@
    %7D%0A%0A    @Test%0A
+
     public void 
@@ -2071,75 +2071,8 @@
 ) %7B%0A
-        NameString nameString = new NameString(%22O'Malley, Bj%C3%B6rn%22);%0A
     

Update test to use variable created on the setUp method, instead of local variable