/*
 * The MIT License
 *
 *  Copyright (c) 2015, Mahmoud Ben Hassine (mahmoud@benhassine.fr)
 *
 *  Permission is hereby granted, free of charge, to any person obtaining a copy
 *  of this software and associated documentation files (the "Software"), to deal
 *  in the Software without restriction, including without limitation the rights
 *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 *  copies of the Software, and to permit persons to whom the Software is
 *  furnished to do so, subject to the following conditions:
 *
 *  The above copyright notice and this permission notice shall be included in
 *  all copies or substantial portions of the Software.
 *
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 *  THE SOFTWARE.
 */

package org.easybatch.integration.opencsv.test;

import org.easybatch.core.record.StringRecord;
import org.easybatch.integration.opencsv.OpenCsvRecordMapper;
import org.junit.Assert;

/**
 * Test class for {@link OpenCsvRecordMapper}.
 *
 * @author Mahmoud Ben Hassine (mahmoud@benhassine.fr)
 */
public class OpenCsvRecordMapperTest {

    private OpenCsvRecordMapper<Foo> openCsvRecordMapper;

    @org.junit.Before
    public void setUp() throws Exception {
        openCsvRecordMapper = new OpenCsvRecordMapper<Foo>(Foo.class, new String[]{"firstName", "lastName", "age", "married"});
    }

    @org.junit.Test
    public void testOpenCsvMapping() throws Exception {
        StringRecord fooRecord = new StringRecord(1, "foo,bar,15,true");
        Foo foo = openCsvRecordMapper.mapRecord(fooRecord);
        Assert.assertNotNull(foo);
        Assert.assertEquals("foo", foo.getFirstName());
        Assert.assertEquals("bar", foo.getLastName());
        Assert.assertEquals(15, foo.getAge());
        Assert.assertEquals(true, foo.isMarried());
    }

    @org.junit.Test
    public void testOpenCsvDelimiter() throws Exception {
        openCsvRecordMapper.setDelimiter(';');
        StringRecord fooRecord = new StringRecord(1, "foo;bar");
        Foo foo = openCsvRecordMapper.mapRecord(fooRecord);
        Assert.assertNotNull(foo);
        Assert.assertEquals("foo", foo.getFirstName());
        Assert.assertEquals("bar", foo.getLastName());
    }

    @org.junit.Test
    public void testOpenCsvQualifier() throws Exception {
        openCsvRecordMapper.setQualifier('\'');
        StringRecord fooRecord = new StringRecord(1, "'foo,s','bar'");
        Foo foo = openCsvRecordMapper.mapRecord(fooRecord);
        Assert.assertNotNull(foo);
        Assert.assertEquals("foo,s", foo.getFirstName());
        Assert.assertEquals("bar", foo.getLastName());
    }

    @org.junit.Test
    public void testOpenCsvCarriageReturn() throws Exception {
        openCsvRecordMapper.setQualifier('\'');
        StringRecord fooRecord = new StringRecord(1, "'foo\n','bar\n'");
        Foo foo = openCsvRecordMapper.mapRecord(fooRecord);
        Assert.assertNotNull(foo);
        Assert.assertEquals("foo\n", foo.getFirstName());
        Assert.assertEquals("bar\n", foo.getLastName());
    }

    @org.junit.After
    public void tearDown() throws Exception {
        openCsvRecordMapper = null;
        System.gc();
    }

}

@@ -1363,16 +1363,64 @@
 .Assert;
+%0Aimport org.junit.Before;%0Aimport org.junit.Test;
 %0A%0A/**%0A *
@@ -1630,26 +1630,16 @@
 ;%0A%0A    @
-org.junit.
 Before%0A 
@@ -1816,34 +1816,24 @@
     %7D%0A%0A    @
-org.junit.
 Test%0A    pub
@@ -2267,34 +2267,24 @@
     %7D%0A%0A    @
-org.junit.
 Test%0A    pub
@@ -2660,34 +2660,24 @@
     %7D%0A%0A    @
-org.junit.
 Test%0A    pub
@@ -3066,26 +3066,16 @@
 %7D%0A%0A    @
-org.junit.
 Test%0A   
@@ -3400,32 +3400,32 @@
 etFirstName());%0A
+
         Assert.a
@@ -3476,137 +3476,6 @@
  %7D%0A%0A
-    @org.junit.After%0A    public void tearDown() throws Exception %7B%0A        openCsvRecordMapper = null;%0A        System.gc();%0A    %7D%0A%0A
 %7D%0A

remove tear down method