Permalink
Browse files

Remove public getPoiCell from SpreadsheetTab, revert getCell to getPo…

…iCell in SpreadsheetCell, minor cleanup.
  • Loading branch information...
jbrundege committed Mar 2, 2015
1 parent 23a6d80 commit ef9d1c0c9b98f6612315107702a48910db572873
@@ -28,6 +28,7 @@
* The getDateValue method returns null if the cell doesn't exist or is empty, and throws an exception if the
* value is not a date.
*/
@SuppressWarnings("UnusedDeclaration")
public class SpreadsheetReader {
/**
@@ -2,6 +2,7 @@
import taro.TaroException;
@SuppressWarnings("UnusedDeclaration")
public class TaroSpreadsheetException extends TaroException {
public TaroSpreadsheetException() {
@@ -1,20 +1,19 @@
package taro.spreadsheet.model;
import static java.lang.String.format;
import java.util.Calendar;
import java.util.Date;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFFont;
import taro.spreadsheet.TaroSpreadsheetException;
import java.util.Calendar;
import java.util.Date;
import static java.lang.String.format;
@SuppressWarnings("UnusedDeclaration")
public class SpreadsheetCell {
private DataFormatter dataFormatter = new DataFormatter();
@@ -86,7 +85,7 @@ public String getValue() {
return dataFormatter.formatCellValue(cell);
}
public XSSFCell getCell() {
public XSSFCell getPoiCell() {
return cell;
}
@@ -10,6 +10,7 @@
import org.apache.commons.lang3.StringUtils;
@SuppressWarnings("UnusedDeclaration")
public class SpreadsheetCellStyle {
// Colors from the excel 'styles' box on the toolbar
@@ -111,7 +111,7 @@ public SpreadsheetCell getOrCreateCell(int row, int col) {
return cell;
}
public XSSFCell getOrCreatePoiCell(int rowNum, int col) {
private XSSFCell getOrCreatePoiCell(int rowNum, int col) {
XSSFRow row = getOrCreatePoiRow(rowNum);
XSSFCell cell = row.getCell(col);
if (cell == null) {
@@ -194,7 +194,7 @@ public void autoSizeRow(int row) {
for (int col = 0; col <= highestModifiedCol; col++) {
SpreadsheetCell cell = getOrCreateCell(row, col);
int fontSize = cell.getFontSizeInPoints();
XSSFCell poiCell = cell.getCell();
XSSFCell poiCell = cell.getPoiCell();
if (poiCell.getCellType() == Cell.CELL_TYPE_STRING) {
String value = poiCell.getStringCellValue();
int numLines = 1;
@@ -2,7 +2,6 @@
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.*;
import java.io.IOException;
@@ -1,15 +1,12 @@
package taro.spreadsheet;
import static org.junit.Assert.*;
import java.util.Date;
import java.util.List;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.junit.Test;
import taro.spreadsheet.model.AbstractTest;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
public class SpreadsheetReaderTest extends AbstractTest {
@@ -126,8 +123,6 @@ public void readDown_ReadsNumericColumn() {
SpreadsheetReader sheet = new SpreadsheetReader(getSpreadsheetTabWithValues().getPoiSheet());
String[] values = sheet.readDown("B2", 3);
DataFormatter dataFormatter = new DataFormatter();
assertThat(values.length)
.isEqualTo(3);
@@ -23,10 +23,10 @@ public void setValueWithString_SetsAStringValueOnTheCell() {
SpreadsheetCell cell = getCell();
cell.setValue("A String");
assertThat(cell.getCell().getCellType())
assertThat(cell.getPoiCell().getCellType())
.isEqualTo(Cell.CELL_TYPE_STRING);
assertThat(cell.getCell().getStringCellValue())
assertThat(cell.getPoiCell().getStringCellValue())
.isEqualTo("A String");
}
@@ -36,31 +36,31 @@ public void setValueWithStringFormula_SetsAFormulaOnTheCell() {
cell.setValue("=B1*C1"); // formula is any string starting with an equals (=) sign
assertThat(cell.getCell().getCellType())
assertThat(cell.getPoiCell().getCellType())
.isEqualTo(Cell.CELL_TYPE_FORMULA);
assertThat(cell.getCell().getCellFormula())
assertThat(cell.getPoiCell().getCellFormula())
.isEqualTo("B1*C1");
}
@Test
public void setValueWithShort_SetsANumericValueOnTheCell() {
SpreadsheetCell cell = getCell();
cell.setValue((short) 12);
assertThat(cell.getCell().getCellType())
assertThat(cell.getPoiCell().getCellType())
.isEqualTo(Cell.CELL_TYPE_NUMERIC);
assertThat(cell.getCell().getNumericCellValue())
assertThat(cell.getPoiCell().getNumericCellValue())
.isEqualTo(12.0);
}
@Test
public void setValueWithInteger_SetsANumericValueOnTheCell() {
SpreadsheetCell cell = getCell();
cell.setValue(12);
assertThat(cell.getCell().getCellType())
assertThat(cell.getPoiCell().getCellType())
.isEqualTo(Cell.CELL_TYPE_NUMERIC);
assertThat(cell.getCell().getNumericCellValue())
assertThat(cell.getPoiCell().getNumericCellValue())
.isEqualTo(12.0);
}
@@ -70,9 +70,9 @@ public void setValueWithLong_SetsANumericValueOnTheCell() {
cell.setValue(12L);
assertThat(cell.getCell().getCellType())
assertThat(cell.getPoiCell().getCellType())
.isEqualTo(Cell.CELL_TYPE_NUMERIC);
assertThat(cell.getCell().getNumericCellValue())
assertThat(cell.getPoiCell().getNumericCellValue())
.isEqualTo(12.0);
}
@@ -82,19 +82,19 @@ public void setValueWithFloat_SetsANumericValueOnTheCell() {
SpreadsheetCell cell = getCell();
cell.setValue(12f);
assertThat(cell.getCell().getCellType())
assertThat(cell.getPoiCell().getCellType())
.isEqualTo(Cell.CELL_TYPE_NUMERIC);
assertThat(cell.getCell().getNumericCellValue())
assertThat(cell.getPoiCell().getNumericCellValue())
.isEqualTo(12.0);
}
@Test
public void setValueWithDouble_SetsANumericValueOnTheCell() {
SpreadsheetCell cell = getCell();
cell.setValue(12.0);
assertThat(cell.getCell().getCellType())
assertThat(cell.getPoiCell().getCellType())
.isEqualTo(Cell.CELL_TYPE_NUMERIC);
assertThat(cell.getCell().getNumericCellValue())
assertThat(cell.getPoiCell().getNumericCellValue())
.isEqualTo(12.0);
}
@@ -105,9 +105,9 @@ public void setValueWithDate_SetsADateValueOnTheCell() {
SpreadsheetCell cell = getCell();
cell.setValue(date);
assertThat(cell.getCell().getCellType())
assertThat(cell.getPoiCell().getCellType())
.isEqualTo(Cell.CELL_TYPE_NUMERIC);
assertThat(cell.getCell().getNumericCellValue())
assertThat(cell.getPoiCell().getNumericCellValue())
.isCloseTo(excelDateNumber, within(0.001));
}
@@ -119,21 +119,21 @@ public void setValueWithCalendar_SetsADateValueOnTheCell() {
SpreadsheetCell cell = getCell();
cell.setValue(calendar);
assertThat(cell.getCell().getCellType())
assertThat(cell.getPoiCell().getCellType())
.isEqualTo(Cell.CELL_TYPE_NUMERIC);
assertThat(cell.getCell().getNumericCellValue())
assertThat(cell.getPoiCell().getNumericCellValue())
.isCloseTo(excelDateNumber, within(0.001));
}
@Test
public void setValueWithBoolean_SetsABooleanValueOnTheCell() {
SpreadsheetCell cell = getCell();
cell.setValue(true);
assertThat(cell.getCell().getCellType())
assertThat(cell.getPoiCell().getCellType())
.isEqualTo(Cell.CELL_TYPE_BOOLEAN);
assertThat(cell.getCell().getBooleanCellValue())
assertThat(cell.getPoiCell().getBooleanCellValue())
.isTrue();
}
@@ -144,10 +144,10 @@ public void setValueWithNull_SetsABlankValueOnTheCell() {
cell.setValue("A String to value to start with");
cell.setValue(null); // wipe out the string value
assertThat(cell.getCell().getCellType())
assertThat(cell.getPoiCell().getCellType())
.isEqualTo(Cell.CELL_TYPE_BLANK);
assertThat(cell.getCell().getStringCellValue())
assertThat(cell.getPoiCell().getStringCellValue())
.isEmpty();
}
@@ -156,7 +156,7 @@ public void cellsStyle_IsNullUntilSet() {
SpreadsheetCell cell = getCell();
assertThat(cell.getStyle())
.isNull();;
.isNull();
SpreadsheetCellStyle cellStyle = new SpreadsheetCellStyle().withAlign(CellStyle.ALIGN_CENTER);
cell.setStyle(cellStyle);
@@ -3,7 +3,6 @@
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
import static org.apache.poi.ss.usermodel.CellStyle.BORDER_MEDIUM;
@@ -47,7 +46,7 @@ public void setValue_SetsBothValueAndStyle() {
assertThat(tab.getCell(2, 2).getValue())
.isEqualTo("three");
assertThat(tab.getCell(2, 2).getCell().getCellStyle().getAlignment())
assertThat(tab.getCell(2, 2).getPoiCell().getCellStyle().getAlignment())
.isEqualTo(CellStyle.ALIGN_CENTER);
}

0 comments on commit ef9d1c0

Please sign in to comment.