package uk.ac.ebi.spot.goci.utils;

import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;

import static junit.framework.TestCase.assertEquals;
import static org.junit.Assert.assertNull;
import static uk.ac.ebi.spot.goci.utils.SheetCellProcessingService.processFloatValues;
import static uk.ac.ebi.spot.goci.utils.SheetCellProcessingService.processIntValues;

/**
 * Created by emma on 14/04/2016.
 *
 * @author emma
 *         <p>
 *         Test for SheetCellProcessingService
 */
@RunWith(MockitoJUnitRunner.class)
public class SheetCellProcessingServiceTest {

    XSSFCell cellWithString;

    XSSFCell cellWithInteger;

    XSSFCell cellWithFloat;

    XSSFCell blankCell;

    @Before
    public void setUp() throws Exception {
        // Create spreadsheet for testing
        XSSFWorkbook workbook = new XSSFWorkbook();
        XSSFSheet sheet = workbook.createSheet("test");
        XSSFRow row = sheet.createRow(0);
        row.createCell(0).setCellValue("this is a string");
        row.createCell(1).setCellValue(12);
        row.createCell(2).setCellValue(1.22);
        row.createCell(3);

        cellWithString = row.getCell(0);
        cellWithInteger = row.getCell(1);
        cellWithFloat = row.getCell(2);
        blankCell = row.getCell(3, row.RETURN_BLANK_AS_NULL);
    }

    @Test
    public void testProcessIntValues() throws Exception {
        assertNull(processIntValues(cellWithString));
        assertNull(processIntValues(blankCell));
        assertEquals(Integer.valueOf(12), processIntValues(cellWithInteger));
    }

    @Test
    public void testProcessFloatValues() throws Exception {
        assertNull(processFloatValues(cellWithString));
        assertNull(processFloatValues(blankCell));
        assertEquals(Float.valueOf(String.valueOf(1.22)), processFloatValues(cellWithFloat));
    }
}
@@ -617,16 +617,103 @@
 tValues;
+%0Aimport static uk.ac.ebi.spot.goci.utils.SheetCellProcessingService.processStringValue;
 %0A%0A/**%0A *
@@ -1026,16 +1026,53 @@
 kCell;%0A%0A
+    XSSFCell cellWithNumericString;%0A%0A
     @Bef
@@ -1486,16 +1486,64 @@
 Cell(3);
+%0A        row.createCell(4).setCellValue(%221.22%22);
 %0A%0A      
@@ -1721,16 +1721,64 @@
 _NULL);%0A
+        cellWithNumericString = row.getCell(4);%0A
     %7D%0A%0A 
@@ -2201,32 +2201,32 @@
 es(blankCell));%0A
-
         assertEq
@@ -2308,10 +2308,276 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testProcessStringValue() throws Exception %7B%0A        assertNull(processStringValue(blankCell));%0A        assertEquals(%221.22%22, processStringValue(cellWithNumericString));%0A        assertEquals(%221.22%22, processStringValue(cellWithFloat));%0A    %7D
 %0A%7D

Update test to reflect new method