public void testWrite() {
    HSSFWorkbook workbook = new HSSFWorkbook();
    HSSFSheet sheet = workbook.createSheet();
    CFRuleRecord rr = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "5", "10");

    PatternFormatting patternFormatting = new PatternFormatting();
    patternFormatting.setFillPattern(PatternFormatting.BRICKS);
    rr.setPatternFormatting(patternFormatting);

    byte[] data = rr.serialize();
    assertEquals(26, data.length);
    assertEquals(3, LittleEndian.getShort(data, 6));
    assertEquals(3, LittleEndian.getShort(data, 8));

    int flags = LittleEndian.getInt(data, 10);
    assertEquals("unused flags should be 111", 0x00380000, flags & 0x00380000);
    assertEquals(
        "undocumented flags should be 0000", 0, flags & 0x03C00000); // Otherwise Excel gets unhappy
    // check all remaining flag bits (some are not well understood yet)
    assertEquals(0x203FFFFF, flags);
  }
  private void testPatternFormattingAccessors(PatternFormatting patternFormatting) {
    patternFormatting.setFillBackgroundColor(HSSFColor.GREEN.index);
    assertEquals(HSSFColor.GREEN.index, patternFormatting.getFillBackgroundColor());

    patternFormatting.setFillForegroundColor(HSSFColor.INDIGO.index);
    assertEquals(HSSFColor.INDIGO.index, patternFormatting.getFillForegroundColor());

    patternFormatting.setFillPattern(PatternFormatting.DIAMONDS);
    assertEquals(PatternFormatting.DIAMONDS, patternFormatting.getFillPattern());
  }