public void testCustomPalette() {
//reading sample xls
HSSFWorkbook book = HSSFTestDataSamples.openSampleWorkbook("Simple.xls");
//creating custom palette
HSSFPalette palette = book.getCustomPalette();
palette.setColorAtIndex((short) 0x12, (byte) 101, (byte) 230, (byte) 100);
palette.setColorAtIndex((short) 0x3b, (byte) 0, (byte) 255, (byte) 52);
//writing to disk; reading in and verifying palette
book = HSSFTestDataSamples.writeOutAndReadBack(book);
palette = book.getCustomPalette();
HSSFColor color = palette.getColor(HSSFColor.CORAL.index); //unmodified
assertNotNull("Unexpected null in custom palette (unmodified index)", color);
short[] expectedRGB = HSSFColor.CORAL.triplet;
short[] actualRGB = color.getTriplet();
String msg = "Expected palette position to remain unmodified";
assertEquals(msg, expectedRGB[0], actualRGB[0]);
assertEquals(msg, expectedRGB[1], actualRGB[1]);
assertEquals(msg, expectedRGB[2], actualRGB[2]);
color = palette.getColor((short) 0x12);
assertNotNull("Unexpected null in custom palette (modified)", color);
actualRGB = color.getTriplet();
msg = "Expected palette modification to be preserved across save";
assertEquals(msg, (short) 101, actualRGB[0]);
assertEquals(msg, (short) 230, actualRGB[1]);