diff options
Diffstat (limited to 'src/testcases')
12 files changed, 991 insertions, 1126 deletions
diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java b/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java index 8d94d2df6e..63bde0c2de 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestMetaDataIPI.java @@ -43,117 +43,80 @@ import org.apache.poi.poifs.filesystem.POIFSFileSystem; /** * Basing on: src/examples/src/org/apache/poi/hpsf/examples/ModifyDocumentSummaryInformation.java * This class tests reading and writing of meta data. No actual document is created. All information - * is stored in a virtal document in a ByteArrayOutputStream + * is stored in a virtual document in a ByteArrayOutputStream * @author Matthias G\u00fcnter */ -public class TestMetaDataIPI extends TestCase{ - - private ByteArrayOutputStream bout= null; //our store - private POIFSFileSystem poifs=null; - DirectoryEntry dir = null; - DocumentSummaryInformation dsi=null; - SummaryInformation si=null; - - - - /** - * Setup is used to get the document ready. Gets the DocumentSummaryInformation and the - * SummaryInformation to reasonable values - */ - public void setUp(){ - bout=new ByteArrayOutputStream(); - poifs= new POIFSFileSystem(); - dir = poifs.getRoot(); - dsi=null; - try - { - DocumentEntry dsiEntry = (DocumentEntry) - dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - DocumentInputStream dis = new DocumentInputStream(dsiEntry); - PropertySet ps = new PropertySet(dis); - dis.close(); - dsi = new DocumentSummaryInformation(ps); - - - } - catch (FileNotFoundException ex) - { - /* There is no document summary information yet. We have to create a - * new one. */ - dsi = PropertySetFactory.newDocumentSummaryInformation(); - assertNotNull(dsi); - } catch (IOException e) { - e.printStackTrace(); - fail(); - } catch (NoPropertySetStreamException e) { - e.printStackTrace(); - fail(); - } catch (MarkUnsupportedException e) { - e.printStackTrace(); - fail(); - } catch (UnexpectedPropertySetTypeException e) { - e.printStackTrace(); - fail(); - } - assertNotNull(dsi); - try - { - DocumentEntry dsiEntry = (DocumentEntry) - dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); - DocumentInputStream dis = new DocumentInputStream(dsiEntry); - PropertySet ps = new PropertySet(dis); - dis.close(); - si = new SummaryInformation(ps); - - - } - catch (FileNotFoundException ex) - { - /* There is no document summary information yet. We have to create a - * new one. */ - si = PropertySetFactory.newSummaryInformation(); - assertNotNull(si); - } catch (IOException e) { - e.printStackTrace(); - fail(); - } catch (NoPropertySetStreamException e) { - e.printStackTrace(); - fail(); - } catch (MarkUnsupportedException e) { - e.printStackTrace(); - fail(); - } catch (UnexpectedPropertySetTypeException e) { - e.printStackTrace(); - fail(); +public final class TestMetaDataIPI extends TestCase{ + + private ByteArrayOutputStream bout; //our store + private POIFSFileSystem poifs; + private DirectoryEntry dir; + private DocumentSummaryInformation dsi; + private SummaryInformation si; + + + + /** + * Setup is used to get the document ready. Gets the DocumentSummaryInformation and the + * SummaryInformation to reasonable values + */ + public void setUp() { + bout = new ByteArrayOutputStream(); + poifs = new POIFSFileSystem(); + dir = poifs.getRoot(); + dsi = null; + try { + DocumentEntry dsiEntry = (DocumentEntry) dir + .getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); + DocumentInputStream dis = new DocumentInputStream(dsiEntry); + PropertySet ps = new PropertySet(dis); + dis.close(); + dsi = new DocumentSummaryInformation(ps); + + } catch (FileNotFoundException ex) { + /* + * There is no document summary information yet. We have to create a + * new one. + */ + dsi = PropertySetFactory.newDocumentSummaryInformation(); + assertNotNull(dsi); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + assertNotNull(dsi); + try { + DocumentEntry dsiEntry = (DocumentEntry) dir + .getEntry(SummaryInformation.DEFAULT_STREAM_NAME); + DocumentInputStream dis = new DocumentInputStream(dsiEntry); + PropertySet ps = new PropertySet(dis); + dis.close(); + si = new SummaryInformation(ps); + + } catch (FileNotFoundException ex) { + /* + * There is no document summary information yet. We have to create a + * new one. + */ + si = PropertySetFactory.newSummaryInformation(); + assertNotNull(si); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + assertNotNull(dsi); } - assertNotNull(dsi); - - - } - - /** - * Setting a lot of things to null. - */ - public void tearDown(){ - bout=null; - poifs=null; - dir=null; - dsi=null; - - } - - - /** - * Closes the ByteArrayOutputStream and reads it into a ByteArrayInputStream. - * When finished writing information this method is used in the tests to - * start reading from the created document and then the see if the results match. - * - */ - public void closeAndReOpen(){ - - try { + + /** + * Closes the ByteArrayOutputStream and reads it into a ByteArrayInputStream. + * When finished writing information this method is used in the tests to + * start reading from the created document and then the see if the results match. + */ + public void closeAndReOpen() { + + try { dsi.write(dir, DocumentSummaryInformation.DEFAULT_STREAM_NAME); - si.write(dir,SummaryInformation.DEFAULT_STREAM_NAME); + si.write(dir, SummaryInformation.DEFAULT_STREAM_NAME); } catch (WritingNotSupportedException e) { e.printStackTrace(); fail(); @@ -162,659 +125,592 @@ public class TestMetaDataIPI extends TestCase{ fail(); } - si=null; - dsi=null; + si = null; + dsi = null; try { - poifs.writeFilesystem(bout); bout.flush(); - } catch (IOException e) { - e.printStackTrace(); fail(); } - - InputStream is=new ByteArrayInputStream(bout.toByteArray()); - assertNotNull(is); - POIFSFileSystem poifs=null; + + InputStream is = new ByteArrayInputStream(bout.toByteArray()); + assertNotNull(is); + POIFSFileSystem poifs = null; try { poifs = new POIFSFileSystem(is); } catch (IOException e) { - e.printStackTrace(); fail(); } - try { + try { is.close(); } catch (IOException e) { e.printStackTrace(); fail(); } - assertNotNull(poifs); - /* Read the document summary information. */ - DirectoryEntry dir = poifs.getRoot(); - - try - { - DocumentEntry dsiEntry = (DocumentEntry) - dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - DocumentInputStream dis = new DocumentInputStream(dsiEntry); - PropertySet ps = new PropertySet(dis); - dis.close(); - dsi = new DocumentSummaryInformation(ps); - } - catch (FileNotFoundException ex) - { - fail(); - } catch (IOException e) { - e.printStackTrace(); + assertNotNull(poifs); + /* Read the document summary information. */ + DirectoryEntry dir = poifs.getRoot(); + + try { + DocumentEntry dsiEntry = (DocumentEntry) dir + .getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); + DocumentInputStream dis = new DocumentInputStream(dsiEntry); + PropertySet ps = new PropertySet(dis); + dis.close(); + dsi = new DocumentSummaryInformation(ps); + } catch (FileNotFoundException ex) { fail(); - } catch (NoPropertySetStreamException e) { + } catch (Exception e) { e.printStackTrace(); fail(); - } catch (MarkUnsupportedException e) { + } + try { + DocumentEntry dsiEntry = (DocumentEntry) dir + .getEntry(SummaryInformation.DEFAULT_STREAM_NAME); + DocumentInputStream dis = new DocumentInputStream(dsiEntry); + PropertySet ps = new PropertySet(dis); + dis.close(); + si = new SummaryInformation(ps); + + } catch (FileNotFoundException ex) { + /* + * There is no document summary information yet. We have to create a + * new one. + */ + si = PropertySetFactory.newSummaryInformation(); + assertNotNull(si); + } catch (Exception e) { e.printStackTrace(); fail(); - } catch (UnexpectedPropertySetTypeException e) { - e.printStackTrace(); + } + } + + /** + * Sets the most important information in DocumentSummaryInformation and Summary Information and rereads it + */ + public void testOne() { + + // DocumentSummaryInformation + dsi.setCompany("xxxCompanyxxx"); + dsi.setManager("xxxManagerxxx"); + dsi.setCategory("xxxCategoryxxx"); + + // SummaryInformation + si.setTitle("xxxTitlexxx"); + si.setAuthor("xxxAuthorxxx"); + si.setComments("xxxCommentsxxx"); + si.setKeywords("xxxKeyWordsxxx"); + si.setSubject("xxxSubjectxxx"); + + // Custom Properties (in DocumentSummaryInformation + CustomProperties customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + customProperties = new CustomProperties(); + } + + /* Insert some custom properties into the container. */ + customProperties.put("Key1", "Value1"); + customProperties.put("Schl\u00fcssel2", "Wert2"); + customProperties.put("Sample Integer", new Integer(12345)); + customProperties.put("Sample Boolean", Boolean.TRUE); + Date date = new Date(); + customProperties.put("Sample Date", date); + customProperties.put("Sample Double", new Double(-1.0001)); + customProperties.put("Sample Negative Integer", new Integer(-100000)); + + dsi.setCustomProperties(customProperties); + + // start reading + closeAndReOpen(); + + // testing + assertNotNull(dsi); + assertNotNull(si); + + assertEquals("Category", "xxxCategoryxxx", dsi.getCategory()); + assertEquals("Company", "xxxCompanyxxx", dsi.getCompany()); + assertEquals("Manager", "xxxManagerxxx", dsi.getManager()); + + assertEquals("", "xxxAuthorxxx", si.getAuthor()); + assertEquals("", "xxxTitlexxx", si.getTitle()); + assertEquals("", "xxxCommentsxxx", si.getComments()); + assertEquals("", "xxxKeyWordsxxx", si.getKeywords()); + assertEquals("", "xxxSubjectxxx", si.getSubject()); + + /* + * Read the custom properties. If there are no custom properties yet, + * the application has to create a new CustomProperties object. It will + * serve as a container for custom properties. + */ + customProperties = dsi.getCustomProperties(); + if (customProperties == null) { fail(); } - try - { - DocumentEntry dsiEntry = (DocumentEntry) - dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); - DocumentInputStream dis = new DocumentInputStream(dsiEntry); - PropertySet ps = new PropertySet(dis); - dis.close(); - si = new SummaryInformation(ps); - - - } - catch (FileNotFoundException ex) - { - /* There is no document summary information yet. We have to create a - * new one. */ - si = PropertySetFactory.newSummaryInformation(); - assertNotNull(si); - } catch (IOException e) { - e.printStackTrace(); - fail(); - } catch (NoPropertySetStreamException e) { - e.printStackTrace(); - fail(); - } catch (MarkUnsupportedException e) { - e.printStackTrace(); - fail(); - } catch (UnexpectedPropertySetTypeException e) { - e.printStackTrace(); - fail(); - } - } - - /** - * Sets the most important information in DocumentSummaryInformation and Summary Information and rereads it - * - */ - public void testOne(){ - - //DocumentSummaryInformation - dsi.setCompany("xxxCompanyxxx"); - dsi.setManager("xxxManagerxxx"); - dsi.setCategory("xxxCategoryxxx"); - - //SummaryInformation - si.setTitle("xxxTitlexxx"); - si.setAuthor("xxxAuthorxxx"); - si.setComments("xxxCommentsxxx"); - si.setKeywords("xxxKeyWordsxxx"); - si.setSubject("xxxSubjectxxx"); - - //Custom Properties (in DocumentSummaryInformation - CustomProperties customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - customProperties = new CustomProperties(); - } - - /* Insert some custom properties into the container. */ - customProperties.put("Key1", "Value1"); - customProperties.put("Schl\u00fcssel2", "Wert2"); - customProperties.put("Sample Integer", new Integer(12345)); - customProperties.put("Sample Boolean", new Boolean(true)); - Date date=new Date(); - customProperties.put("Sample Date", date); - customProperties.put("Sample Double", new Double(-1.0001)); - customProperties.put("Sample Negative Integer", new Integer(-100000)); - - dsi.setCustomProperties(customProperties); - - //start reading - closeAndReOpen(); - - //testing - assertNotNull(dsi); - assertNotNull(si); - - assertEquals("Category","xxxCategoryxxx",dsi.getCategory()); - assertEquals("Company","xxxCompanyxxx",dsi.getCompany()); - assertEquals("Manager","xxxManagerxxx",dsi.getManager()); - - assertEquals("","xxxAuthorxxx",si.getAuthor()); - assertEquals("","xxxTitlexxx",si.getTitle()); - assertEquals("","xxxCommentsxxx",si.getComments()); - assertEquals("","xxxKeyWordsxxx",si.getKeywords()); - assertEquals("","xxxSubjectxxx",si.getSubject()); - - - /* Read the custom properties. If there are no custom properties yet, - * the application has to create a new CustomProperties object. It will - * serve as a container for custom properties. */ - customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - fail(); - } - - /* Insert some custom properties into the container. */ - String a1=(String) customProperties.get("Key1"); - assertEquals("Key1","Value1",a1); - String a2=(String) customProperties.get("Schl\u00fcssel2"); - assertEquals("Schl\u00fcssel2","Wert2",a2); - Integer a3=(Integer) customProperties.get("Sample Integer"); - assertEquals("Sample Number",new Integer(12345),a3); - Boolean a4=(Boolean) customProperties.get("Sample Boolean"); - assertEquals("Sample Boolean",new Boolean(true),a4); - Date a5=(Date) customProperties.get("Sample Date"); - assertEquals("Custom Date:",date,a5); - - Double a6=(Double) customProperties.get("Sample Double"); - assertEquals("Custom Float",new Double(-1.0001),a6); - - Integer a7=(Integer) customProperties.get("Sample Negative Integer"); - assertEquals("Neg", new Integer(-100000),a7); - } - - - /** - * multiplies a string - * @param s Input String - * @return the multiplied String - */ - public String elongate(String s){ - StringBuffer sb=new StringBuffer(); - for (int i=0;i<10000;i++){ - sb.append(s); - sb.append(" "); - } - return sb.toString(); - } - - - - /** - * Test very long input in each of the fields (approx 30-60KB each) - * - */ -public void testTwo(){ - - String company=elongate("company"); - String manager=elongate("manager"); - String category=elongate("category"); - String title=elongate("title"); - String author=elongate("author"); - String comments=elongate("comments"); - String keywords=elongate("keywords"); - String subject=elongate("subject"); - String p1=elongate("p1"); - String p2=elongate("p2"); - String k1=elongate("k1"); - String k2=elongate("k2"); - - dsi.setCompany(company); - dsi.setManager(manager); - dsi.setCategory(category); - - si.setTitle(title); - si.setAuthor(author); - si.setComments(comments); - si.setKeywords(keywords); - si.setSubject(subject); - CustomProperties customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - customProperties = new CustomProperties(); - } - - /* Insert some custom properties into the container. */ - customProperties.put(k1, p1); - customProperties.put(k2, p2); - customProperties.put("Sample Number", new Integer(12345)); - customProperties.put("Sample Boolean", new Boolean(true)); - Date date=new Date(); - customProperties.put("Sample Date", date); - - dsi.setCustomProperties(customProperties); - - - closeAndReOpen(); - - assertNotNull(dsi); - assertNotNull(si); - /* Change the category to "POI example". Any former category value will - * be lost. If there has been no category yet, it will be created. */ - assertEquals("Category",category,dsi.getCategory()); - assertEquals("Company",company,dsi.getCompany()); - assertEquals("Manager",manager,dsi.getManager()); - - assertEquals("",author,si.getAuthor()); - assertEquals("",title,si.getTitle()); - assertEquals("",comments,si.getComments()); - assertEquals("",keywords,si.getKeywords()); - assertEquals("",subject,si.getSubject()); - - - /* Read the custom properties. If there are no custom properties - * yet, the application has to create a new CustomProperties object. - * It will serve as a container for custom properties. */ - customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - fail(); - } - - /* Insert some custom properties into the container. */ - String a1=(String) customProperties.get(k1); - assertEquals("Key1",p1,a1); - String a2=(String) customProperties.get(k2); - assertEquals("Schl\u00fcssel2",p2,a2); - Integer a3=(Integer) customProperties.get("Sample Number"); - assertEquals("Sample Number",new Integer(12345),a3); - Boolean a4=(Boolean) customProperties.get("Sample Boolean"); - assertEquals("Sample Boolean",new Boolean(true),a4); - Date a5=(Date) customProperties.get("Sample Date"); - assertEquals("Custom Date:",date,a5); + /* Insert some custom properties into the container. */ + String a1 = (String) customProperties.get("Key1"); + assertEquals("Key1", "Value1", a1); + String a2 = (String) customProperties.get("Schl\u00fcssel2"); + assertEquals("Schl\u00fcssel2", "Wert2", a2); + Integer a3 = (Integer) customProperties.get("Sample Integer"); + assertEquals("Sample Number", new Integer(12345), a3); + Boolean a4 = (Boolean) customProperties.get("Sample Boolean"); + assertEquals("Sample Boolean", Boolean.TRUE, a4); + Date a5 = (Date) customProperties.get("Sample Date"); + assertEquals("Custom Date:", date, a5); + + Double a6 = (Double) customProperties.get("Sample Double"); + assertEquals("Custom Float", new Double(-1.0001), a6); + + Integer a7 = (Integer) customProperties.get("Sample Negative Integer"); + assertEquals("Neg", new Integer(-100000), a7); + } + /** + * multiplies a string + * @param s Input String + * @return the multiplied String + */ + private static String elongate(String s) { + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < 10000; i++) { + sb.append(s); + sb.append(" "); + } + return sb.toString(); } - -/** - * adds strange characters to the string - * @param s Input String - * @return the multiplied String - */ -public String strangize(String s){ - StringBuffer sb=new StringBuffer(); - String[] umlaute= {"\u00e4","\u00fc","\u00f6","\u00dc","$","\u00d6","\u00dc","\u00c9","\u00d6","@","\u00e7","&"}; - char j=0; - Random rand=new Random(); - for (int i=0;i<5;i++){ - sb.append(s); - sb.append(" "); - j=(char) rand.nextInt(220); - j+=33; - // System.out.println(j); - sb.append(">"); - sb.append(new Character(j)); - sb.append("="); - sb.append(umlaute[rand.nextInt(umlaute.length)]); - sb.append("<"); - } - - return sb.toString(); -} + /** + * Test very long input in each of the fields (approx 30-60KB each) + */ + public void testTwo() { + + String company = elongate("company"); + String manager = elongate("manager"); + String category = elongate("category"); + String title = elongate("title"); + String author = elongate("author"); + String comments = elongate("comments"); + String keywords = elongate("keywords"); + String subject = elongate("subject"); + String p1 = elongate("p1"); + String p2 = elongate("p2"); + String k1 = elongate("k1"); + String k2 = elongate("k2"); + + dsi.setCompany(company); + dsi.setManager(manager); + dsi.setCategory(category); + + si.setTitle(title); + si.setAuthor(author); + si.setComments(comments); + si.setKeywords(keywords); + si.setSubject(subject); + CustomProperties customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + customProperties = new CustomProperties(); + } + /* Insert some custom properties into the container. */ + customProperties.put(k1, p1); + customProperties.put(k2, p2); + customProperties.put("Sample Number", new Integer(12345)); + customProperties.put("Sample Boolean", Boolean.TRUE); + Date date = new Date(); + customProperties.put("Sample Date", date); + + dsi.setCustomProperties(customProperties); + + closeAndReOpen(); + + assertNotNull(dsi); + assertNotNull(si); + /* + * Change the category to "POI example". Any former category value will + * be lost. If there has been no category yet, it will be created. + */ + assertEquals("Category", category, dsi.getCategory()); + assertEquals("Company", company, dsi.getCompany()); + assertEquals("Manager", manager, dsi.getManager()); + + assertEquals("", author, si.getAuthor()); + assertEquals("", title, si.getTitle()); + assertEquals("", comments, si.getComments()); + assertEquals("", keywords, si.getKeywords()); + assertEquals("", subject, si.getSubject()); + + /* + * Read the custom properties. If there are no custom properties yet, + * the application has to create a new CustomProperties object. It will + * serve as a container for custom properties. + */ + customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + fail(); + } -/** - * Tests with strange characters in keys and data (Umlaute etc.) - * - */ -public void testThree(){ - - String company=strangize("company"); - String manager=strangize("manager"); - String category=strangize("category"); - String title=strangize("title"); - String author=strangize("author"); - String comments=strangize("comments"); - String keywords=strangize("keywords"); - String subject=strangize("subject"); - String p1=strangize("p1"); - String p2=strangize("p2"); - String k1=strangize("k1"); - String k2=strangize("k2"); - - dsi.setCompany(company); - dsi.setManager(manager); - dsi.setCategory(category); - - si.setTitle(title); - si.setAuthor(author); - si.setComments(comments); - si.setKeywords(keywords); - si.setSubject(subject); - CustomProperties customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - customProperties = new CustomProperties(); - } - - /* Insert some custom properties into the container. */ - customProperties.put(k1, p1); - customProperties.put(k2, p2); - customProperties.put("Sample Number", new Integer(12345)); - customProperties.put("Sample Boolean", new Boolean(false)); - Date date=new Date(0); - customProperties.put("Sample Date", date); - - dsi.setCustomProperties(customProperties); - - - closeAndReOpen(); - - assertNotNull(dsi); - assertNotNull(si); - /* Change the category to "POI example". Any former category value will - * be lost. If there has been no category yet, it will be created. */ - assertEquals("Category",category,dsi.getCategory()); - assertEquals("Company",company,dsi.getCompany()); - assertEquals("Manager",manager,dsi.getManager()); - - assertEquals("",author,si.getAuthor()); - assertEquals("",title,si.getTitle()); - assertEquals("",comments,si.getComments()); - assertEquals("",keywords,si.getKeywords()); - assertEquals("",subject,si.getSubject()); - - - /* Read the custom properties. If there are no custom properties yet, - * the application has to create a new CustomProperties object. It will - * serve as a container for custom properties. */ - customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - fail(); - } - - /* Insert some custom properties into the container. */ - // System.out.println(k1); - String a1=(String) customProperties.get(k1); - assertEquals("Key1",p1,a1); - String a2=(String) customProperties.get(k2); - assertEquals("Schl\u00fcssel2",p2,a2); - Integer a3=(Integer) customProperties.get("Sample Number"); - assertEquals("Sample Number",new Integer(12345),a3); - Boolean a4=(Boolean) customProperties.get("Sample Boolean"); - assertEquals("Sample Boolean",new Boolean(false),a4); - Date a5=(Date) customProperties.get("Sample Date"); - assertEquals("Custom Date:",date,a5); - + /* Insert some custom properties into the container. */ + String a1 = (String) customProperties.get(k1); + assertEquals("Key1", p1, a1); + String a2 = (String) customProperties.get(k2); + assertEquals("Schl\u00fcssel2", p2, a2); + Integer a3 = (Integer) customProperties.get("Sample Number"); + assertEquals("Sample Number", new Integer(12345), a3); + Boolean a4 = (Boolean) customProperties.get("Sample Boolean"); + assertEquals("Sample Boolean", Boolean.TRUE, a4); + Date a5 = (Date) customProperties.get("Sample Date"); + assertEquals("Custom Date:", date, a5); } - - /** - * Iterative testing: writing, reading etc. - * - */ - public void testFour(){ - for (int i=1;i<100;i++){ - setUp(); - testThree(); - tearDown(); - } - } - - - /** - * adds strange characters to the string with the adding of unicode characters - * @param s Input String - * @return the multiplied String - */ - public String strangizeU(String s){ - - StringBuffer sb=new StringBuffer(); - String[] umlaute= {"\u00e4","\u00fc","\u00f6","\u00dc","$","\u00d6","\u00dc","\u00c9","\u00d6","@","\u00e7","&"}; - char j=0; - Random rand=new Random(); - for (int i=0;i<5;i++){ - sb.append(s); - sb.append(" "); - j=(char) rand.nextInt(220); - j+=33; - // System.out.println(j); - sb.append(">"); - sb.append(new Character(j)); - sb.append("="); - sb.append(umlaute[rand.nextInt(umlaute.length)]); - sb.append("<"); - } - sb.append("\u00e4\u00f6\u00fc\uD840\uDC00"); - return sb.toString(); - } - /** - * Unicode test - * - */ - public void testUnicode(){ - String company=strangizeU("company"); - String manager=strangizeU("manager"); - String category=strangizeU("category"); - String title=strangizeU("title"); - String author=strangizeU("author"); - String comments=strangizeU("comments"); - String keywords=strangizeU("keywords"); - String subject=strangizeU("subject"); - String p1=strangizeU("p1"); - String p2=strangizeU("p2"); - String k1=strangizeU("k1"); - String k2=strangizeU("k2"); - - dsi.setCompany(company); - dsi.setManager(manager); - dsi.setCategory(category); - - si.setTitle(title); - si.setAuthor(author); - si.setComments(comments); - si.setKeywords(keywords); - si.setSubject(subject); - CustomProperties customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - customProperties = new CustomProperties(); - } - - /* Insert some custom properties into the container. */ - customProperties.put(k1, p1); - customProperties.put(k2, p2); - customProperties.put("Sample Number", new Integer(12345)); - customProperties.put("Sample Boolean", new Boolean(true)); - Date date=new Date(); - customProperties.put("Sample Date", date); - - dsi.setCustomProperties(customProperties); - - - closeAndReOpen(); - - assertNotNull(dsi); - assertNotNull(si); - /* Change the category to "POI example". Any former category value will - * be lost. If there has been no category yet, it will be created. */ - assertEquals("Category",category,dsi.getCategory()); - assertEquals("Company",company,dsi.getCompany()); - assertEquals("Manager",manager,dsi.getManager()); - - assertEquals("",author,si.getAuthor()); - assertEquals("",title,si.getTitle()); - assertEquals("",comments,si.getComments()); - assertEquals("",keywords,si.getKeywords()); - assertEquals("",subject,si.getSubject()); - - - /* Read the custom properties. If there are no custom properties yet, - * the application has to create a new CustomProperties object. It will - * serve as a container for custom properties. */ - customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - fail(); - } - - /* Insert some custom properties into the container. */ - // System.out.println(k1); - String a1=(String) customProperties.get(k1); - assertEquals("Key1",p1,a1); - String a2=(String) customProperties.get(k2); - assertEquals("Schl\u00fcssel2",p2,a2); - Integer a3=(Integer) customProperties.get("Sample Number"); - assertEquals("Sample Number",new Integer(12345),a3); - Boolean a4=(Boolean) customProperties.get("Sample Boolean"); - assertEquals("Sample Boolean",new Boolean(true),a4); - Date a5=(Date) customProperties.get("Sample Date"); - assertEquals("Custom Date:",date,a5); - - - - } - - - /** - * Iterative testing of the unicode test - * + + /** + * adds strange characters to the string + * @param s Input String + * @return the multiplied String + */ + private static String strangize(String s) { + StringBuffer sb = new StringBuffer(); + String[] umlaute = { "\u00e4", "\u00fc", "\u00f6", "\u00dc", "$", "\u00d6", "\u00dc", + "\u00c9", "\u00d6", "@", "\u00e7", "&" }; + char j = 0; + Random rand = new Random(0); // TODO - no Random - tests should be completely deterministic + for (int i = 0; i < 5; i++) { + sb.append(s); + sb.append(" "); + j = (char) rand.nextInt(220); + j += 33; + // System.out.println(j); + sb.append(">"); + sb.append(new Character(j)); + sb.append("="); + sb.append(umlaute[rand.nextInt(umlaute.length)]); + sb.append("<"); + } + + return sb.toString(); + } + + + /** + * Tests with strange characters in keys and data (Umlaute etc.) + */ + public void testThree() { + + String company = strangize("company"); + String manager = strangize("manager"); + String category = strangize("category"); + String title = strangize("title"); + String author = strangize("author"); + String comments = strangize("comments"); + String keywords = strangize("keywords"); + String subject = strangize("subject"); + String p1 = strangize("p1"); + String p2 = strangize("p2"); + String k1 = strangize("k1"); + String k2 = strangize("k2"); + + dsi.setCompany(company); + dsi.setManager(manager); + dsi.setCategory(category); + + si.setTitle(title); + si.setAuthor(author); + si.setComments(comments); + si.setKeywords(keywords); + si.setSubject(subject); + CustomProperties customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + customProperties = new CustomProperties(); + } + + /* Insert some custom properties into the container. */ + customProperties.put(k1, p1); + customProperties.put(k2, p2); + customProperties.put("Sample Number", new Integer(12345)); + customProperties.put("Sample Boolean", Boolean.FALSE); + Date date = new Date(0); + customProperties.put("Sample Date", date); + + dsi.setCustomProperties(customProperties); + + closeAndReOpen(); + + assertNotNull(dsi); + assertNotNull(si); + /* + * Change the category to "POI example". Any former category value will + * be lost. If there has been no category yet, it will be created. + */ + assertEquals("Category", category, dsi.getCategory()); + assertEquals("Company", company, dsi.getCompany()); + assertEquals("Manager", manager, dsi.getManager()); + + assertEquals("", author, si.getAuthor()); + assertEquals("", title, si.getTitle()); + assertEquals("", comments, si.getComments()); + assertEquals("", keywords, si.getKeywords()); + assertEquals("", subject, si.getSubject()); + + /* + * Read the custom properties. If there are no custom properties yet, + * the application has to create a new CustomProperties object. It will + * serve as a container for custom properties. + */ + customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + fail(); + } + + /* Insert some custom properties into the container. */ + // System.out.println(k1); + String a1 = (String) customProperties.get(k1); + assertEquals("Key1", p1, a1); + String a2 = (String) customProperties.get(k2); + assertEquals("Schl\u00fcssel2", p2, a2); + Integer a3 = (Integer) customProperties.get("Sample Number"); + assertEquals("Sample Number", new Integer(12345), a3); + Boolean a4 = (Boolean) customProperties.get("Sample Boolean"); + assertEquals("Sample Boolean", Boolean.FALSE, a4); + Date a5 = (Date) customProperties.get("Sample Date"); + assertEquals("Custom Date:", date, a5); + + } + + /** + * Iterative testing: writing, reading etc. + */ + public void testFour() { + for (int i = 1; i < 100; i++) { + setUp(); + testThree(); + } + } + + + + /** + * adds strange characters to the string with the adding of unicode characters + * @param s Input String + * @return the multiplied String */ - public void testSix(){ - for (int i=1;i<100;i++){ - setUp(); - testUnicode(); - tearDown(); - } - } - + private static String strangizeU(String s) { + + StringBuffer sb = new StringBuffer(); + String[] umlaute = { "\u00e4", "\u00fc", "\u00f6", "\u00dc", "$", "\u00d6", "\u00dc", + "\u00c9", "\u00d6", "@", "\u00e7", "&" }; + char j = 0; + Random rand = new Random(0); // TODO - no Random - tests should be completely deterministic + for (int i = 0; i < 5; i++) { + sb.append(s); + sb.append(" "); + j = (char) rand.nextInt(220); + j += 33; + // System.out.println(j); + sb.append(">"); + sb.append(new Character(j)); + sb.append("="); + sb.append(umlaute[rand.nextInt(umlaute.length)]); + sb.append("<"); + } + sb.append("\u00e4\u00f6\u00fc\uD840\uDC00"); + return sb.toString(); + } + + /** + * Unicode test + */ + public void testUnicode() { + String company = strangizeU("company"); + String manager = strangizeU("manager"); + String category = strangizeU("category"); + String title = strangizeU("title"); + String author = strangizeU("author"); + String comments = strangizeU("comments"); + String keywords = strangizeU("keywords"); + String subject = strangizeU("subject"); + String p1 = strangizeU("p1"); + String p2 = strangizeU("p2"); + String k1 = strangizeU("k1"); + String k2 = strangizeU("k2"); + + dsi.setCompany(company); + dsi.setManager(manager); + dsi.setCategory(category); + + si.setTitle(title); + si.setAuthor(author); + si.setComments(comments); + si.setKeywords(keywords); + si.setSubject(subject); + CustomProperties customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + customProperties = new CustomProperties(); + } + + /* Insert some custom properties into the container. */ + customProperties.put(k1, p1); + customProperties.put(k2, p2); + customProperties.put("Sample Number", new Integer(12345)); + customProperties.put("Sample Boolean", Boolean.TRUE); + Date date = new Date(); + customProperties.put("Sample Date", date); + + dsi.setCustomProperties(customProperties); + + closeAndReOpen(); + + assertNotNull(dsi); + assertNotNull(si); + /* + * Change the category to "POI example". Any former category value will + * be lost. If there has been no category yet, it will be created. + */ + assertEquals("Category", category, dsi.getCategory()); + assertEquals("Company", company, dsi.getCompany()); + assertEquals("Manager", manager, dsi.getManager()); + + assertEquals("", author, si.getAuthor()); + assertEquals("", title, si.getTitle()); + assertEquals("", comments, si.getComments()); + assertEquals("", keywords, si.getKeywords()); + assertEquals("", subject, si.getSubject()); + + /* + * Read the custom properties. If there are no custom properties yet, + * the application has to create a new CustomProperties object. It will + * serve as a container for custom properties. + */ + customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + fail(); + } + + /* Insert some custom properties into the container. */ + // System.out.println(k1); + String a1 = (String) customProperties.get(k1); + assertEquals("Key1", p1, a1); + String a2 = (String) customProperties.get(k2); + assertEquals("Schl\u00fcssel2", p2, a2); + Integer a3 = (Integer) customProperties.get("Sample Number"); + assertEquals("Sample Number", new Integer(12345), a3); + Boolean a4 = (Boolean) customProperties.get("Sample Boolean"); + assertEquals("Sample Boolean", Boolean.TRUE, a4); + Date a5 = (Date) customProperties.get("Sample Date"); + assertEquals("Custom Date:", date, a5); + } + /** - * Tests conversion in custom fields and errors - * - */ - public void testConvAndExistance(){ - - - CustomProperties customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - customProperties = new CustomProperties(); - } - - /* Insert some custom properties into the container. */ - customProperties.put("int", new Integer(12345)); - customProperties.put("negint", new Integer(-12345)); - customProperties.put("long", new Long(12345)); - customProperties.put("neglong", new Long(-12345)); - customProperties.put("boolean", new Boolean(true)); - customProperties.put("string", "a String"); - //customProperties.put("float", new Float(12345.0)); is not valid - //customProperties.put("negfloat", new Float(-12345.1)); is not valid - customProperties.put("double", new Double(12345.2)); - customProperties.put("negdouble", new Double(-12345.3)); - //customProperties.put("char", new Character('a')); is not valid - - Date date=new Date(); - customProperties.put("date", date); - - dsi.setCustomProperties(customProperties); - - - closeAndReOpen(); - - assertNotNull(dsi); - assertNotNull(si); - /* Change the category to "POI example". Any former category value will - * be lost. If there has been no category yet, it will be created. */ - assertNull(dsi.getCategory()); - assertNull(dsi.getCompany()); - assertNull(dsi.getManager()); - - assertNull(si.getAuthor()); - assertNull(si.getTitle()); - assertNull(si.getComments()); - assertNull(si.getKeywords()); - assertNull(si.getSubject()); - - - /* Read the custom properties. If there are no custom properties - * yet, the application has to create a new CustomProperties object. - * It will serve as a container for custom properties. */ - customProperties = dsi.getCustomProperties(); - if (customProperties == null){ - fail(); - } - - /* Insert some custom properties into the container. */ - - Integer a3=(Integer) customProperties.get("int"); - assertEquals("int",new Integer(12345),a3); - - a3=(Integer) customProperties.get("negint"); - assertEquals("negint",new Integer(-12345),a3); - - Long al=(Long) customProperties.get("neglong"); - assertEquals("neglong",new Long(-12345),al); - - al=(Long) customProperties.get("long"); - assertEquals("long",new Long(12345),al); - - Boolean a4=(Boolean) customProperties.get("boolean"); - assertEquals("boolean",new Boolean(true),a4); - - Date a5=(Date) customProperties.get("date"); - assertEquals("Custom Date:",date,a5); - - Double d=(Double) customProperties.get("double"); - assertEquals("int",new Double(12345.2),d); - - d=(Double) customProperties.get("negdouble"); - assertEquals("string",new Double(-12345.3),d); - - String s=(String) customProperties.get("string"); - assertEquals("sring","a String",s); - - Object o=null; - - o=customProperties.get("string"); - if (!(o instanceof String)){ - fail(); - } - o=customProperties.get("boolean"); - if (!(o instanceof Boolean)){ - fail(); - } - - o=customProperties.get("int"); - if (!(o instanceof Integer)){ - fail(); - } - o=customProperties.get("negint"); - if (!(o instanceof Integer)){ - fail(); - } - - o=customProperties.get("long"); - if (!(o instanceof Long)){ - fail(); - } - o=customProperties.get("neglong"); - if (!(o instanceof Long)){ - fail(); - } - - o=customProperties.get("double"); - if (!(o instanceof Double)){ - fail(); - } - o=customProperties.get("negdouble"); - if (!(o instanceof Double)){ - fail(); - } - - o=customProperties.get("date"); - if (!(o instanceof Date)){ - fail(); - } - } - - - -}
\ No newline at end of file + * Iterative testing of the unicode test + * + */ + public void testSix() { + for (int i = 1; i < 100; i++) { + setUp(); + testUnicode(); + } + } + + + /** + * Tests conversion in custom fields and errors + */ + public void testConvAndExistence() { + + CustomProperties customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + customProperties = new CustomProperties(); + } + + /* Insert some custom properties into the container. */ + customProperties.put("int", new Integer(12345)); + customProperties.put("negint", new Integer(-12345)); + customProperties.put("long", new Long(12345)); + customProperties.put("neglong", new Long(-12345)); + customProperties.put("boolean", Boolean.TRUE); + customProperties.put("string", "a String"); + // customProperties.put("float", new Float(12345.0)); is not valid + // customProperties.put("negfloat", new Float(-12345.1)); is not valid + customProperties.put("double", new Double(12345.2)); + customProperties.put("negdouble", new Double(-12345.3)); + // customProperties.put("char", new Character('a')); is not valid + + Date date = new Date(); + customProperties.put("date", date); + + dsi.setCustomProperties(customProperties); + + closeAndReOpen(); + + assertNotNull(dsi); + assertNotNull(si); + /* + * Change the category to "POI example". Any former category value will + * be lost. If there has been no category yet, it will be created. + */ + assertNull(dsi.getCategory()); + assertNull(dsi.getCompany()); + assertNull(dsi.getManager()); + + assertNull(si.getAuthor()); + assertNull(si.getTitle()); + assertNull(si.getComments()); + assertNull(si.getKeywords()); + assertNull(si.getSubject()); + + /* + * Read the custom properties. If there are no custom properties yet, + * the application has to create a new CustomProperties object. It will + * serve as a container for custom properties. + */ + customProperties = dsi.getCustomProperties(); + if (customProperties == null) { + fail(); + } + + /* Insert some custom properties into the container. */ + + Integer a3 = (Integer) customProperties.get("int"); + assertEquals("int", new Integer(12345), a3); + + a3 = (Integer) customProperties.get("negint"); + assertEquals("negint", new Integer(-12345), a3); + + Long al = (Long) customProperties.get("neglong"); + assertEquals("neglong", new Long(-12345), al); + + al = (Long) customProperties.get("long"); + assertEquals("long", new Long(12345), al); + + Boolean a4 = (Boolean) customProperties.get("boolean"); + assertEquals("boolean", Boolean.TRUE, a4); + + Date a5 = (Date) customProperties.get("date"); + assertEquals("Custom Date:", date, a5); + + Double d = (Double) customProperties.get("double"); + assertEquals("int", new Double(12345.2), d); + + d = (Double) customProperties.get("negdouble"); + assertEquals("string", new Double(-12345.3), d); + + String s = (String) customProperties.get("string"); + assertEquals("sring", "a String", s); + + + assertTrue(customProperties.get("string") instanceof String); + assertTrue(customProperties.get("boolean") instanceof Boolean); + assertTrue(customProperties.get("int") instanceof Integer); + assertTrue(customProperties.get("negint") instanceof Integer); + assertTrue(customProperties.get("long") instanceof Long); + assertTrue(customProperties.get("neglong") instanceof Long); + assertTrue(customProperties.get("double") instanceof Double); + assertTrue(customProperties.get("negdouble") instanceof Double); + assertTrue(customProperties.get("date") instanceof Date); + } +} diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java b/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java index 581ff14381..cdd74f79fc 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestUnicode.java @@ -53,7 +53,7 @@ public class TestUnicode extends TestCase { /** * <p>Read a the test file from the "data" directory.</p> - * + * * @exception FileNotFoundException if the file to be read does not exist. * @exception IOException if any other I/O exception occurs */ @@ -68,7 +68,7 @@ public class TestUnicode extends TestCase { * <p>Tests the {@link PropertySet} methods. The test file has two * property set: the first one is a {@link SummaryInformation}, * the second one is a {@link DocumentSummaryInformation}.</p> - * + * * @exception IOException if an I/O exception occurs * @exception HPSFException if an HPSF exception occurs */ @@ -82,9 +82,9 @@ public class TestUnicode extends TestCase { Assert.assertEquals(ps.getSectionCount(), 2); Section s = (Section) ps.getSections().get(1); Assert.assertEquals(s.getProperty(1), - new Integer(Constants.CP_UTF16)); + Integer.valueOf(Constants.CP_UTF16)); Assert.assertEquals(s.getProperty(2), - new Integer(-96070278)); + Integer.valueOf(-96070278)); Assert.assertEquals(s.getProperty(3), "MCon_Info zu Office bei Schreiner"); Assert.assertEquals(s.getProperty(4), diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java index f824ffb7bc..eabda72d5b 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestWrite.java @@ -107,7 +107,7 @@ public class TestWrite extends TestCase /** * <p>Writes an empty property set to a POIFS and reads it back * in.</p> - * + * * @exception IOException if an I/O exception occurs */ public void testNoFormatID() throws IOException @@ -150,7 +150,7 @@ public class TestWrite extends TestCase /** * <p>Writes an empty property set to a POIFS and reads it back * in.</p> - * + * * @exception IOException if an I/O exception occurs * @exception UnsupportedVariantTypeException if HPSF does not yet support * a variant type to be written @@ -190,7 +190,7 @@ public class TestWrite extends TestCase /** * <p>Writes a simple property set with a SummaryInformation section to a * POIFS and reads it back in.</p> - * + * * @exception IOException if an I/O exception occurs * @exception UnsupportedVariantTypeException if HPSF does not yet support * a variant type to be written @@ -199,30 +199,30 @@ public class TestWrite extends TestCase throws IOException, UnsupportedVariantTypeException { final String AUTHOR = "Rainer Klute"; - final String TITLE = "Test Document"; + final String TITLE = "Test Document"; final File dataDir = _samples.getFile(""); final File filename = new File(dataDir, POI_FS); filename.deleteOnExit(); final OutputStream out = new FileOutputStream(filename); final POIFSFileSystem poiFs = new POIFSFileSystem(); - + final MutablePropertySet ps = new MutablePropertySet(); final MutableSection si = new MutableSection(); si.setFormatID(SectionIDMap.SUMMARY_INFORMATION_ID); ps.getSections().set(0, si); - + final MutableProperty p = new MutableProperty(); p.setID(PropertyIDMap.PID_AUTHOR); p.setType(Variant.VT_LPWSTR); p.setValue(AUTHOR); si.setProperty(p); si.setProperty(PropertyIDMap.PID_TITLE, Variant.VT_LPSTR, TITLE); - + poiFs.createDocument(ps.toInputStream(), SummaryInformation.DEFAULT_STREAM_NAME); poiFs.writeFilesystem(out); out.close(); - + /* Read the POIFS: */ final PropertySet[] psa = new PropertySet[1]; final POIFSReader r = new POIFSReader(); @@ -240,7 +240,7 @@ public class TestWrite extends TestCase fail(org.apache.poi.hpsf.Util.toString(ex)); } } - + }, SummaryInformation.DEFAULT_STREAM_NAME); r.read(new FileInputStream(filename)); @@ -259,7 +259,7 @@ public class TestWrite extends TestCase /** * <p>Writes a simple property set with two sections to a POIFS and reads it * back in.</p> - * + * * @exception IOException if an I/O exception occurs * @exception WritingNotSupportedException if HPSF does not yet support * a variant type to be written @@ -365,7 +365,7 @@ public class TestWrite extends TestCase { Throwable t = null; final int codepage = CODEPAGE_DEFAULT; - if (!hasProperDefaultCharset()) + if (!hasProperDefaultCharset()) { System.err.println(IMPROPER_DEFAULT_CHARSET_MESSAGE + " This testcase is skipped."); @@ -375,8 +375,8 @@ public class TestWrite extends TestCase try { check(Variant.VT_EMPTY, null, codepage); - check(Variant.VT_BOOL, new Boolean(true), codepage); - check(Variant.VT_BOOL, new Boolean(false), codepage); + check(Variant.VT_BOOL, Boolean.TRUE, codepage); + check(Variant.VT_BOOL, Boolean.FALSE, codepage); check(Variant.VT_CF, new byte[]{0}, codepage); check(Variant.VT_CF, new byte[]{0, 1}, codepage); check(Variant.VT_CF, new byte[]{0, 1, 2}, codepage); @@ -385,11 +385,11 @@ public class TestWrite extends TestCase check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5}, codepage); check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6}, codepage); check(Variant.VT_CF, new byte[]{0, 1, 2, 3, 4, 5, 6, 7}, codepage); - check(Variant.VT_I4, new Integer(27), codepage); - check(Variant.VT_I8, new Long(28), codepage); + check(Variant.VT_I4, Integer.valueOf(27), codepage); + check(Variant.VT_I8, Long.valueOf(28), codepage); check(Variant.VT_R8, new Double(29.0), codepage); - check(Variant.VT_I4, new Integer(-27), codepage); - check(Variant.VT_I8, new Long(-28), codepage); + check(Variant.VT_I4, Integer.valueOf(-27), codepage); + check(Variant.VT_I8, Long.valueOf(-28), codepage); check(Variant.VT_R8, new Double(-29.0), codepage); check(Variant.VT_FILETIME, new Date(), codepage); check(Variant.VT_I4, new Integer(Integer.MAX_VALUE), codepage); @@ -460,7 +460,7 @@ public class TestWrite extends TestCase for (int i = 0; i < validCodepages.length; i++) { final int cp = validCodepages[i]; - if (cp == -1 && !hasProperDefaultCharset()) + if (cp == -1 && !hasProperDefaultCharset()) { System.err.println(IMPROPER_DEFAULT_CHARSET_MESSAGE + " This testcase is skipped for the default codepage."); @@ -590,10 +590,10 @@ public class TestWrite extends TestCase * @param codepage The codepage to use for writing and reading. * @throws UnsupportedVariantTypeException if the variant is not supported. * @throws IOException if an I/O exception occurs. - * @throws ReadingNotSupportedException - * @throws UnsupportedEncodingException + * @throws ReadingNotSupportedException + * @throws UnsupportedEncodingException */ - private void check(final long variantType, final Object value, + private void check(final long variantType, final Object value, final int codepage) throws UnsupportedVariantTypeException, IOException, ReadingNotSupportedException, UnsupportedEncodingException @@ -651,17 +651,17 @@ public class TestWrite extends TestCase * <p>This test method does a write and read back test with all POI * filesystems in the "data" directory by performing the following * actions for each file:</p> - * + * * <ul> - * + * * <li><p>Read its property set streams.</p></li> - * + * * <li><p>Create a new POI filesystem containing the origin file's * property set streams.</p></li> - * + * * <li><p>Read the property set streams from the POI filesystem just * created.</p></li> - * + * * <li><p>Compare each property set stream with the corresponding one from * the origin file and check whether they are equal.</p></li> * @@ -731,7 +731,7 @@ public class TestWrite extends TestCase final InputStream in2 = new ByteArrayInputStream(bytes2); final PropertySet ps1 = PropertySetFactory.create(in1); final PropertySet ps2 = PropertySetFactory.create(in2); - + /* Compare the property set stream with the corresponding one * from the origin file and check whether they are equal. */ assertEquals("Equality for file " + f.getName(), ps1, ps2); @@ -761,14 +761,14 @@ public class TestWrite extends TestCase final MutablePropertySet ps1 = new MutablePropertySet(); final MutableSection s = (MutableSection) ps1.getSections().get(0); final Map m = new HashMap(3, 1.0f); - m.put(new Long(1), "String 1"); - m.put(new Long(2), "String 2"); - m.put(new Long(3), "String 3"); + m.put(Long.valueOf(1), "String 1"); + m.put(Long.valueOf(2), "String 2"); + m.put(Long.valueOf(3), "String 3"); s.setDictionary(m); s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]); int codepage = Constants.CP_UNICODE; s.setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, - new Integer(codepage)); + Integer.valueOf(codepage)); poiFs.createDocument(ps1.toInputStream(), "Test"); poiFs.writeFilesystem(out); out.close(); @@ -813,14 +813,14 @@ public class TestWrite extends TestCase final MutablePropertySet ps1 = new MutablePropertySet(); final MutableSection s = (MutableSection) ps1.getSections().get(0); final Map m = new HashMap(3, 1.0f); - m.put(new Long(1), "String 1"); - m.put(new Long(2), "String 2"); - m.put(new Long(3), "String 3"); + m.put(Long.valueOf(1), "String 1"); + m.put(Long.valueOf(2), "String 2"); + m.put(Long.valueOf(3), "String 3"); s.setDictionary(m); s.setFormatID(SectionIDMap.DOCUMENT_SUMMARY_INFORMATION_ID[0]); int codepage = 12345; s.setProperty(PropertyIDMap.PID_CODEPAGE, Variant.VT_I2, - new Integer(codepage)); + Integer.valueOf(codepage)); poiFs.createDocument(ps1.toInputStream(), "Test"); poiFs.writeFilesystem(out); out.close(); diff --git a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java index ca3b0864ba..ad6e1237cf 100644 --- a/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java +++ b/src/testcases/org/apache/poi/hpsf/basic/TestWriteWellKnown.java @@ -58,7 +58,7 @@ import org.apache.poi.POIDataSamples; /** * <p>Tests HPSF's high-level writing functionality for the well-known property * set "SummaryInformation" and "DocumentSummaryInformation".</p> - * + * * @author Rainer Klute * <a href="mailto:klute@rainer-klute.de">klute@rainer-klute.de</a> */ @@ -83,11 +83,6 @@ public class TestWriteWellKnown extends TestCase { * pointed to by the "POI.testdata.path" system property, trying to extract * the document summary information stream in the root directory and calling * its get... methods.</p> - * @throws IOException - * @throws FileNotFoundException - * @throws MarkUnsupportedException - * @throws NoPropertySetStreamException - * @throws UnexpectedPropertySetTypeException */ public void testReadDocumentSummaryInformation() throws FileNotFoundException, IOException, @@ -131,7 +126,7 @@ public class TestWriteWellKnown extends TestCase { final DocumentInputStream dis = new DocumentInputStream(dsiEntry); final PropertySet ps = new PropertySet(dis); final DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps); - + /* Execute the get... methods. */ dsi.getByteCount(); dsi.getByteOrder(); @@ -159,43 +154,43 @@ public class TestWriteWellKnown extends TestCase { * <p>This test method test the writing of properties in the well-known * property set streams "SummaryInformation" and * "DocumentSummaryInformation" by performing the following steps:</p> - * + * * <ol> - * + * * <li><p>Read a test document <em>doc1</em> into a POI filesystem.</p></li> - * + * * <li><p>Read the summary information stream and the document summary * information stream from the POI filesystem.</p></li> - * + * * <li><p>Write all properties supported by HPSF to the summary * information (e.g. author, edit date, application name) and to the * document summary information (e.g. company, manager).</p></li> - * + * * <li><p>Write the summary information stream and the document summary * information stream to the POI filesystem.</p></li> - * + * * <li><p>Write the POI filesystem to a (temporary) file <em>doc2</em> * and close the latter.</p></li> - * + * * <li><p>Open <em>doc2</em> for reading and check summary information * and document summary information. All properties written before must be * found in the property streams of <em>doc2</em> and have the correct * values.</p></li> - * + * * <li><p>Remove all properties supported by HPSF from the summary * information (e.g. author, edit date, application name) and from the * document summary information (e.g. company, manager).</p></li> - * + * * <li><p>Write the summary information stream and the document summary * information stream to the POI filesystem.</p></li> - * + * * <li><p>Write the POI filesystem to a (temporary) file <em>doc3</em> * and close the latter.</p></li> - * + * * <li><p>Open <em>doc3</em> for reading and check summary information * and document summary information. All properties removed before must not * be found in the property streams of <em>doc3</em>.</p></li> </ol> - * + * * @throws IOException if some I/O error occurred. * @throws MarkUnsupportedException * @throws NoPropertySetStreamException @@ -209,17 +204,17 @@ public class TestWriteWellKnown extends TestCase { POIDataSamples _samples = POIDataSamples.getHPSFInstance(); final File dataDir = _samples.getFile(""); final File doc1 = new File(dataDir, POI_FS); - + /* Read a test document <em>doc1</em> into a POI filesystem. */ POIFSFileSystem poifs = new POIFSFileSystem(new FileInputStream(doc1)); DirectoryEntry dir = poifs.getRoot(); DocumentEntry siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); DocumentEntry dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - + /* * Read the summary information stream and the document summary * information stream from the POI filesystem. - * + * * Please note that the result consists of SummaryInformation and * DocumentSummaryInformation instances which are in memory only. To * make them permanent they have to be written to a POI filesystem @@ -232,7 +227,7 @@ public class TestWriteWellKnown extends TestCase { dis = new DocumentInputStream(dsiEntry); ps = new PropertySet(dis); DocumentSummaryInformation dsi = new DocumentSummaryInformation(ps); - + /* * Write all properties supported by HPSF to the summary information * (e.g. author, edit date, application name) and to the document @@ -245,7 +240,7 @@ public class TestWriteWellKnown extends TestCase { final long time2 = cal.getTimeInMillis(); cal.set(2002, 8, 8, 8, 8, 8); final long time3 = cal.getTimeInMillis(); - + int nr = 4711; final String P_APPLICATION_NAME = "ApplicationName"; final String P_AUTHOR = "Author"; @@ -265,7 +260,7 @@ public class TestWriteWellKnown extends TestCase { // FIXME (byte array properties not yet implemented): final byte[] P_THUMBNAIL = new byte[123]; final String P_TITLE = "Title"; final int P_WORD_COUNT = ++nr; - + final int P_BYTE_COUNT = ++nr; final String P_CATEGORY = "Category"; final String P_COMPANY = "Company"; @@ -296,7 +291,7 @@ public class TestWriteWellKnown extends TestCase { final Long MIN_LONG = new Long(Long.MIN_VALUE); final Double MAX_DOUBLE = new Double(Double.MAX_VALUE); final Double MIN_DOUBLE = new Double(Double.MIN_VALUE); - + si.setApplicationName(P_APPLICATION_NAME); si.setAuthor(P_AUTHOR); si.setCharCount(P_CHAR_COUNT); @@ -315,7 +310,7 @@ public class TestWriteWellKnown extends TestCase { // FIXME (byte array properties not yet implemented): si.setThumbnail(P_THUMBNAIL); si.setTitle(P_TITLE); si.setWordCount(P_WORD_COUNT); - + dsi.setByteCount(P_BYTE_COUNT); dsi.setCategory(P_CATEGORY); dsi.setCompany(P_COMPANY); @@ -345,7 +340,7 @@ public class TestWriteWellKnown extends TestCase { customProperties.put("negative_Integer", NEGATIVE_INTEGER); customProperties.put("negative_Long", NEGATIVE_LONG); customProperties.put("negative_Double", NEGATIVE_DOUBLE); - customProperties.put("Boolean", new Boolean(true)); + customProperties.put("Boolean", Boolean.TRUE); customProperties.put("Date", now); customProperties.put("max_Integer", MAX_INTEGER); customProperties.put("min_Integer", MIN_INTEGER); @@ -378,14 +373,14 @@ public class TestWriteWellKnown extends TestCase { dir = poifs.getRoot(); siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - + dis = new DocumentInputStream(siEntry); ps = new PropertySet(dis); si = new SummaryInformation(ps); dis = new DocumentInputStream(dsiEntry); ps = new PropertySet(dis); dsi = new DocumentSummaryInformation(ps); - + assertEquals(P_APPLICATION_NAME, si.getApplicationName()); assertEquals(P_AUTHOR, si.getAuthor()); assertEquals(P_CHAR_COUNT, si.getCharCount()); @@ -404,7 +399,7 @@ public class TestWriteWellKnown extends TestCase { // FIXME (byte array properties not yet implemented): assertEquals(P_THUMBNAIL, si.getThumbnail()); assertEquals(P_TITLE, si.getTitle()); assertEquals(P_WORD_COUNT, si.getWordCount()); - + assertEquals(P_BYTE_COUNT, dsi.getByteCount()); assertEquals(P_CATEGORY, dsi.getCategory()); assertEquals(P_COMPANY, dsi.getCompany()); @@ -434,7 +429,7 @@ public class TestWriteWellKnown extends TestCase { assertEquals(NEGATIVE_INTEGER, cps.get("negative_Integer")); assertEquals(NEGATIVE_LONG, cps.get("negative_Long")); assertEquals(NEGATIVE_DOUBLE, cps.get("negative_Double")); - assertEquals(new Boolean(true), cps.get("Boolean")); + assertEquals(Boolean.TRUE, cps.get("Boolean")); assertEquals(now, cps.get("Date")); assertEquals(MAX_INTEGER, cps.get("max_Integer")); assertEquals(MIN_INTEGER, cps.get("min_Integer")); @@ -464,7 +459,7 @@ public class TestWriteWellKnown extends TestCase { si.removeThumbnail(); si.removeTitle(); si.removeWordCount(); - + dsi.removeByteCount(); dsi.removeCategory(); dsi.removeCompany(); @@ -481,14 +476,14 @@ public class TestWriteWellKnown extends TestCase { dsi.removePresentationFormat(); dsi.removeScale(); dsi.removeSlideCount(); - - /* + + /* * <li><p>Write the summary information stream and the document summary * information stream to the POI filesystem. */ si.write(dir, siEntry.getName()); dsi.write(dir, dsiEntry.getName()); - - /* + + /* * <li><p>Write the POI filesystem to a (temporary) file <em>doc3</em> * and close the latter. */ final File doc3 = File.createTempFile("POI_HPSF_Test.", ".tmp"); @@ -496,8 +491,8 @@ public class TestWriteWellKnown extends TestCase { out = new FileOutputStream(doc3); poifs.writeFilesystem(out); out.close(); - - /* + + /* * Open <em>doc3</em> for reading and check summary information * and document summary information. All properties removed before must not * be found in the property streams of <em>doc3</em>. @@ -506,14 +501,14 @@ public class TestWriteWellKnown extends TestCase { dir = poifs.getRoot(); siEntry = (DocumentEntry) dir.getEntry(SummaryInformation.DEFAULT_STREAM_NAME); dsiEntry = (DocumentEntry) dir.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME); - + dis = new DocumentInputStream(siEntry); ps = new PropertySet(dis); si = new SummaryInformation(ps); dis = new DocumentInputStream(dsiEntry); ps = new PropertySet(dis); dsi = new DocumentSummaryInformation(ps); - + assertEquals(null, si.getApplicationName()); assertEquals(null, si.getAuthor()); assertEquals(0, si.getCharCount()); @@ -537,7 +532,7 @@ public class TestWriteWellKnown extends TestCase { assertEquals(null, si.getTitle()); assertEquals(0, si.getWordCount()); assertTrue(si.wasNull()); - + assertEquals(0, dsi.getByteCount()); assertTrue(dsi.wasNull()); assertEquals(null, dsi.getCategory()); @@ -611,7 +606,7 @@ public class TestWriteWellKnown extends TestCase { else dsi = PropertySetFactory.newDocumentSummaryInformation(); final CustomProperties cps = dsi.getCustomProperties(); - + if (cps == null) /* The document does not have custom properties. */ return; @@ -663,14 +658,14 @@ public class TestWriteWellKnown extends TestCase { assertEquals(1, cps.size()); Object v1 = cps.get(KEY); assertEquals(VALUE_1, v1); - + /* After adding a custom property with the same name the size must still * be one. */ cps.put(KEY, VALUE_2); assertEquals(1, cps.size()); Object v2 = cps.get(KEY); assertEquals(VALUE_2, v2); - + /* Removing the custom property must return the remove property and * reduce the size to 0. */ cp = (CustomProperty) cps.remove(KEY); @@ -715,7 +710,7 @@ public class TestWriteWellKnown extends TestCase { p.setType(Variant.VT_LPWSTR); p.setValue(VALUE_1); s.setProperty(p); - dictionary.put(new Long(ID_1), NAME_1); + dictionary.put(Long.valueOf(ID_1), NAME_1); s.setDictionary(dictionary); cps = dsi.getCustomProperties(); assertEquals(1, cps.size()); @@ -723,7 +718,7 @@ public class TestWriteWellKnown extends TestCase { /* Add another custom property. */ s.setProperty(ID_2, Variant.VT_LPWSTR, VALUE_1); - dictionary.put(new Long(ID_2), NAME_1); + dictionary.put(Long.valueOf(ID_2), NAME_1); s.setDictionary(dictionary); cps = dsi.getCustomProperties(); assertEquals(1, cps.size()); diff --git a/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java b/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java index 7702fce3d4..c3a026c211 100644 --- a/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java +++ b/src/testcases/org/apache/poi/hssf/record/formula/function/ExcelFileFormatDocFunctionExtractor.java @@ -56,7 +56,7 @@ import org.xml.sax.helpers.XMLReaderFactory; * the file 'functionMetadata.txt'. There are more than 300 built-in functions in Excel and the * intention of this class is to make it easier to maintain the metadata, by extracting it from * a reliable source. - * + * * @author Josh Micich */ public final class ExcelFileFormatDocFunctionExtractor { @@ -65,10 +65,10 @@ public final class ExcelFileFormatDocFunctionExtractor { /** * For simplicity, the output file is strictly simple ASCII. - * This method detects any unexpected characters. + * This method detects any unexpected characters. */ /* package */ static boolean isSimpleAscii(char c) { - + if (c>=0x21 && c<=0x7E) { // everything from '!' to '~' (includes letters, digits, punctuation return true; @@ -83,8 +83,8 @@ public final class ExcelFileFormatDocFunctionExtractor { } return false; } - - + + private static final class FunctionData { // special characters from the ooo document private static final int CHAR_ELLIPSIS_8230 = 8230; @@ -148,7 +148,7 @@ public final class ExcelFileFormatDocFunctionExtractor { return b ? "x" : ""; } } - + private static final class FunctionDataCollector { private final Map _allFunctionsByIndex; @@ -156,7 +156,7 @@ public final class ExcelFileFormatDocFunctionExtractor { private final Set _groupFunctionIndexes; private final Set _groupFunctionNames; private final PrintStream _ps; - + public FunctionDataCollector(PrintStream ps) { _ps = ps; _allFunctionsByIndex = new HashMap(); @@ -168,19 +168,19 @@ public final class ExcelFileFormatDocFunctionExtractor { public void addFuntion(int funcIx, boolean hasFootnote, String funcName, int minParams, int maxParams, String returnClass, String paramClasses, String volatileFlagStr) { boolean isVolatile = volatileFlagStr.length() > 0; - - Integer funcIxKey = new Integer(funcIx); + + Integer funcIxKey = Integer.valueOf(funcIx); if(!_groupFunctionIndexes.add(funcIxKey)) { throw new RuntimeException("Duplicate function index (" + funcIx + ")"); } if(!_groupFunctionNames.add(funcName)) { throw new RuntimeException("Duplicate function name '" + funcName + "'"); } - + checkRedefinedFunction(hasFootnote, funcName, funcIxKey); - FunctionData fd = new FunctionData(funcIx, hasFootnote, funcName, + FunctionData fd = new FunctionData(funcIx, hasFootnote, funcName, minParams, maxParams, returnClass, paramClasses, isVolatile); - + _allFunctionsByIndex.put(funcIxKey, fd); _allFunctionsByName.put(funcName, fd); } @@ -195,7 +195,7 @@ public final class ExcelFileFormatDocFunctionExtractor { fdPrev = (FunctionData) _allFunctionsByIndex.get(funcIxKey); if(fdPrev != null) { if(!fdPrev.hasFootnote() || !hasNote) { - throw new RuntimeException("changing function [" + throw new RuntimeException("changing function [" + funcIxKey + "] definition without foot-note"); } _allFunctionsByName.remove(fdPrev.getName()); @@ -204,10 +204,10 @@ public final class ExcelFileFormatDocFunctionExtractor { fdPrev = (FunctionData) _allFunctionsByName.get(funcName); if(fdPrev != null) { if(!fdPrev.hasFootnote() || !hasNote) { - throw new RuntimeException("changing function '" + throw new RuntimeException("changing function '" + funcName + "' definition without foot-note"); } - _allFunctionsByIndex.remove(new Integer(fdPrev.getIndex())); + _allFunctionsByIndex.remove(Integer.valueOf(fdPrev.getIndex())); } } @@ -217,7 +217,7 @@ public final class ExcelFileFormatDocFunctionExtractor { _groupFunctionIndexes.clear(); _groupFunctionNames.clear(); Arrays.sort(keys); - + _ps.println("# " + headingText); for (int i = 0; i < keys.length; i++) { FunctionData fd = (FunctionData) _allFunctionsByIndex.get(keys[i]); @@ -225,25 +225,25 @@ public final class ExcelFileFormatDocFunctionExtractor { } } } - + /** - * To avoid drag-in - parse XML using only JDK. + * To avoid drag-in - parse XML using only JDK. */ private static class EFFDocHandler implements ContentHandler { private static final String[] HEADING_PATH_NAMES = { - "office:document-content", "office:body", "office:text", "text:h", + "office:document-content", "office:body", "office:text", "text:h", }; private static final String[] TABLE_BASE_PATH_NAMES = { - "office:document-content", "office:body", "office:text", "table:table", + "office:document-content", "office:body", "office:text", "table:table", }; private static final String[] TABLE_ROW_RELPATH_NAMES = { - "table:table-row", + "table:table-row", }; private static final String[] TABLE_CELL_RELPATH_NAMES = { - "table:table-row", "table:table-cell", "text:p", + "table:table-row", "table:table-cell", "text:p", }; // after May 2008 there was one more style applied to the footnotes - private static final String[] NOTE_REF_RELPATH_NAMES_OLD = { + private static final String[] NOTE_REF_RELPATH_NAMES_OLD = { "table:table-row", "table:table-cell", "text:p", "text:span", "text:note-ref", }; private static final String[] NOTE_REF_RELPATH_NAMES = { @@ -255,7 +255,7 @@ public final class ExcelFileFormatDocFunctionExtractor { /** <code>true</code> only when parsing the target tables */ private boolean _isInsideTable; - private final List _rowData; + private final List _rowData; private final StringBuffer _textNodeBuffer; private final List _rowNoteFlags; private boolean _cellHasNote; @@ -304,7 +304,7 @@ public final class ExcelFileFormatDocFunctionExtractor { if(matchesPath(0, HEADING_PATH_NAMES)) { _lastHeadingText = _textNodeBuffer.toString().trim(); _textNodeBuffer.setLength(0); - } + } if(_isInsideTable) { if(matchesTargetPath()) { _fdc.endTableGroup(_lastHeadingText); @@ -350,7 +350,7 @@ public final class ExcelFileFormatDocFunctionExtractor { String returnClass = cellData[i + 4]; String paramClasses = cellData[i + 5]; String volatileFlagStr = cellData[i + 6]; - + _fdc.addFuntion(funcIx, hasFootnote, funcName, minParams, maxParams, returnClass, paramClasses, volatileFlagStr); } private static int parseInt(String valStr) { @@ -412,7 +412,7 @@ public final class ExcelFileFormatDocFunctionExtractor { private static void extractFunctionData(FunctionDataCollector fdc, InputStream is) { XMLReader xr; - + try { // First up, try the default one xr = XMLReaderFactory.createXMLReader(); @@ -460,7 +460,7 @@ public final class ExcelFileFormatDocFunctionExtractor { public void write(byte[] b, int off, int len) throws IOException { for (int i = 0; i < len; i++) { checkByte(b[i + off]); - + } _os.write(b, off, len); } @@ -483,7 +483,7 @@ public final class ExcelFileFormatDocFunctionExtractor { } catch(UnsupportedEncodingException e) { throw new RuntimeException(e); } - + outputLicenseHeader(ps); Class genClass = ExcelFileFormatDocFunctionExtractor.class; ps.println("# Created by (" + genClass.getName() + ")"); @@ -504,7 +504,7 @@ public final class ExcelFileFormatDocFunctionExtractor { throw new RuntimeException(e); } ps.close(); - + String canonicalOutputFileName; try { canonicalOutputFileName = outFile.getCanonicalPath(); @@ -554,7 +554,7 @@ public final class ExcelFileFormatDocFunctionExtractor { InputStream is = new FileInputStream(f); while(true) { int bytesRead = is.read(buf); - if(bytesRead<1) { + if(bytesRead<1) { break; } m.update(buf, 0, bytesRead); @@ -563,7 +563,7 @@ public final class ExcelFileFormatDocFunctionExtractor { } catch (IOException e) { throw new RuntimeException(e); } - + return "0x" + new BigInteger(1, m.digest()).toString(16); } @@ -585,7 +585,7 @@ public final class ExcelFileFormatDocFunctionExtractor { OutputStream os = new FileOutputStream(result); while(true) { int bytesRead = is.read(buf); - if(bytesRead<1) { + if(bytesRead<1) { break; } os.write(buf, 0, bytesRead); @@ -609,7 +609,7 @@ public final class ExcelFileFormatDocFunctionExtractor { processFile(effDocFile, outFile); return; } - + File tempEFFDocFile = downloadSourceFile(); processFile(tempEFFDocFile, outFile); tempEFFDocFile.delete(); diff --git a/src/testcases/org/apache/poi/hssf/usermodel/StreamUtility.java b/src/testcases/org/apache/poi/hssf/usermodel/StreamUtility.java index 45ae4ac362..b9f39a03c6 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/StreamUtility.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/StreamUtility.java @@ -6,7 +6,7 @@ (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 + 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, @@ -23,24 +23,24 @@ import java.util.ArrayList; import java.util.List; /** - * Utility class to help test code verify that generated files do not differ from proof copies in + * Utility class to help test code verify that generated files do not differ from proof copies in * any significant detail. Normally this task would be simple except for the presence of artifacts - * in the file that change every time it is generated. Usually these volatile artifacts are + * in the file that change every time it is generated. Usually these volatile artifacts are * time-stamps, user names, or other machine dependent parameters. - * + * * @author Josh Micich */ public final class StreamUtility { /** * Compares two streams with expected differences in specified regions. The streams are - * expected to be of equal length and comparison is always byte for byte. That is - - * differences can only involve exchanging each individual byte for another single byte.<br> - * Both input streams are closed. - * - * @param allowableDifferenceRegions array of integer pairs: (offset, length). + * expected to be of equal length and comparison is always byte for byte. That is - + * differences can only involve exchanging each individual byte for another single byte.<br> + * Both input streams are closed. + * + * @param allowableDifferenceRegions array of integer pairs: (offset, length). * Any differences encountered in these regions of the streams will be ignored - * @return <code>null</code> if streams are identical, else the + * @return <code>null</code> if streams are identical, else the * byte indexes of differing data. If streams were different lengths, * the returned indexes will be -1 and the length of the shorter stream */ @@ -51,36 +51,36 @@ public final class StreamUtility { } boolean success = false; int[] result; - try { - result = diffInternal(isA, isB, allowableDifferenceRegions); - success = true; - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - close(isA, success); - close(isB, success); - } - return result; + try { + result = diffInternal(isA, isB, allowableDifferenceRegions); + success = true; + } catch (IOException e) { + throw new RuntimeException(e); + } finally { + close(isA, success); + close(isB, success); + } + return result; } /** * @param success <code>false</code> if the outer method is throwing an exception. */ - private static void close(InputStream is, boolean success) { - try { - is.close(); - } catch (IOException e) { - if(success) { - // this is a new error. ok to throw - throw new RuntimeException(e); - } - // else don't subvert original exception. just print stack trace for this one - e.printStackTrace(); - } - } + private static void close(InputStream is, boolean success) { + try { + is.close(); + } catch (IOException e) { + if(success) { + // this is a new error. ok to throw + throw new RuntimeException(e); + } + // else don't subvert original exception. just print stack trace for this one + e.printStackTrace(); + } + } - private static int[] diffInternal(InputStream isA, InputStream isB, int[] allowableDifferenceRegions) - throws IOException { + private static int[] diffInternal(InputStream isA, InputStream isB, int[] allowableDifferenceRegions) + throws IOException { int offset = 0; List temp = new ArrayList(); while (true) { @@ -97,11 +97,11 @@ public final class StreamUtility { return new int[] { -1, offset, }; } if (b != b2 && !isIgnoredRegion(allowableDifferenceRegions, offset)) { - temp.add(new Integer(offset)); + temp.add(Integer.valueOf(offset)); } offset++; } - } + } private static boolean isIgnoredRegion(int[] allowableDifferenceRegions, int offset) { for (int i = 0; i < allowableDifferenceRegions.length; i+=2) { @@ -121,7 +121,7 @@ public final class StreamUtility { } Integer[] boxInts = new Integer[nItems]; temp.toArray(boxInts); - + int[] result = new int[nItems]; for (int i = 0; i < result.length; i++) { result[i] = boxInts[i].intValue(); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java index 8eeb64c7c6..b1c21dd373 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestDataFormat.java @@ -40,7 +40,7 @@ public abstract class BaseTestDataFormat extends TestCase { Map<Integer, String> formats = BuiltinFormats.getBuiltinFormats(); for (int idx : formats.keySet()) { - String fmt = formats.get(new Integer(idx)); + String fmt = formats.get(Integer.valueOf(idx)); assertEquals(idx, df.getFormat(fmt)); } diff --git a/src/testcases/org/apache/poi/util/LocalTestNode.java b/src/testcases/org/apache/poi/util/LocalTestNode.java index 2f1ae62649..6eaaed5901 100644 --- a/src/testcases/org/apache/poi/util/LocalTestNode.java +++ b/src/testcases/org/apache/poi/util/LocalTestNode.java @@ -15,7 +15,6 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - package org.apache.poi.util; @@ -33,7 +32,7 @@ class LocalTestNode LocalTestNode(final int key) { - _key = new Integer(key); + _key = Integer.valueOf(key); _value = String.valueOf(key); } @@ -118,7 +117,6 @@ class LocalTestNode /** * @return hash code */ - public int hashCode() { return getKey().hashCode() ^ getValue().hashCode(); diff --git a/src/testcases/org/apache/poi/util/TestArrayUtil.java b/src/testcases/org/apache/poi/util/TestArrayUtil.java index 7a517e3c6b..2af0481513 100644 --- a/src/testcases/org/apache/poi/util/TestArrayUtil.java +++ b/src/testcases/org/apache/poi/util/TestArrayUtil.java @@ -15,261 +15,264 @@ See the License for the specific language governing permissions and limitations under the License. ==================================================================== */ - + package org.apache.poi.util; -import junit.framework.*; +import junit.framework.TestCase; /** * Unit test for ArrayUtil * * @author Nick Burch */ -public class TestArrayUtil extends TestCase -{ +public class TestArrayUtil extends TestCase { /** * Test to ensure that our own arraycopy behaves as it should do */ public void testarraycopy() { byte[] bytes = new byte[] { 0x01, 0x02, 0x03, 0x04 }; - + // Test copy whole thing byte[] dest = new byte[4]; ArrayUtil.arraycopy(bytes, 0, dest, 0, 4); - + assertEquals(dest.length, bytes.length); for(int i=0; i<dest.length; i++) { assertEquals(bytes[i], dest[i]); } - + // ToDo - test exceptions are as expected } - - + + /** - * Helper for testArrayMoveWithin + * Helper for testArrayMoveWithin */ - private Integer[] getIntsList() { + private Integer[] getIntsList() { return new Integer[] { - new Integer(0), - new Integer(1), - new Integer(2), - new Integer(3), - new Integer(4), - new Integer(5), - new Integer(6), - new Integer(7), - new Integer(8), - new Integer(9) + Integer.valueOf(0), + Integer.valueOf(1), + Integer.valueOf(2), + Integer.valueOf(3), + Integer.valueOf(4), + Integer.valueOf(5), + Integer.valueOf(6), + Integer.valueOf(7), + Integer.valueOf(8), + Integer.valueOf(9) }; } + + private static void assertEquals(int exp, Integer act) { + assertEquals(exp, act.intValue()); + } /** * Test to ensure that arrayMoveWithin works as expected */ public void testArrayMoveWithin() { Integer[] ints = getIntsList(); - - assertEquals(new Integer(0), ints[0]); - assertEquals(new Integer(1), ints[1]); - assertEquals(new Integer(2), ints[2]); - assertEquals(new Integer(3), ints[3]); - assertEquals(new Integer(4), ints[4]); - assertEquals(new Integer(5), ints[5]); - assertEquals(new Integer(6), ints[6]); - assertEquals(new Integer(7), ints[7]); - assertEquals(new Integer(8), ints[8]); - assertEquals(new Integer(9), ints[9]); - - + + assertEquals(0, ints[0]); + assertEquals(1, ints[1]); + assertEquals(2, ints[2]); + assertEquals(3, ints[3]); + assertEquals(4, ints[4]); + assertEquals(5, ints[5]); + assertEquals(6, ints[6]); + assertEquals(7, ints[7]); + assertEquals(8, ints[8]); + assertEquals(9, ints[9]); + + // // Moving to a later point in the array // - + // Shift 1 back ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 4, 8, 1); - assertEquals(new Integer(0), ints[0]); - assertEquals(new Integer(1), ints[1]); - assertEquals(new Integer(2), ints[2]); - assertEquals(new Integer(3), ints[3]); - assertEquals(new Integer(5), ints[4]); - assertEquals(new Integer(6), ints[5]); - assertEquals(new Integer(7), ints[6]); - assertEquals(new Integer(8), ints[7]); - assertEquals(new Integer(4), ints[8]); - assertEquals(new Integer(9), ints[9]); - + assertEquals(0, ints[0]); + assertEquals(1, ints[1]); + assertEquals(2, ints[2]); + assertEquals(3, ints[3]); + assertEquals(5, ints[4]); + assertEquals(6, ints[5]); + assertEquals(7, ints[6]); + assertEquals(8, ints[7]); + assertEquals(4, ints[8]); + assertEquals(9, ints[9]); + // Shift front 1 back ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 0, 7, 1); - assertEquals(new Integer(1), ints[0]); - assertEquals(new Integer(2), ints[1]); - assertEquals(new Integer(3), ints[2]); - assertEquals(new Integer(4), ints[3]); - assertEquals(new Integer(5), ints[4]); - assertEquals(new Integer(6), ints[5]); - assertEquals(new Integer(7), ints[6]); - assertEquals(new Integer(0), ints[7]); - assertEquals(new Integer(8), ints[8]); - assertEquals(new Integer(9), ints[9]); - + assertEquals(1, ints[0]); + assertEquals(2, ints[1]); + assertEquals(3, ints[2]); + assertEquals(4, ints[3]); + assertEquals(5, ints[4]); + assertEquals(6, ints[5]); + assertEquals(7, ints[6]); + assertEquals(0, ints[7]); + assertEquals(8, ints[8]); + assertEquals(9, ints[9]); + // Shift 1 to end ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 4, 9, 1); - assertEquals(new Integer(0), ints[0]); - assertEquals(new Integer(1), ints[1]); - assertEquals(new Integer(2), ints[2]); - assertEquals(new Integer(3), ints[3]); - assertEquals(new Integer(5), ints[4]); - assertEquals(new Integer(6), ints[5]); - assertEquals(new Integer(7), ints[6]); - assertEquals(new Integer(8), ints[7]); - assertEquals(new Integer(9), ints[8]); - assertEquals(new Integer(4), ints[9]); - - + assertEquals(0, ints[0]); + assertEquals(1, ints[1]); + assertEquals(2, ints[2]); + assertEquals(3, ints[3]); + assertEquals(5, ints[4]); + assertEquals(6, ints[5]); + assertEquals(7, ints[6]); + assertEquals(8, ints[7]); + assertEquals(9, ints[8]); + assertEquals(4, ints[9]); + + // // Moving to an earlier point in the array // - + // Shift 1 forward ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 8, 3, 1); - assertEquals(new Integer(0), ints[0]); - assertEquals(new Integer(1), ints[1]); - assertEquals(new Integer(2), ints[2]); - assertEquals(new Integer(8), ints[3]); - assertEquals(new Integer(3), ints[4]); - assertEquals(new Integer(4), ints[5]); - assertEquals(new Integer(5), ints[6]); - assertEquals(new Integer(6), ints[7]); - assertEquals(new Integer(7), ints[8]); - assertEquals(new Integer(9), ints[9]); - + assertEquals(0, ints[0]); + assertEquals(1, ints[1]); + assertEquals(2, ints[2]); + assertEquals(8, ints[3]); + assertEquals(3, ints[4]); + assertEquals(4, ints[5]); + assertEquals(5, ints[6]); + assertEquals(6, ints[7]); + assertEquals(7, ints[8]); + assertEquals(9, ints[9]); + // Shift end 1 forward ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 9, 2, 1); - assertEquals(new Integer(0), ints[0]); - assertEquals(new Integer(1), ints[1]); - assertEquals(new Integer(9), ints[2]); - assertEquals(new Integer(2), ints[3]); - assertEquals(new Integer(3), ints[4]); - assertEquals(new Integer(4), ints[5]); - assertEquals(new Integer(5), ints[6]); - assertEquals(new Integer(6), ints[7]); - assertEquals(new Integer(7), ints[8]); - assertEquals(new Integer(8), ints[9]); - + assertEquals(0, ints[0]); + assertEquals(1, ints[1]); + assertEquals(9, ints[2]); + assertEquals(2, ints[3]); + assertEquals(3, ints[4]); + assertEquals(4, ints[5]); + assertEquals(5, ints[6]); + assertEquals(6, ints[7]); + assertEquals(7, ints[8]); + assertEquals(8, ints[9]); + // Shift 1 to front ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 5, 0, 1); - assertEquals(new Integer(5), ints[0]); - assertEquals(new Integer(0), ints[1]); - assertEquals(new Integer(1), ints[2]); - assertEquals(new Integer(2), ints[3]); - assertEquals(new Integer(3), ints[4]); - assertEquals(new Integer(4), ints[5]); - assertEquals(new Integer(6), ints[6]); - assertEquals(new Integer(7), ints[7]); - assertEquals(new Integer(8), ints[8]); - assertEquals(new Integer(9), ints[9]); - - + assertEquals(5, ints[0]); + assertEquals(0, ints[1]); + assertEquals(1, ints[2]); + assertEquals(2, ints[3]); + assertEquals(3, ints[4]); + assertEquals(4, ints[5]); + assertEquals(6, ints[6]); + assertEquals(7, ints[7]); + assertEquals(8, ints[8]); + assertEquals(9, ints[9]); + + // // Moving many to a later point in the array // - + // Shift 3 back ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 2, 6, 3); - assertEquals(new Integer(0), ints[0]); - assertEquals(new Integer(1), ints[1]); - assertEquals(new Integer(5), ints[2]); - assertEquals(new Integer(6), ints[3]); - assertEquals(new Integer(7), ints[4]); - assertEquals(new Integer(8), ints[5]); - assertEquals(new Integer(2), ints[6]); - assertEquals(new Integer(3), ints[7]); - assertEquals(new Integer(4), ints[8]); - assertEquals(new Integer(9), ints[9]); - + assertEquals(0, ints[0]); + assertEquals(1, ints[1]); + assertEquals(5, ints[2]); + assertEquals(6, ints[3]); + assertEquals(7, ints[4]); + assertEquals(8, ints[5]); + assertEquals(2, ints[6]); + assertEquals(3, ints[7]); + assertEquals(4, ints[8]); + assertEquals(9, ints[9]); + // Shift 3 to back ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 2, 7, 3); - assertEquals(new Integer(0), ints[0]); - assertEquals(new Integer(1), ints[1]); - assertEquals(new Integer(5), ints[2]); - assertEquals(new Integer(6), ints[3]); - assertEquals(new Integer(7), ints[4]); - assertEquals(new Integer(8), ints[5]); - assertEquals(new Integer(9), ints[6]); - assertEquals(new Integer(2), ints[7]); - assertEquals(new Integer(3), ints[8]); - assertEquals(new Integer(4), ints[9]); - + assertEquals(0, ints[0]); + assertEquals(1, ints[1]); + assertEquals(5, ints[2]); + assertEquals(6, ints[3]); + assertEquals(7, ints[4]); + assertEquals(8, ints[5]); + assertEquals(9, ints[6]); + assertEquals(2, ints[7]); + assertEquals(3, ints[8]); + assertEquals(4, ints[9]); + // Shift from 3 front ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 0, 5, 3); - assertEquals(new Integer(3), ints[0]); - assertEquals(new Integer(4), ints[1]); - assertEquals(new Integer(5), ints[2]); - assertEquals(new Integer(6), ints[3]); - assertEquals(new Integer(7), ints[4]); - assertEquals(new Integer(0), ints[5]); - assertEquals(new Integer(1), ints[6]); - assertEquals(new Integer(2), ints[7]); - assertEquals(new Integer(8), ints[8]); - assertEquals(new Integer(9), ints[9]); - - + assertEquals(3, ints[0]); + assertEquals(4, ints[1]); + assertEquals(5, ints[2]); + assertEquals(6, ints[3]); + assertEquals(7, ints[4]); + assertEquals(0, ints[5]); + assertEquals(1, ints[6]); + assertEquals(2, ints[7]); + assertEquals(8, ints[8]); + assertEquals(9, ints[9]); + + // // Moving many to an earlier point in the array // - + // Shift 3 forward ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 6, 2, 3); - assertEquals(new Integer(0), ints[0]); - assertEquals(new Integer(1), ints[1]); - assertEquals(new Integer(6), ints[2]); - assertEquals(new Integer(7), ints[3]); - assertEquals(new Integer(8), ints[4]); - assertEquals(new Integer(2), ints[5]); - assertEquals(new Integer(3), ints[6]); - assertEquals(new Integer(4), ints[7]); - assertEquals(new Integer(5), ints[8]); - assertEquals(new Integer(9), ints[9]); - + assertEquals(0, ints[0]); + assertEquals(1, ints[1]); + assertEquals(6, ints[2]); + assertEquals(7, ints[3]); + assertEquals(8, ints[4]); + assertEquals(2, ints[5]); + assertEquals(3, ints[6]); + assertEquals(4, ints[7]); + assertEquals(5, ints[8]); + assertEquals(9, ints[9]); + // Shift 3 to front ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 6, 0, 3); - assertEquals(new Integer(6), ints[0]); - assertEquals(new Integer(7), ints[1]); - assertEquals(new Integer(8), ints[2]); - assertEquals(new Integer(0), ints[3]); - assertEquals(new Integer(1), ints[4]); - assertEquals(new Integer(2), ints[5]); - assertEquals(new Integer(3), ints[6]); - assertEquals(new Integer(4), ints[7]); - assertEquals(new Integer(5), ints[8]); - assertEquals(new Integer(9), ints[9]); - + assertEquals(6, ints[0]); + assertEquals(7, ints[1]); + assertEquals(8, ints[2]); + assertEquals(0, ints[3]); + assertEquals(1, ints[4]); + assertEquals(2, ints[5]); + assertEquals(3, ints[6]); + assertEquals(4, ints[7]); + assertEquals(5, ints[8]); + assertEquals(9, ints[9]); + // Shift from 3 back ints = getIntsList(); ArrayUtil.arrayMoveWithin(ints, 7, 3, 3); - assertEquals(new Integer(0), ints[0]); - assertEquals(new Integer(1), ints[1]); - assertEquals(new Integer(2), ints[2]); - assertEquals(new Integer(7), ints[3]); - assertEquals(new Integer(8), ints[4]); - assertEquals(new Integer(9), ints[5]); - assertEquals(new Integer(3), ints[6]); - assertEquals(new Integer(4), ints[7]); - assertEquals(new Integer(5), ints[8]); - assertEquals(new Integer(6), ints[9]); - - + assertEquals(0, ints[0]); + assertEquals(1, ints[1]); + assertEquals(2, ints[2]); + assertEquals(7, ints[3]); + assertEquals(8, ints[4]); + assertEquals(9, ints[5]); + assertEquals(3, ints[6]); + assertEquals(4, ints[7]); + assertEquals(5, ints[8]); + assertEquals(6, ints[9]); + + // Check can't shift more than we have try { ints = getIntsList(); @@ -278,7 +281,7 @@ public class TestArrayUtil extends TestCase } catch(IllegalArgumentException e) { // Good, we don't have 5 from 7 onwards } - + // Check can't shift where would overshoot try { ints = getIntsList(); @@ -289,4 +292,3 @@ public class TestArrayUtil extends TestCase } } } - diff --git a/src/testcases/org/apache/poi/util/TestBinaryTree.java b/src/testcases/org/apache/poi/util/TestBinaryTree.java index f9474adee1..542635980f 100644 --- a/src/testcases/org/apache/poi/util/TestBinaryTree.java +++ b/src/testcases/org/apache/poi/util/TestBinaryTree.java @@ -120,7 +120,7 @@ public final class TestBinaryTree extends TestCase { m.put(nodes[ k ].getKey(), nodes[ k ]); assertTrue(m.containsKey(nodes[ k ].getKey())); } - assertTrue(!m.containsKey(new Integer(-1))); + assertTrue(!m.containsKey(Integer.valueOf(-1))); try { m.containsKey("foo"); @@ -179,7 +179,7 @@ public final class TestBinaryTree extends TestCase { m.put(nodes[ k ].getKey(), nodes[ k ]); assertSame(m.get(nodes[ k ].getKey()), nodes[ k ]); } - assertNull(m.get(new Integer(-1))); + assertNull(m.get(Integer.valueOf(-1))); try { m.get("foo"); @@ -270,7 +270,7 @@ public final class TestBinaryTree extends TestCase { catch (ClassCastException ignored) { } - assertNull(m.remove(new Integer(-1))); + assertNull(m.remove(Integer.valueOf(-1))); try { m.remove("foo"); @@ -450,7 +450,7 @@ public final class TestBinaryTree extends TestCase { Collection c1 = new LinkedList(); Collection c2 = new LinkedList(); - c2.add(new Integer(-99)); + c2.add(Integer.valueOf(-99)); for (int k = 0; k < nodes.length; k++) { m.put(nodes[ k ].getKey(), nodes[ k ]); @@ -461,7 +461,7 @@ public final class TestBinaryTree extends TestCase { assertTrue(!m.keySet().containsAll(c2)); m = new BinaryTree(); c1 = new LinkedList(); - c1.add(new Integer(-55)); + c1.add(Integer.valueOf(-55)); try { m.keySet().addAll(c1); @@ -869,7 +869,7 @@ public final class TestBinaryTree extends TestCase { } // reject incompatible values - m2.put("2", new Integer(2)); + m2.put("2", Integer.valueOf(2)); try { m = new BinaryTree(m2); @@ -881,7 +881,7 @@ public final class TestBinaryTree extends TestCase { // reject incompatible keys m2.remove("2"); - m2.put(new Integer(2), "bad key"); + m2.put(Integer.valueOf(2), "bad key"); try { m = new BinaryTree(m2); @@ -973,7 +973,7 @@ public final class TestBinaryTree extends TestCase { catch (ClassCastException ignored) { } - assertNull(m.remove(new Integer(-1))); + assertNull(m.remove(Integer.valueOf(-1))); try { m.removeValue("foo"); @@ -1135,7 +1135,7 @@ public final class TestBinaryTree extends TestCase { Collection c1 = new LinkedList(); Collection c2 = new LinkedList(); - c2.add(new Integer(-99)); + c2.add(Integer.valueOf(-99)); for (int k = 0; k < nodes.length; k++) { m.put(nodes[ k ].getKey(), nodes[ k ]); @@ -1146,7 +1146,7 @@ public final class TestBinaryTree extends TestCase { assertTrue(!m.keySetByValue().containsAll(c2)); m = new BinaryTree(); c1 = new LinkedList(); - c1.add(new Integer(-55)); + c1.add(Integer.valueOf(-55)); try { m.keySetByValue().addAll(c1); @@ -1390,7 +1390,7 @@ public final class TestBinaryTree extends TestCase { } for (int k = 0; k < m.size(); k++) { - assertTrue(s.contains(new Integer(k))); + assertTrue(s.contains(Integer.valueOf(k))); } int count = 0; @@ -1616,7 +1616,7 @@ public final class TestBinaryTree extends TestCase { } for (int k = 0; k < m.size(); k++) { - assertTrue(s.contains(new Integer(k))); + assertTrue(s.contains(Integer.valueOf(k))); } int count = 0; diff --git a/src/testcases/org/apache/poi/util/TestPOILogger.java b/src/testcases/org/apache/poi/util/TestPOILogger.java index 90732d3637..a3d34fac17 100644 --- a/src/testcases/org/apache/poi/util/TestPOILogger.java +++ b/src/testcases/org/apache/poi/util/TestPOILogger.java @@ -39,8 +39,8 @@ public final class TestPOILogger extends TestCase { POILogger log = POILogFactory.getLogger( "foo" ); - log.log( POILogger.WARN, "Test = ", new Integer( 1 ) ); - log.logFormatted( POILogger.ERROR, "Test param 1 = %, param 2 = %", "2", new Integer( 3 ) ); + log.log( POILogger.WARN, "Test = ", Integer.valueOf( 1 ) ); + log.logFormatted( POILogger.ERROR, "Test param 1 = %, param 2 = %", "2", Integer.valueOf( 3 ) ); log.logFormatted( POILogger.ERROR, "Test param 1 = %, param 2 = %", new int[]{4, 5} ); log.logFormatted( POILogger.ERROR, "Test param 1 = %1.1, param 2 = %0.1", new double[]{4, 5.23} ); diff --git a/src/testcases/org/apache/poi/util/TestStringUtil.java b/src/testcases/org/apache/poi/util/TestStringUtil.java index abfba6c297..e05fe0611a 100644 --- a/src/testcases/org/apache/poi/util/TestStringUtil.java +++ b/src/testcases/org/apache/poi/util/TestStringUtil.java @@ -60,11 +60,11 @@ public final class TestStringUtil extends TestCase { (byte) 'r', (byte) 'l', (byte) 'd', (byte) 0xAE }; String input; - try { - input = new String( expected_output, StringUtil.getPreferredEncoding() ); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); - } + try { + input = new String( expected_output, StringUtil.getPreferredEncoding() ); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } StringUtil.putCompressedUnicode( input, output, 0 ); for ( int j = 0; j < expected_output.length; j++ ) @@ -129,57 +129,31 @@ public final class TestStringUtil extends TestCase { } public void testFormat() { - assertEquals( "This is a test " + fmt( 1.2345, 2, 2 ), - StringUtil.format( "This is a test %2.2", new Object[] - { - new Double( 1.2345 ) - } ) ); - assertEquals( "This is a test " + fmt( 1.2345, -1, 3 ), - StringUtil.format( "This is a test %.3", new Object[] - { - new Double( 1.2345 ) - } ) ); - assertEquals( "This is a great test " + fmt( 1.2345, -1, 3 ), - StringUtil.format( "This is a % test %.3", new Object[] - { - "great", new Double( 1.2345 ) - } ) ); - assertEquals( "This is a test 1", - StringUtil.format( "This is a test %", new Object[] - { - new Integer( 1 ) - } ) ); - assertEquals( "This is a test 1", - StringUtil.format( "This is a test %", new Object[] - { - new Integer( 1 ), new Integer( 1 ) - } ) ); - assertEquals( "This is a test 1.x", - StringUtil.format( "This is a test %1.x", new Object[] - { - new Integer( 1 ) - } ) ); - assertEquals( "This is a test ?missing data?1.x", - StringUtil.format( "This is a test %1.x", new Object[] - { - } ) ); - assertEquals( "This is a test %1.x", - StringUtil.format( "This is a test \\%1.x", new Object[] - { - } ) ); + + confirm("This is a test " + fmt(1.2345, 2, 2), "This is a test %2.2", new Double(1.2345)); + confirm("This is a test " + fmt(1.2345, -1, 3), "This is a test %.3", new Double(1.2345)); + confirm("This is a great test " + fmt(1.2345, -1, 3), + "This is a % test %.3", "great", new Double(1.2345)); + confirm("This is a test 1", "This is a test %", Integer.valueOf(1)); + confirm("This is a test 1", "This is a test %", Integer.valueOf(1), Integer.valueOf(1)); + confirm("This is a test 1.x", "This is a test %1.x", Integer.valueOf(1)); + confirm("This is a test ?missing data?1.x", "This is a test %1.x"); + confirm("This is a test %1.x", "This is a test \\%1.x"); } + private static void confirm(String expectedResult, String fmtString, Object ... params) { + String actualResult = StringUtil.format(fmtString, params); + assertEquals(expectedResult, actualResult); + } private static String fmt(double num, int minIntDigits, int maxFracDigitis) { NumberFormat nf = NumberFormat.getInstance(); - if ( minIntDigits != -1 ) - { - nf.setMinimumIntegerDigits( minIntDigits ); + if (minIntDigits != -1) { + nf.setMinimumIntegerDigits(minIntDigits); } - if ( maxFracDigitis != -1 ) - { - nf.setMaximumFractionDigits( maxFracDigitis ); + if (maxFracDigitis != -1) { + nf.setMaximumFractionDigits(maxFracDigitis); } return nf.format( num ); |