/*
 * Copyright 2016 a5xysq1.
 *
 * Licensed 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 com.dua3.meja.model.poi;

import static org.junit.Assert.assertEquals;

import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.xssf.usermodel.XSSFColor;
import org.junit.Test;

import com.dua3.utility.Color;

/**
 *
 * @author a5xysq1
 */
public class PoiTest {

    public PoiTest() {
    }

    /**
     * Test converting color from Meja to POI color and back again does not
     * change the color value.
     *
     * This test checks the implementation for HSSF.
     */
    @Test
    public void testColorConversionHssf() {
        PoiWorkbook.PoiHssfWorkbook wb = (PoiWorkbook.PoiHssfWorkbook) PoiWorkbookFactory.instance().createXls();
        // HSSF seems to map colors to more or less matching nearest colors.
        // The first 16 entries seem to be exact.
        int n = 0;
        for (Color col : Color.values()) {
            if (++n > 16) {
                break;
            }

            HSSFColor poiColor = wb.getPoiColor(col);
            Color expected = col;
            Color actual = wb.getColor(poiColor, Color.BLACK);
            assertEquals(expected, actual);
        }
    }

    /**
     * Test converting color from Meja to POI color and back again does not
     * change the color value.
     *
     * This test checks the implementation for XSSF.
     */
    @Test
    public void testColorConversionXssf() {
        PoiWorkbook.PoiXssfWorkbook wb = (PoiWorkbook.PoiXssfWorkbook) PoiWorkbookFactory.instance().createXlsx();
        for (Color col : Color.values()) {
            XSSFColor poiColor = wb.getPoiColor(col);
            Color expected = col;
            Color actual = wb.getColor(poiColor, Color.BLACK);
            assertEquals(expected, actual);
        }
    }

}

@@ -677,16 +677,112 @@
 Equals;%0D
+%0Aimport static org.junit.Assert.assertTrue;%0D%0A%0D%0Aimport java.util.HashSet;%0D%0Aimport java.util.Set;%0D
 %0A%0D%0Aimpor
@@ -1402,20 +1402,12 @@
 SSF 
-seems to 
 map
+s
  col
@@ -1464,272 +1464,248 @@
     
-// The first 16 entries seem to be exact.%0D%0A        int n = 0;%0D%0A        for (Color col : Color.values()) %7B%0D%0A            if (++n %3E 16) %7B%0D%0A                break;%0D%0A            %7D%0D%0A%0D%0A            HSSFColor poiColor = wb.getPoiColor(col);%0D%0A            Color expected = col
+Set%3CString%3E used = new HashSet%3C%3E();%0D%0A        for (Color col : Color.values()) %7B%0D%0A            HSSFColor poiColor = wb.getPoiColor(col);%0D%0A            short%5B%5D t = poiColor.getTriplet();%0D%0A            Color expected = new Color(t%5B0%5D, t%5B1%5D, t%5B2%5D)
 ;%0D%0A 
@@ -1812,33 +1812,114 @@
 tual);%0D%0A        
-%7D
+    used.add(expected.toString());%0D%0A        %7D%0D%0A        assertTrue(used.size()%3E20);
 %0D%0A    %7D%0D%0A%0D%0A    /

Fix test