/*
 * 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.junit.Assert.assertEquals;

import java.nio.charset.Charset;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

/**
 * Tests the {@code HumanNameParser} class.
 */
public class HumanNameParserTest {

    private CSVParser parser;

    @Before
    public void setUp() throws Exception {
        parser = CSVParser.parse(
                HumanNameParserTest.class.getResource("testNames.txt"), 
                Charset.forName("UTF-8"), 
                CSVFormat.DEFAULT.withDelimiter('|').withHeader());
    }

    @After
    public void tearDown() throws Exception {
        if (parser != null) {
            parser.close();
        }
    }

    @Test
    public void testInputs() {
        for (CSVRecord record : parser) {
            validateRecord(record);
        }
    }

    
    /**
     * Validates a line in the testNames.txt file.
     *
     * @param record the tokens with leading spaces
     */
    private void validateRecord(CSVRecord record) {
        HumanNameParser parser = new HumanNameParser(record.get(Colums.Name));

        assertEquals("Wrong LeadingInit in record " + record.getRecordNumber(),
                record.get(Colums.LeadingInit), parser.getLeadingInit());
        
        assertEquals("Wrong FirstName in record " + record.getRecordNumber(), 
                record.get(Colums.FirstName), parser.getFirst());
        
        assertEquals("Wrong NickName in record " + record.getRecordNumber(), 
                record.get(Colums.NickName), parser.getNickname());
        
        assertEquals("Wrong MiddleName in record " + record.getRecordNumber(), 
                record.get(Colums.MiddleName), parser.getMiddle());
        
        assertEquals("Wrong LastName in record " + record.getRecordNumber(), 
                record.get(Colums.LastName), parser.getLast());
        
        assertEquals("Wrong Suffix in record " + record.getRecordNumber(), 
                record.get(Colums.Suffix), parser.getSuffix());
    }

    private enum Colums {
        Name,LeadingInit,FirstName,NickName,MiddleName,LastName,Suffix
    }
}

@@ -832,24 +832,69 @@
 ext.names;%0A%0A
+import static org.hamcrest.Matchers.equalTo;%0A
 import stati
@@ -918,22 +918,20 @@
 t.assert
-Equals
+That
 ;%0A%0Aimpor
@@ -2091,38 +2091,36 @@
 %0A%0A        assert
-Equals
+That
 (%22Wrong LeadingI
@@ -2179,34 +2179,26 @@
         
-record.get(Colums.
+parser.get
 LeadingI
@@ -2200,29 +2200,46 @@
 dingInit
+(
 ), 
-parser.get
+equalTo(record.get(Colums.
 LeadingI
@@ -2241,17 +2241,17 @@
 dingInit
-(
+)
 ));%0A    
@@ -2261,38 +2261,36 @@
  %0A        assert
-Equals
+That
 (%22Wrong FirstNam
@@ -2322,33 +2322,32 @@
 tRecordNumber(),
- 
 %0A               
@@ -2339,32 +2339,59 @@
                 
+parser.getFirst(), equalTo(
 record.get(Colum
@@ -2406,26 +2406,8 @@
 ame)
-, parser.getFirst(
 ));%0A
@@ -2421,38 +2421,36 @@
  %0A        assert
-Equals
+That
 (%22Wrong NickName
@@ -2481,33 +2481,32 @@
 tRecordNumber(),
- 
 %0A               
@@ -2510,56 +2510,65 @@
     
-record.get(Colums.
+parser.get
 Nick
-N
+n
 ame
+(
 ), 
-parser.get
+equalTo(record.get(Colums.
 Nick
-name(
+Name)
 ));%0A
@@ -2582,38 +2582,36 @@
  %0A        assert
-Equals
+That
 (%22Wrong MiddleNa
@@ -2644,33 +2644,32 @@
 tRecordNumber(),
- 
 %0A               
@@ -2673,56 +2673,65 @@
     
-record.get(Colums.MiddleName), parser.get
+parser.getMiddle(), equalTo(record.get(Colums.
 Middle
-(
+Name)
 ));%0A
@@ -2745,38 +2745,36 @@
  %0A        assert
-Equals
+That
 (%22Wrong LastName
@@ -2805,33 +2805,32 @@
 tRecordNumber(),
- 
 %0A               
@@ -2822,32 +2822,58 @@
                 
+parser.getLast(), equalTo(
 record.get(Colum
@@ -2887,25 +2887,8 @@
 ame)
-, parser.getLast(
 ));%0A
@@ -2914,14 +2914,12 @@
 sert
-Equals
+That
 (%22Wr
@@ -2968,17 +2968,16 @@
 umber(),
- 
 %0A       
@@ -2989,52 +2989,61 @@
     
-record.get(Colums.
+parser.get
 Suffix
+(
 ), 
-parser.get
+equalTo(record.get(Colums.
 Suffix
-(
+)
 ));%0A

Use hamcrest matchers for checking results