package umm3601.digitalDisplayGarden;


import com.mongodb.MongoClient;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import org.junit.Before;
import org.junit.Test;

import static org.junit.Assert.assertEquals;

/**
 * Created by benek020 on 3/6/17.
 */
public class TestExcelParser {

    public MongoClient mongoClient = new MongoClient();
    public MongoDatabase testDB;
    public ExcelParser parser;

    @Before
    public void clearAndPopulateDatabase(){
        mongoClient.dropDatabase("test");
        testDB = mongoClient.getDatabase("test");
        parser = new ExcelParser();
    }



    @Test
    public void testSpeadsheetToDoubleArray(){
        String[][] plantArray = parser.extractFromXLSX();
        //printDoubleArray(plantArray);

        assertEquals(1668, plantArray.length);
        assertEquals(plantArray[40].length, plantArray[1234].length);
        assertEquals("ALEXANDER", plantArray[5][2]);

    }

    @Test
    public void testCollapse(){
        String[][] plantArray = parser.extractFromXLSX();
        System.out.println(plantArray.length);
        printDoubleArray(plantArray);

        plantArray = parser.collapseHorizontally(plantArray);
        plantArray = parser.collapseVertically(plantArray);

        printDoubleArray(plantArray);

        assertEquals(1668, plantArray.length);
        assertEquals(10, plantArray[30].length);
        assertEquals(10, plantArray[0].length);
        assertEquals(10, plantArray[3].length);
    }

    private static void printDoubleArray(String[][] input){
        for(int i = 0; i < input.length; i++){
            if (!(input[i] == (null))) {
                for (int j = 0; j < input[i].length; j++) {
                    //System.out.print(" | " + "i: " + i + " j: " + j + " value: " + input[i][j] );
                    System.out.print(" | " + input[i][j]);
                }
                System.out.println();
                System.out.println("-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------");
            }
        }
    }
}

@@ -242,16 +242,62 @@
 tEquals;
+%0Aimport static org.junit.Assert.assertNotNull;
 %0A%0A/**%0A *
@@ -1112,32 +1112,34 @@
 XLSX();%0A        
+//
 System.out.print
@@ -1161,32 +1161,34 @@
 ength);%0A        
+//
 printDoubleArray
@@ -1333,16 +1333,18 @@
         
+//
 printDou
@@ -1558,23 +1558,439 @@
 ength);%0A
-
     %7D%0A%0A
+    @Test%0A    public void testReplaceNulls()%7B%0A        String%5B%5D%5B%5D plantArray = parser.extractFromXLSX();%0A        plantArray = parser.collapseHorizontally(plantArray);%0A        plantArray = parser.collapseVertically(plantArray);%0A        parser.replaceNulls(plantArray);%0A%0A        for (String%5B%5D row : plantArray)%7B%0A            for (String cell : row)%7B%0A                assertNotNull(cell);%0A            %7D%0A        %7D%0A    %7D%0A%0A%0A%0A
     priv

Add test for replaceNulls(String[][])