/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package nl.meine.scouting.solparser.writer;

import java.io.File;
import java.net.URISyntaxException;
import java.util.Date;
import java.util.List;
import java.util.Map;
import nl.meine.scouting.solparser.Parser;
import nl.meine.scouting.solparser.ParserTest;
import nl.meine.scouting.solparser.entities.Person;
import nl.meine.scouting.solparser.sorter.SorterFactory;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import static org.junit.Assert.*;

/**
 *
 * @author meine
 */
public class ExcelWriterTest extends ExcelWriter{

    private static Map<String, List<Person>> sortedPersons;
    private static List<Person> persons;
    
    private ExcelWriter instance = new ExcelWriter("dummy.xls");

    public ExcelWriterTest() {
        super("dummy.xls");
    }


    @BeforeClass
    public static void setUpClass() throws URISyntaxException {

        File twopersons = ParserTest.getResource("twopersons.csv");
        Parser p = new Parser(twopersons , SorterFactory.createSorter(SorterFactory.SORTER_ONLYALL));

        p.read(true);
        persons = p.getAllPersons();
        sortedPersons = p.getSortedPersons();
    }

    @AfterClass
    public static void tearDownClass() {
        
    }

    @Before
    public void setUp() {
        instance.setAllPersons(persons);
        instance.setSortedPersons(sortedPersons);
        instance.init();
    }

    @After
    public void tearDown() {
        if(instance.output.exists()){
            instance.output.delete();
        }
    }

    /**
     * Test of init method, of class ExcelWriter.
     */
    @Test
    public void testInit() {
        assertNotNull ("Persons must be initialized before callinig init", instance.allPersons);
        assertNotNull ("Persons must be initialized before callinig init", instance.sortedPersons);
        assertNotNull( instance.out);
        assertNotNull( instance.output);
        assertNotNull(instance.previous);
        assertNotNull(instance.workbook);
        assertNotNull(instance.headingStyle);
        assertNotNull(instance.normalStyle);

    }

    /**
     * Test of write method, of class ExcelWriter.
     */
    @Test
    public void testWrite() {
        assertNotNull ("Persons must be initialized before callinig init", instance.allPersons);
        assertNotNull ("Persons must be initialized before callinig init", instance.sortedPersons);
        Date begin = new Date();
        instance.write();
        Date end = new Date();
        Long duration = end.getTime() - begin.getTime();
        assertTrue(instance.previous.lastModified() - instance.output.lastModified() < duration);
        assertTrue(instance.previous.exists());
        assertTrue(instance.output.exists());
        
        assertEquals(1,instance.workbook.getNumberOfSheets());

    }

    /**
     * Test of finalize method, of class ExcelWriter.
     */
    @Test
    public void testFinalize() throws Exception, Throwable {
        System.out.println("finalize");
        instance.finalize();
        fail("The test case is a prototype.");
    }

}

@@ -547,16 +547,139 @@
 actory;%0A
+import org.apache.poi.ss.usermodel.Cell;%0Aimport org.apache.poi.ss.usermodel.Row;%0Aimport org.apache.poi.ss.usermodel.Sheet;%0A
 import o
@@ -690,24 +690,24 @@
 unit.After;%0A
-
 import org.j
@@ -1879,16 +1879,106 @@
       %7D%0A
+        if(instance.previous.exists())%7B%0A            instance.previous.delete();%0A        %7D%0A
     %7D%0A%0A 
@@ -3093,56 +3093,8 @@
 n);%0A
-        assertTrue(instance.previous.exists());%0A
     
@@ -3203,24 +3203,531 @@
 fSheets());%0A
+        Sheet s = instance.workbook.getSheetAt(0);%0A        assertEquals(3, s.getPhysicalNumberOfRows());%0A        Row r1 = s.getRow(1);%0A        Cell c1 = r1.getCell(0);%0A        assertEquals ( true,c1.getStringCellValue().equalsIgnoreCase(%2216%22) %7C%7C c1.getStringCellValue().equalsIgnoreCase(%221616%22));%0A        Row r2 = s.getRow(2);%0A        Cell c2 = r2.getCell(0);%0A        assertEquals ( true,c2.getStringCellValue().equalsIgnoreCase(%2216%22) %7C%7C c2.getStringCellValue().equalsIgnoreCase(%221616%22));%0A        int a = 0;
 %0A    %7D%0A%0A    

Add extra testcase for writing excel