fix unnecessary cast warnings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1715626 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Andreas Beeker 2015-11-22 12:30:42 +00:00
parent e0f10f2071
commit 4ccadf7315
29 changed files with 117 additions and 84 deletions

View File

@ -250,7 +250,6 @@ public class AddDimensionedImage {
String imageFile, double reqImageWidthMM, double reqImageHeightMM, String imageFile, double reqImageWidthMM, double reqImageHeightMM,
int resizeBehaviour) throws FileNotFoundException, IOException, int resizeBehaviour) throws FileNotFoundException, IOException,
IllegalArgumentException { IllegalArgumentException {
HSSFRow row = null;
HSSFClientAnchor anchor = null; HSSFClientAnchor anchor = null;
HSSFPatriarch patriarch = null; HSSFPatriarch patriarch = null;
ClientAnchorDetail rowClientAnchorDetail = null; ClientAnchorDetail rowClientAnchorDetail = null;
@ -720,7 +719,6 @@ public class AddDimensionedImage {
public static void main(String[] args) { public static void main(String[] args) {
String imageFile = null; String imageFile = null;
String outputFile = null; String outputFile = null;
FileInputStream fis = null;
FileOutputStream fos = null; FileOutputStream fos = null;
HSSFWorkbook workbook = null; HSSFWorkbook workbook = null;
HSSFSheet sheet = null; HSSFSheet sheet = null;
@ -753,14 +751,20 @@ public class AddDimensionedImage {
ioEx.printStackTrace(System.out); ioEx.printStackTrace(System.out);
} }
finally { finally {
if(fos != null) { try {
try { if (workbook != null) {
workbook.close();
}
} catch(IOException ioEx) {
// I G N O R E
}
try {
if(fos != null) {
fos.close(); fos.close();
fos = null; fos = null;
} }
catch(IOException ioEx) { } catch(IOException ioEx) {
// I G N O R E // I G N O R E
}
} }
} }
} }
@ -912,7 +916,7 @@ public class AddDimensionedImage {
int pixels = (widthUnits / EXCEL_COLUMN_WIDTH_FACTOR) int pixels = (widthUnits / EXCEL_COLUMN_WIDTH_FACTOR)
* UNIT_OFFSET_LENGTH; * UNIT_OFFSET_LENGTH;
int offsetWidthUnits = widthUnits % EXCEL_COLUMN_WIDTH_FACTOR; int offsetWidthUnits = widthUnits % EXCEL_COLUMN_WIDTH_FACTOR;
pixels += Math.round((float) offsetWidthUnits / pixels += Math.round(offsetWidthUnits /
((float) EXCEL_COLUMN_WIDTH_FACTOR / UNIT_OFFSET_LENGTH)); ((float) EXCEL_COLUMN_WIDTH_FACTOR / UNIT_OFFSET_LENGTH));
return pixels; return pixels;
} }

View File

@ -163,7 +163,7 @@ public class SVSheetTable extends JTable {
Row row = sheet.getRow(i - sheet.getFirstRowNum()); Row row = sheet.getRow(i - sheet.getFirstRowNum());
if (row != null) { if (row != null) {
short h = row.getHeight(); short h = row.getHeight();
int height = (int)Math.round(Math.max(1., ((double)h) / (((double)res) / 70. * 20.) + 3.)); int height = (int)Math.round(Math.max(1., h / (res / 70. * 20.) + 3.));
System.out.printf("%d: %d (%d @ %d)%n", i, height, h, res); System.out.printf("%d: %d (%d @ %d)%n", i, height, h, res);
setRowHeight(i, height); setRowHeight(i, height);
} }

View File

@ -18,14 +18,25 @@
package org.apache.poi.hssf.view; package org.apache.poi.hssf.view;
import java.awt.*; import java.awt.Color;
import java.awt.event.*; import java.awt.Component;
import java.util.*; import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent;
import java.util.EventObject;
import java.util.Map;
import javax.swing.*; import javax.swing.AbstractCellEditor;
import javax.swing.table.*; import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.table.TableCellEditor;
import org.apache.poi.hssf.usermodel.*; import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor; import org.apache.poi.hssf.util.HSSFColor;
/** /**
@ -43,9 +54,6 @@ public class SVTableCellEditor extends AbstractCellEditor implements TableCellEd
private HSSFWorkbook wb; private HSSFWorkbook wb;
private JTextField editor; private JTextField editor;
private HSSFCell editorValue;
public SVTableCellEditor(HSSFWorkbook wb) { public SVTableCellEditor(HSSFWorkbook wb) {
this.wb = wb; this.wb = wb;
this.editor = new JTextField(); this.editor = new JTextField();
@ -191,7 +199,7 @@ public class SVTableCellEditor extends AbstractCellEditor implements TableCellEd
* *
*/ */
private final Color getAWTColor(int index, Color deflt) { private final Color getAWTColor(int index, Color deflt) {
HSSFColor clr = (HSSFColor)colors.get(Integer.valueOf(index)); HSSFColor clr = colors.get(index);
if (clr == null) return deflt; if (clr == null) return deflt;
return getAWTColor(clr); return getAWTColor(clr);
} }

View File

@ -72,7 +72,7 @@ public class SVTableUtils {
* @return The aWTColor value * @return The aWTColor value
*/ */
public final static Color getAWTColor(int index, Color deflt) { public final static Color getAWTColor(int index, Color deflt) {
HSSFColor clr = (HSSFColor) colors.get(Integer.valueOf(index)); HSSFColor clr = colors.get(index);
if (clr == null) { if (clr == null) {
return deflt; return deflt;
} }

View File

@ -182,7 +182,7 @@ public class TreeReaderListener implements POIFSReaderListener
final String fsName, final String fsName,
final MutableTreeNode root) final MutableTreeNode root)
{ {
MutableTreeNode n = (MutableTreeNode) pathToNode.get(path); MutableTreeNode n = pathToNode.get(path);
if (n != null) if (n != null)
/* Node found in map, just return it. */ /* Node found in map, just return it. */
return n; return n;
@ -193,7 +193,7 @@ public class TreeReaderListener implements POIFSReaderListener
* the POI filesystem itself. This is a tree node with the * the POI filesystem itself. This is a tree node with the
* POI filesystem's name (this the operating system file's * POI filesystem's name (this the operating system file's
* name) as its key it the path-to-node map. */ * name) as its key it the path-to-node map. */
n = (MutableTreeNode) pathToNode.get(fsName); n = pathToNode.get(fsName);
if (n == null) if (n == null)
{ {
/* A tree node for the POI filesystem does not yet /* A tree node for the POI filesystem does not yet

View File

@ -34,7 +34,7 @@ public class CreatePivotTable {
public static void main(String[] args) throws FileNotFoundException, IOException, InvalidFormatException { public static void main(String[] args) throws FileNotFoundException, IOException, InvalidFormatException {
XSSFWorkbook wb = new XSSFWorkbook(); XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet = (XSSFSheet) wb.createSheet(); XSSFSheet sheet = wb.createSheet();
//Create some data to build the pivot table on //Create some data to build the pivot table on
setCellData(sheet); setCellData(sheet);
@ -53,6 +53,7 @@ public class CreatePivotTable {
FileOutputStream fileOut = new FileOutputStream("ooxml-pivottable.xlsx"); FileOutputStream fileOut = new FileOutputStream("ooxml-pivottable.xlsx");
wb.write(fileOut); wb.write(fileOut);
fileOut.close(); fileOut.close();
wb.close();
} }
public static void setCellData(XSSFSheet sheet){ public static void setCellData(XSSFSheet sheet){

View File

@ -440,10 +440,10 @@ public abstract class CFRuleBase extends StandardRecord implements Cloneable {
rec.formatting_options = formatting_options; rec.formatting_options = formatting_options;
rec.formatting_not_used = formatting_not_used; rec.formatting_not_used = formatting_not_used;
if (containsFontFormattingBlock()) { if (containsFontFormattingBlock()) {
rec._fontFormatting = (FontFormatting) _fontFormatting.clone(); rec._fontFormatting = _fontFormatting.clone();
} }
if (containsBorderFormattingBlock()) { if (containsBorderFormattingBlock()) {
rec._borderFormatting = (BorderFormatting) _borderFormatting.clone(); rec._borderFormatting = _borderFormatting.clone();
} }
if (containsPatternFormattingBlock()) { if (containsPatternFormattingBlock()) {
rec._patternFormatting = (PatternFormatting) _patternFormatting.clone(); rec._patternFormatting = (PatternFormatting) _patternFormatting.clone();

View File

@ -135,9 +135,9 @@ public final class DataBarFormatting implements Cloneable {
rec.options = options; rec.options = options;
rec.percentMin = percentMin; rec.percentMin = percentMin;
rec.percentMax = percentMax; rec.percentMax = percentMax;
rec.color = (ExtendedColor)color.clone(); rec.color = color.clone();
rec.thresholdMin = (DataBarThreshold)thresholdMin.clone(); rec.thresholdMin = thresholdMin.clone();
rec.thresholdMax = (DataBarThreshold)thresholdMax.clone(); rec.thresholdMax = thresholdMax.clone();
return rec; return rec;
} }

View File

@ -176,7 +176,7 @@ public class CTSRgbColor {
* *
*/ */
public void setVal(byte[] value) { public void setVal(byte[] value) {
this.val = ((byte[]) value); this.val = (value != null) ? value.clone() : null;
} }
public boolean isSetVal() { public boolean isSetVal() {

View File

@ -209,7 +209,7 @@ public class CTSystemColor {
* *
*/ */
public void setLastClr(byte[] value) { public void setLastClr(byte[] value) {
this.lastClr = ((byte[]) value); this.lastClr = (value != null) ? value.clone() : null;
} }
public boolean isSetLastClr() { public boolean isSetLastClr() {

View File

@ -32,7 +32,7 @@ public class SimpleFraction {
* @return a SimpleFraction with the given values set. * @return a SimpleFraction with the given values set.
*/ */
public static SimpleFraction buildFractionExactDenominator(double val, int exactDenom){ public static SimpleFraction buildFractionExactDenominator(double val, int exactDenom){
int num = (int)Math.round(val*(double)exactDenom); int num = (int)Math.round(val*exactDenom);
return new SimpleFraction(num,exactDenom); return new SimpleFraction(num,exactDenom);
} }

View File

@ -19,21 +19,27 @@
package org.apache.poi.xssf.streaming; package org.apache.poi.xssf.streaming;
import java.io.IOException; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import junit.framework.TestCase; import java.io.IOException;
import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.junit.Test;
public final class TestOutlining extends TestCase { public final class TestOutlining {
public void testSetRowGroupCollapsed() throws Exception { @Test
public void testSetRowGroupCollapsed() throws IOException {
SXSSFWorkbook wb2 = new SXSSFWorkbook(100); SXSSFWorkbook wb2 = new SXSSFWorkbook(100);
wb2.setCompressTempFiles(true); wb2.setCompressTempFiles(true);
SXSSFSheet sheet2 = (SXSSFSheet) wb2.createSheet("new sheet"); SXSSFSheet sheet2 = wb2.createSheet("new sheet");
int rowCount = 20; int rowCount = 20;
for (int i = 0; i < rowCount; i++) { for (int i = 0; i < rowCount; i++) {
@ -45,21 +51,22 @@ public final class TestOutlining extends TestCase {
sheet2.setRowGroupCollapsed(4, true); sheet2.setRowGroupCollapsed(4, true);
SXSSFRow r = (SXSSFRow) sheet2.getRow(8); SXSSFRow r = sheet2.getRow(8);
assertTrue(r.getHidden()); assertTrue(r.getHidden());
r = (SXSSFRow) sheet2.getRow(10); r = sheet2.getRow(10);
assertTrue(r.getCollapsed()); assertTrue(r.getCollapsed());
r = (SXSSFRow) sheet2.getRow(12); r = sheet2.getRow(12);
assertNull(r.getHidden()); assertNull(r.getHidden());
wb2.dispose(); wb2.dispose();
wb2.close(); wb2.close();
} }
public void testSetRowGroupCollapsedError() throws Exception { @Test
public void testSetRowGroupCollapsedError() throws IOException {
SXSSFWorkbook wb2 = new SXSSFWorkbook(100); SXSSFWorkbook wb2 = new SXSSFWorkbook(100);
wb2.setCompressTempFiles(true); wb2.setCompressTempFiles(true);
SXSSFSheet sheet2 = (SXSSFSheet) wb2.createSheet("new sheet"); SXSSFSheet sheet2 = wb2.createSheet("new sheet");
int rowCount = 20; int rowCount = 20;
for (int i = 0; i < rowCount; i++) { for (int i = 0; i < rowCount; i++) {
@ -98,18 +105,19 @@ public final class TestOutlining extends TestCase {
e.getMessage().contains("Row does not exist")); e.getMessage().contains("Row does not exist"));
} }
SXSSFRow r = (SXSSFRow) sheet2.getRow(8); SXSSFRow r = sheet2.getRow(8);
assertNotNull(r); assertNotNull(r);
assertNull(r.getHidden()); assertNull(r.getHidden());
r = (SXSSFRow) sheet2.getRow(10); r = sheet2.getRow(10);
assertNull(r.getCollapsed()); assertNull(r.getCollapsed());
r = (SXSSFRow) sheet2.getRow(12); r = sheet2.getRow(12);
assertNull(r.getHidden()); assertNull(r.getHidden());
wb2.dispose(); wb2.dispose();
wb2.close(); wb2.close();
} }
@Test
public void testOutlineGettersHSSF() throws IOException { public void testOutlineGettersHSSF() throws IOException {
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); HSSFWorkbook hssfWorkbook = new HSSFWorkbook();
HSSFSheet hssfSheet = hssfWorkbook.createSheet(); HSSFSheet hssfSheet = hssfWorkbook.createSheet();
@ -129,6 +137,7 @@ public final class TestOutlining extends TestCase {
hssfWorkbook.close(); hssfWorkbook.close();
} }
@Test
public void testOutlineGettersXSSF() throws IOException { public void testOutlineGettersXSSF() throws IOException {
XSSFWorkbook xssfWorkbook = new XSSFWorkbook(); XSSFWorkbook xssfWorkbook = new XSSFWorkbook();
XSSFSheet xssfSheet = xssfWorkbook.createSheet(); XSSFSheet xssfSheet = xssfWorkbook.createSheet();
@ -148,6 +157,7 @@ public final class TestOutlining extends TestCase {
xssfWorkbook.close(); xssfWorkbook.close();
} }
@Test
public void testOutlineGettersSXSSF() throws IOException { public void testOutlineGettersSXSSF() throws IOException {
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(); SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
Sheet sxssfSheet = sxssfWorkbook.createSheet(); Sheet sxssfSheet = sxssfWorkbook.createSheet();
@ -190,6 +200,7 @@ public final class TestOutlining extends TestCase {
sxssfWorkbook.close(); sxssfWorkbook.close();
} }
@Test
public void testOutlineGettersSXSSFSetOutlineLevel() throws IOException { public void testOutlineGettersSXSSFSetOutlineLevel() throws IOException {
SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook(); SXSSFWorkbook sxssfWorkbook = new SXSSFWorkbook();
Sheet sxssfSheet = sxssfWorkbook.createSheet(); Sheet sxssfSheet = sxssfWorkbook.createSheet();

View File

@ -37,7 +37,6 @@ public final class OldSectionTable extends SectionTable
* @deprecated Use {@link #OldSectionTable(byte[],int,int)} instead * @deprecated Use {@link #OldSectionTable(byte[],int,int)} instead
*/ */
@Deprecated @Deprecated
@SuppressWarnings( "unused" )
public OldSectionTable( byte[] documentStream, int offset, int size, public OldSectionTable( byte[] documentStream, int offset, int size,
int fcMin, TextPieceTable tpt ) int fcMin, TextPieceTable tpt )
{ {

View File

@ -61,7 +61,6 @@ public class PAPBinTable
* {@link #PAPBinTable(byte[], byte[], byte[], int, int, CharIndexTranslator)} * {@link #PAPBinTable(byte[], byte[], byte[], int, int, CharIndexTranslator)}
* instead * instead
*/ */
@SuppressWarnings( "unused" )
public PAPBinTable( byte[] documentStream, byte[] tableStream, public PAPBinTable( byte[] documentStream, byte[] tableStream,
byte[] dataStream, int offset, int size, int fcMin, byte[] dataStream, int offset, int size, int fcMin,
TextPieceTable tpt ) TextPieceTable tpt )

View File

@ -214,7 +214,7 @@ public class Sttb
if ( _fExtend ) if ( _fExtend )
{ {
LittleEndian.putUShort( buffer, offset, (int) entry.length() ); LittleEndian.putUShort( buffer, offset, entry.length() );
offset += LittleEndian.SHORT_SIZE; offset += LittleEndian.SHORT_SIZE;
StringUtil.putUnicodeLE( entry, buffer, offset ); StringUtil.putUnicodeLE( entry, buffer, offset );

View File

@ -79,7 +79,7 @@ public abstract class FSPAAbstractType
LittleEndian.putInt(data, 0x8 + offset, field_3_yaTop); LittleEndian.putInt(data, 0x8 + offset, field_3_yaTop);
LittleEndian.putInt(data, 0xc + offset, field_4_xaRight); LittleEndian.putInt(data, 0xc + offset, field_4_xaRight);
LittleEndian.putInt(data, 0x10 + offset, field_5_yaBottom); LittleEndian.putInt(data, 0x10 + offset, field_5_yaBottom);
LittleEndian.putShort(data, 0x14 + offset, (short)field_6_flags); LittleEndian.putShort(data, 0x14 + offset, field_6_flags);
LittleEndian.putInt(data, 0x16 + offset, field_7_cTxbx); LittleEndian.putInt(data, 0x16 + offset, field_7_cTxbx);
} }

View File

@ -70,7 +70,7 @@ public final class TestCruddyExtractor extends TestCase {
// Ensure they match // Ensure they match
assertEquals(allTheText.length,foundTextV.size()); assertEquals(allTheText.length,foundTextV.size());
for(int i=0; i<allTheText.length; i++) { for(int i=0; i<allTheText.length; i++) {
String foundText = (String)foundTextV.get(i); String foundText = foundTextV.get(i);
assertEquals(allTheText[i],foundText); assertEquals(allTheText[i],foundText);
} }
} }

View File

@ -17,25 +17,29 @@
package org.apache.poi.hwpf.usermodel; package org.apache.poi.hwpf.usermodel;
import java.util.List; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import junit.framework.TestCase; import java.util.List;
import org.apache.poi.POIDataSamples; import org.apache.poi.POIDataSamples;
import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.PicturesTable; import org.apache.poi.hwpf.model.PicturesTable;
import org.junit.Test;
/** /**
* Test the picture handling * Test the picture handling
* *
* @author Nick Burch * @author Nick Burch
*/ */
public final class TestPictures extends TestCase { public final class TestPictures {
/** /**
* two jpegs * two jpegs
*/ */
@Test
public void testTwoImages() { public void testTwoImages() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("two_images.doc"); HWPFDocument doc = HWPFTestDataSamples.openSampleFile("two_images.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures(); List<Picture> pics = doc.getPicturesTable().getAllPictures();
@ -43,7 +47,7 @@ public final class TestPictures extends TestCase {
assertNotNull(pics); assertNotNull(pics);
assertEquals(pics.size(), 2); assertEquals(pics.size(), 2);
for(int i=0; i<pics.size(); i++) { for(int i=0; i<pics.size(); i++) {
Picture pic = (Picture)pics.get(i); Picture pic = pics.get(i);
assertNotNull(pic.suggestFileExtension()); assertNotNull(pic.suggestFileExtension());
assertNotNull(pic.suggestFullFileName()); assertNotNull(pic.suggestFullFileName());
} }
@ -51,20 +55,20 @@ public final class TestPictures extends TestCase {
Picture picA = pics.get(0); Picture picA = pics.get(0);
Picture picB = pics.get(1); Picture picB = pics.get(1);
assertEquals("jpg", picA.suggestFileExtension()); assertEquals("jpg", picA.suggestFileExtension());
assertEquals("jpg", picA.suggestFileExtension()); assertEquals("png", picB.suggestFileExtension());
} }
/** /**
* pngs and jpegs * pngs and jpegs
*/ */
@Test
public void testDifferentImages() { public void testDifferentImages() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("testPictures.doc"); HWPFDocument doc = HWPFTestDataSamples.openSampleFile("testPictures.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures(); List<Picture> pics = doc.getPicturesTable().getAllPictures();
assertNotNull(pics); assertNotNull(pics);
assertEquals(7, pics.size()); assertEquals(7, pics.size());
for(int i=0; i<pics.size(); i++) { for(Picture pic : pics) {
Picture pic = (Picture)pics.get(i);
assertNotNull(pic.suggestFileExtension()); assertNotNull(pic.suggestFileExtension());
assertNotNull(pic.suggestFullFileName()); assertNotNull(pic.suggestFullFileName());
} }
@ -86,6 +90,7 @@ public final class TestPictures extends TestCase {
/** /**
* emf image, nice and simple * emf image, nice and simple
*/ */
@Test
public void testEmfImage() { public void testEmfImage() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("vector_image.doc"); HWPFDocument doc = HWPFTestDataSamples.openSampleFile("vector_image.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures(); List<Picture> pics = doc.getPicturesTable().getAllPictures();
@ -107,32 +112,37 @@ public final class TestPictures extends TestCase {
} }
} }
public void testPicturesWithTable() { @Test
public void testPicturesWithTable() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44603.doc"); HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug44603.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures(); List<Picture> pics = doc.getPicturesTable().getAllPictures();
assertEquals(2, pics.size()); assertEquals(2, pics.size());
} }
public void testPicturesInHeader() { @Test
public void testPicturesInHeader() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("header_image.doc"); HWPFDocument doc = HWPFTestDataSamples.openSampleFile("header_image.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures(); List<Picture> pics = doc.getPicturesTable().getAllPictures();
assertEquals(2, pics.size()); assertEquals(2, pics.size());
} }
@Test
public void testFastSaved() { public void testFastSaved() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("rasp.doc"); HWPFDocument doc = HWPFTestDataSamples.openSampleFile("rasp.doc");
doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
} }
@Test
public void testFastSaved2() { public void testFastSaved2() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("o_kurs.doc"); HWPFDocument doc = HWPFTestDataSamples.openSampleFile("o_kurs.doc");
doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception doc.getPicturesTable().getAllPictures(); // just check that we do not throw Exception
} }
@Test
public void testFastSaved3() { public void testFastSaved3() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ob_is.doc"); HWPFDocument doc = HWPFTestDataSamples.openSampleFile("ob_is.doc");
@ -146,7 +156,8 @@ public final class TestPictures extends TestCase {
* then used as-is to speed things up. * then used as-is to speed things up.
* Check that we can properly read one of these * Check that we can properly read one of these
*/ */
public void testEmbededDocumentIcon() throws Exception { @Test
public void testEmbededDocumentIcon() {
// This file has two embeded excel files, an embeded powerpoint // This file has two embeded excel files, an embeded powerpoint
// file and an embeded word file, in that order // file and an embeded word file, in that order
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("word_with_embeded.doc"); HWPFDocument doc = HWPFTestDataSamples.openSampleFile("word_with_embeded.doc");
@ -231,6 +242,7 @@ public final class TestPictures extends TestCase {
assertEquals( "image/x-emf", picture.getMimeType() ); assertEquals( "image/x-emf", picture.getMimeType() );
} }
@Test
public void testEquation() public void testEquation()
{ {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "equation.doc" ); HWPFDocument doc = HWPFTestDataSamples.openSampleFile( "equation.doc" );
@ -256,7 +268,8 @@ public final class TestPictures extends TestCase {
* \u0001 which has the offset. More than one can * \u0001 which has the offset. More than one can
* reference the same \u0001 * reference the same \u0001
*/ */
public void testFloatingPictures() throws Exception { @Test
public void testFloatingPictures() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("FloatingPictures.doc"); HWPFDocument doc = HWPFTestDataSamples.openSampleFile("FloatingPictures.doc");
PicturesTable pictures = doc.getPicturesTable(); PicturesTable pictures = doc.getPicturesTable();
@ -290,6 +303,7 @@ public final class TestPictures extends TestCase {
} }
@SuppressWarnings( "deprecation" ) @SuppressWarnings( "deprecation" )
@Test
public void testCroppedPictures() { public void testCroppedPictures() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("testCroppedPictures.doc"); HWPFDocument doc = HWPFTestDataSamples.openSampleFile("testCroppedPictures.doc");
List<Picture> pics = doc.getPicturesTable().getAllPictures(); List<Picture> pics = doc.getPicturesTable().getAllPictures();
@ -323,7 +337,8 @@ public final class TestPictures extends TestCase {
assertEquals(0, pic2.getDyaCropBottom()); assertEquals(0, pic2.getDyaCropBottom());
} }
public void testPictureDetectionWithPNG() throws Exception { @Test
public void testPictureDetectionWithPNG() {
HWPFDocument document = HWPFTestDataSamples.openSampleFile("PngPicture.doc"); HWPFDocument document = HWPFTestDataSamples.openSampleFile("PngPicture.doc");
PicturesTable pictureTable = document.getPicturesTable(); PicturesTable pictureTable = document.getPicturesTable();
@ -334,7 +349,8 @@ public final class TestPictures extends TestCase {
assertEquals("png", p.suggestFileExtension()); assertEquals("png", p.suggestFileExtension());
} }
public void testPictureWithAlternativeText() throws Exception { @Test
public void testPictureWithAlternativeText() {
HWPFDocument document = HWPFTestDataSamples.openSampleFile("Picture_Alternative_Text.doc"); HWPFDocument document = HWPFTestDataSamples.openSampleFile("Picture_Alternative_Text.doc");
PicturesTable pictureTable = document.getPicturesTable(); PicturesTable pictureTable = document.getPicturesTable();
Picture picture = pictureTable.getAllPictures().get(0); Picture picture = pictureTable.getAllPictures().get(0);

View File

@ -17,12 +17,12 @@
package org.apache.poi.hwpf.usermodel; package org.apache.poi.hwpf.usermodel;
import junit.framework.TestCase;
import org.apache.poi.hwpf.HWPFDocument; import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.HWPFTestDataSamples; import org.apache.poi.hwpf.HWPFTestDataSamples;
import org.apache.poi.hwpf.model.PAPX; import org.apache.poi.hwpf.model.PAPX;
import junit.framework.TestCase;
/** /**
* Test to see if Range.delete() works even if the Range contains a * Test to see if Range.delete() works even if the Range contains a
* CharacterRun that uses Unicode characters. * CharacterRun that uses Unicode characters.
@ -93,7 +93,7 @@ public final class TestRangeDelete extends TestCase {
assertEquals(fillerText, para.text()); assertEquals(fillerText, para.text());
paraDef = (PAPX)daDoc.getParagraphTable().getParagraphs().get(2); paraDef = daDoc.getParagraphTable().getParagraphs().get(2);
assertEquals(132, paraDef.getStart()); assertEquals(132, paraDef.getStart());
assertEquals(400, paraDef.getEnd()); assertEquals(400, paraDef.getEnd());
@ -102,7 +102,7 @@ public final class TestRangeDelete extends TestCase {
assertEquals(originalText, para.text()); assertEquals(originalText, para.text());
paraDef = (PAPX)daDoc.getParagraphTable().getParagraphs().get(3); paraDef = daDoc.getParagraphTable().getParagraphs().get(3);
assertEquals(400, paraDef.getStart()); assertEquals(400, paraDef.getStart());
assertEquals(438, paraDef.getEnd()); assertEquals(438, paraDef.getEnd());

View File

@ -62,7 +62,7 @@ public class TestVariantSupport extends TestCase {
PropertySet ps = PropertySetFactory.create(new ByteArrayInputStream(bytes)); PropertySet ps = PropertySetFactory.create(new ByteArrayInputStream(bytes));
DocumentSummaryInformation dsi = (DocumentSummaryInformation) ps; DocumentSummaryInformation dsi = (DocumentSummaryInformation) ps;
Section s = (Section) dsi.getSections().get(0); Section s = dsi.getSections().get(0);
Object hdrs = s.getProperty(PropertyIDMap.PID_HEADINGPAIR); Object hdrs = s.getProperty(PropertyIDMap.PID_HEADINGPAIR);

View File

@ -57,7 +57,7 @@ public final class TestAutoFilterInfoRecord extends TestCase {
record.setNumEntries((short)3); record.setNumEntries((short)3);
byte[] src = record.serialize(); byte[] src = record.serialize();
AutoFilterInfoRecord cloned = (AutoFilterInfoRecord)record.clone(); AutoFilterInfoRecord cloned = record.clone();
assertEquals(3, record.getNumEntries()); assertEquals(3, record.getNumEntries());
byte[] cln = cloned.serialize(); byte[] cln = cloned.serialize();

View File

@ -437,7 +437,7 @@ public final class TestCFRuleRecord extends TestCase {
CFRuleRecord record = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5"); CFRuleRecord record = CFRuleRecord.create(sheet, ComparisonOperator.BETWEEN, "2", "5");
CFRuleRecord clone = (CFRuleRecord) record.clone(); CFRuleRecord clone = record.clone();
byte [] serializedRecord = record.serialize(); byte [] serializedRecord = record.serialize();
byte [] serializedClone = clone.serialize(); byte [] serializedClone = clone.serialize();

View File

@ -56,7 +56,7 @@ public final class TestFtCblsSubRecord extends TestCase {
FtCblsSubRecord record = new FtCblsSubRecord(); FtCblsSubRecord record = new FtCblsSubRecord();
byte[] src = record.serialize(); byte[] src = record.serialize();
FtCblsSubRecord cloned = (FtCblsSubRecord)record.clone(); FtCblsSubRecord cloned = record.clone();
byte[] cln = cloned.serialize(); byte[] cln = cloned.serialize();
assertEquals(record.getDataSize(), cloned.getDataSize()); assertEquals(record.getDataSize(), cloned.getDataSize());

View File

@ -432,7 +432,7 @@ public final class TestHyperlinkRecord {
for (int i = 0; i < data.length; i++) { for (int i = 0; i < data.length; i++) {
RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, data[i]); RecordInputStream is = TestcaseRecordInputStream.create(HyperlinkRecord.sid, data[i]);
HyperlinkRecord link = new HyperlinkRecord(is); HyperlinkRecord link = new HyperlinkRecord(is);
HyperlinkRecord clone = (HyperlinkRecord)link.clone(); HyperlinkRecord clone = link.clone();
assertArrayEquals(link.serialize(), clone.serialize()); assertArrayEquals(link.serialize(), clone.serialize());
} }

View File

@ -42,7 +42,7 @@ public final class TestMergeCellsRecord extends TestCase {
public void testCloneReferences() { public void testCloneReferences() {
CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2), }; CellRangeAddress[] cras = { new CellRangeAddress(0, 1, 0, 2), };
MergeCellsRecord merge = new MergeCellsRecord(cras, 0, cras.length); MergeCellsRecord merge = new MergeCellsRecord(cras, 0, cras.length);
MergeCellsRecord clone = (MergeCellsRecord)merge.clone(); MergeCellsRecord clone = merge.clone();
assertNotSame("Merged and cloned objects are the same", merge, clone); assertNotSame("Merged and cloned objects are the same", merge, clone);

View File

@ -73,7 +73,7 @@ public final class TestNoteRecord extends TestCase {
record.setShapeId((short)1026); record.setShapeId((short)1026);
record.setAuthor("Apache Software Foundation"); record.setAuthor("Apache Software Foundation");
NoteRecord cloned = (NoteRecord)record.clone(); NoteRecord cloned = record.clone();
assertEquals(record.getRow(), cloned.getRow()); assertEquals(record.getRow(), cloned.getRow());
assertEquals(record.getColumn(), cloned.getColumn()); assertEquals(record.getColumn(), cloned.getColumn());
assertEquals(record.getFlags(), cloned.getFlags()); assertEquals(record.getFlags(), cloned.getFlags());

View File

@ -58,7 +58,7 @@ public final class TestNoteStructureSubRecord extends TestCase {
NoteStructureSubRecord record = new NoteStructureSubRecord(); NoteStructureSubRecord record = new NoteStructureSubRecord();
byte[] src = record.serialize(); byte[] src = record.serialize();
NoteStructureSubRecord cloned = (NoteStructureSubRecord)record.clone(); NoteStructureSubRecord cloned = record.clone();
byte[] cln = cloned.serialize(); byte[] cln = cloned.serialize();
assertEquals(record.getDataSize(), cloned.getDataSize()); assertEquals(record.getDataSize(), cloned.getDataSize());

View File

@ -159,10 +159,7 @@ public final class TestDocument extends TestCase {
} }
else else
{ {
copy = new OPOIFSDocument( copy = new OPOIFSDocument("test"+input.length, document.getSmallBlocks(), input.length);
"test" + input.length,
( SmallDocumentBlock [] ) document.getSmallBlocks(),
input.length);
} }
return copy; return copy;
} }

View File

@ -20,8 +20,6 @@
*/ */
package org.apache.poi.ss.formula.functions; package org.apache.poi.ss.formula.functions;
import java.lang.reflect.Constructor;
import org.apache.poi.ss.formula.functions.XYNumericFunction.Accumulator; import org.apache.poi.ss.formula.functions.XYNumericFunction.Accumulator;
@ -305,10 +303,10 @@ public class TestMathX extends AbstractNumericTestCase {
assertEquals(0.0, MathX.mod(0, 2)); assertEquals(0.0, MathX.mod(0, 2));
assertEquals(Double.NaN, MathX.mod(3, 0)); assertEquals(Double.NaN, MathX.mod(3, 0));
assertEquals((double) 1.4, MathX.mod(3.4, 2)); assertEquals(1.4, MathX.mod(3.4, 2));
assertEquals((double) -1.4, MathX.mod(-3.4, -2)); assertEquals(-1.4, MathX.mod(-3.4, -2));
assertEquals((double) 0.6000000000000001, MathX.mod(-3.4, 2.0));// should actually be 0.6 assertEquals(0.6000000000000001, MathX.mod(-3.4, 2.0));// should actually be 0.6
assertEquals((double) -0.6000000000000001, MathX.mod(3.4, -2.0));// should actually be -0.6 assertEquals(-0.6000000000000001, MathX.mod(3.4, -2.0));// should actually be -0.6
assertEquals(3.0, MathX.mod(3, Double.MAX_VALUE)); assertEquals(3.0, MathX.mod(3, Double.MAX_VALUE));
assertEquals(2.0, MathX.mod(Double.MAX_VALUE, 3)); assertEquals(2.0, MathX.mod(Double.MAX_VALUE, 3));