diff options
author | Andreas Beeker <kiwiwings@apache.org> | 2021-10-18 22:35:17 +0000 |
---|---|---|
committer | Andreas Beeker <kiwiwings@apache.org> | 2021-10-18 22:35:17 +0000 |
commit | 3c3154ea8c330833fc38bd2144018f09a7d56b09 (patch) | |
tree | 89fd43d1280fa4865fe7f0fd4b821b5ad148178c /poi-scratchpad | |
parent | 646fb8c69080d191256468168ce63e1d3cb81c2d (diff) | |
download | poi-3c3154ea8c330833fc38bd2144018f09a7d56b09.tar.gz poi-3c3154ea8c330833fc38bd2144018f09a7d56b09.zip |
sonar fixes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1894365 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'poi-scratchpad')
10 files changed, 100 insertions, 105 deletions
diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java index 5525cdf808..f13991370c 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/extractor/TestExtractor.java @@ -165,7 +165,7 @@ public final class TestExtractor { assertNotNull(nText); // Notes record were corrupt, so don't expect any - assertEquals(nText.length(), 0); + assertEquals(0, nText.length()); // Slide records were fine assertContains(text, "Using Disease Surveillance and Response"); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestShapes.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestShapes.java index 84af931507..2b7cbb240b 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestShapes.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/model/TestShapes.java @@ -116,7 +116,7 @@ public final class TestShapes { String text = txtbox.getText(); assertNotNull(text); - assertEquals(txtbox.getTextParagraphs().get(0).getTextRuns().size(), 1); + assertEquals(1, txtbox.getTextParagraphs().get(0).getTextRuns().size()); HSLFTextRun rt = txtbox.getTextParagraphs().get(0).getTextRuns().get(0); switch (text) { diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExControl.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExControl.java index 2b1cfa3bda..fc8c353e33 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExControl.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExControl.java @@ -80,9 +80,9 @@ public final class TestExControl { ExOleObjAtom oleObj = record.getExOleObjAtom(); assertNotNull(oleObj); - assertEquals(oleObj.getDrawAspect(), ExOleObjAtom.DRAW_ASPECT_VISIBLE); - assertEquals(oleObj.getType(), ExOleObjAtom.TYPE_CONTROL); - assertEquals(oleObj.getSubType(), ExOleObjAtom.SUBTYPE_DEFAULT); + assertEquals(ExOleObjAtom.DRAW_ASPECT_VISIBLE, oleObj.getDrawAspect()); + assertEquals(ExOleObjAtom.TYPE_CONTROL, oleObj.getType()); + assertEquals(ExOleObjAtom.SUBTYPE_DEFAULT, oleObj.getSubType()); assertEquals("Shockwave Flash Object", record.getMenuName()); assertEquals("ShockwaveFlash.ShockwaveFlash.9", record.getProgId()); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjAtom.java index 01d72f3265..337f6f5307 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestExOleObjAtom.java @@ -38,12 +38,13 @@ public final class TestExOleObjAtom { ExOleObjAtom record = new ExOleObjAtom(data, 0, data.length); assertEquals(RecordTypes.ExOleObjAtom.typeID, record.getRecordType()); - assertEquals(record.getDrawAspect(), ExOleObjAtom.DRAW_ASPECT_VISIBLE); - assertEquals(record.getType(), ExOleObjAtom.TYPE_CONTROL); - assertEquals(record.getObjID(), 1); - assertEquals(record.getSubType(), ExOleObjAtom.SUBTYPE_DEFAULT); - assertEquals(record.getObjStgDataRef(), 2); - assertEquals(record.getOptions(), 1283584); //ther meaning is unknown + assertEquals(ExOleObjAtom.DRAW_ASPECT_VISIBLE, record.getDrawAspect()); + assertEquals(ExOleObjAtom.TYPE_CONTROL, record.getType()); + assertEquals(1, record.getObjID()); + assertEquals(ExOleObjAtom.SUBTYPE_DEFAULT, record.getSubType()); + assertEquals(2, record.getObjStgDataRef()); + // the meaning is unknown + assertEquals(1283584, record.getOptions()); } @Test diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestFontCollection.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestFontCollection.java index 3592100af6..a15fa80016 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestFontCollection.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestFontCollection.java @@ -55,28 +55,28 @@ public final class TestFontCollection { void testFonts() { FontCollection fonts = new FontCollection(data, 0, data.length); Record[] child = fonts.getChildRecords(); - assertEquals(child.length, 1); + assertEquals(1, child.length); FontEntityAtom fnt = (FontEntityAtom)child[0]; - assertEquals(fnt.getFontName(), "Times New Roman"); + assertEquals("Times New Roman", fnt.getFontName()); } @Test void testAddFont() { FontCollection fonts = new FontCollection(data, 0, data.length); HSLFFontInfo fi = fonts.addFont(HSLFFontInfoPredefined.TIMES_NEW_ROMAN); - assertEquals((int)fi.getIndex(), 0); + assertEquals(0, (int)fi.getIndex()); fi = fonts.addFont(new HSLFFontInfo("Helvetica")); - assertEquals((int)fi.getIndex(), 1); + assertEquals(1, (int)fi.getIndex()); fi = fonts.addFont(HSLFFontInfoPredefined.ARIAL); - assertEquals((int)fi.getIndex(), 2); + assertEquals(2, (int)fi.getIndex()); //the font being added twice fi = fonts.addFont(HSLFFontInfoPredefined.ARIAL); - assertEquals((int)fi.getIndex(), 2); + assertEquals(2, (int)fi.getIndex()); // Font collection should contain 3 fonts Record[] child = fonts.getChildRecords(); - assertEquals(child.length, 3); + assertEquals(3, child.length); // Check we get the right font name for the indicies fi = fonts.getFontInfo(0); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextRulerAtom.java b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextRulerAtom.java index 2a64d4fc21..e1a08b6e09 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextRulerAtom.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hslf/record/TestTextRulerAtom.java @@ -45,8 +45,8 @@ public final class TestTextRulerAtom { @Test void testReadRuler() { TextRulerAtom ruler = new TextRulerAtom(data_1, 0, data_1.length); - assertEquals(ruler.getNumberOfLevels(), 0); - assertEquals(ruler.getDefaultTabSize(), 0); + assertEquals(0, ruler.getNumberOfLevels()); + assertEquals(0, ruler.getDefaultTabSize()); List<HSLFTabStop> tabStops = ruler.getTabStops(); assertNotNull(tabStops); diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java index a11ba12c90..c5395232dc 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hsmf/TestExtractEmbeddedMSG.java @@ -102,7 +102,7 @@ public class TestExtractEmbeddedMSG { expectedMessageDate.set(Calendar.MILLISECOND, 0); assertEquals(expectedMessageDate.getTimeInMillis(), messageDate.getTimeInMillis()); // test variable length property - assertEquals(msg.getSubject(), "Test Attachment"); + assertEquals("Test Attachment", msg.getSubject()); } private POIFSFileSystem rebuildFromAttached(MAPIMessage attachedMsg) throws IOException { diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestPlexOfCps.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestPlexOfCps.java index 23a4c28777..ef467516e0 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestPlexOfCps.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/model/TestPlexOfCps.java @@ -26,53 +26,51 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public final class TestPlexOfCps { - private PlexOfCps _plexOfCps; - private HWPFDocFixture _hWPFDocFixture; + private PlexOfCps _plexOfCps; + private HWPFDocFixture _hWPFDocFixture; - @Test - void testWriteRead() { - _plexOfCps = new PlexOfCps(4); + @Test + void testWriteRead() { + _plexOfCps = new PlexOfCps(4); - int last = 0; - for (int x = 0; x < 110; x++) - { - byte[] intHolder = new byte[4]; - int span = (int)(110.0f * Math.random()); - LittleEndian.putInt(intHolder, 0, span); - _plexOfCps.addProperty(new GenericPropertyNode(last, last + span, intHolder)); - last += span; - } + int last = 0; + for (int x = 0; x < 110; x++) { + byte[] intHolder = new byte[4]; + int span = (int) (110.0f * Math.random()); + LittleEndian.putInt(intHolder, 0, span); + _plexOfCps.addProperty(new GenericPropertyNode(last, last + span, intHolder)); + last += span; + } - byte[] output = _plexOfCps.toByteArray(); - _plexOfCps = new PlexOfCps(output, 0, output.length, 4); - int len = _plexOfCps.length(); - assertEquals(len, 110); + byte[] output = _plexOfCps.toByteArray(); + _plexOfCps = new PlexOfCps(output, 0, output.length, 4); + int len = _plexOfCps.length(); + assertEquals(110, len); - last = 0; - for (int x = 0; x < len; x++) - { - GenericPropertyNode node = _plexOfCps.getProperty(x); - assertEquals(node.getStart(), last); - last = node.getEnd(); - int span = LittleEndian.getInt(node.getBytes()); - assertEquals(node.getEnd()-node.getStart(), span); + last = 0; + for (int x = 0; x < len; x++) { + GenericPropertyNode node = _plexOfCps.getProperty(x); + assertEquals(node.getStart(), last); + last = node.getEnd(); + int span = LittleEndian.getInt(node.getBytes()); + assertEquals(node.getEnd() - node.getStart(), span); + } } - } - @BeforeEach - void setUp() throws Exception { - /**@todo verify the constructors*/ - _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE); + @BeforeEach + void setUp() throws Exception { + /* @todo verify the constructors*/ + _hWPFDocFixture = new HWPFDocFixture(this, HWPFDocFixture.DEFAULT_TEST_FILE); - _hWPFDocFixture.setUp(); - } + _hWPFDocFixture.setUp(); + } - @AfterEach - void tearDown() throws Exception { - _plexOfCps = null; - _hWPFDocFixture.tearDown(); + @AfterEach + void tearDown() { + _plexOfCps = null; + _hWPFDocFixture.tearDown(); - _hWPFDocFixture = null; - } + _hWPFDocFixture = null; + } } diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestPictures.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestPictures.java index 61e4ced097..b792289282 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestPictures.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestPictures.java @@ -52,9 +52,8 @@ public final class TestPictures { List<Picture> pics = doc.getPicturesTable().getAllPictures(); assertNotNull(pics); - assertEquals(pics.size(), 2); - for (int i = 0; i < pics.size(); i++) { - Picture pic = pics.get(i); + assertEquals(2, pics.size()); + for (Picture pic : pics) { assertNotNull(pic.suggestFileExtension()); assertNotNull(pic.suggestFullFileName()); } @@ -289,7 +288,6 @@ public final class TestPictures { assertEquals(0, plain8s); } - @SuppressWarnings("deprecation") @Test void testCroppedPictures() { HWPFDocument doc = openSampleFile("testCroppedPictures.doc"); @@ -334,40 +332,40 @@ public final class TestPictures { } @Test - void testPictureWithAlternativeText() { - HWPFDocument document = openSampleFile("Picture_Alternative_Text.doc"); - PicturesTable pictureTable = document.getPicturesTable(); - Picture picture = pictureTable.getAllPictures().get(0); + void testPictureWithAlternativeText() throws IOException { + try (HWPFDocument document = openSampleFile("Picture_Alternative_Text.doc")) { + PicturesTable pictureTable = document.getPicturesTable(); + Picture picture = pictureTable.getAllPictures().get(0); - assertEquals("This is the alternative text for the picture.", picture.getDescription()); + assertEquals("This is the alternative text for the picture.", picture.getDescription()); + } } @Disabled("This bug is not fixed yet") @Test void test58804_1() throws Exception { - HWPFDocument docA = openSampleFile("58804_1.doc"); - - expectImages(docA, 1); - - HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA); + try (HWPFDocument docA = openSampleFile("58804_1.doc")) { + expectImages(docA, 1); - try (OutputStream out = new FileOutputStream("/tmp/58804_1_out.doc")) { - docB.write(out); + try (HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA); + OutputStream out = new FileOutputStream("/tmp/58804_1_out.doc")) { + docB.write(out); + expectImages(docB, 1); + } } - - expectImages(docB, 1); } @Disabled("This bug is not fixed yet") @Test - void test58804() throws Exception { - HWPFDocument docA = openSampleFile("58804.doc"); - - expectImages(docA, 7); + void test58804() throws IOException { + try (HWPFDocument docA = openSampleFile("58804.doc")) { + expectImages(docA, 7); - HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA); + try (HWPFDocument docB = HWPFTestDataSamples.writeOutAndReadBack(docA)) { + expectImages(docB, 7); + } + } - expectImages(docB, 7); } private void expectImages(HWPFDocument docA, int expectedCount) { diff --git a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRange.java b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRange.java index 7d6c72fc6e..4965fc44b0 100644 --- a/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRange.java +++ b/poi-scratchpad/src/test/java/org/apache/poi/hwpf/usermodel/TestRange.java @@ -64,33 +64,31 @@ public final class TestRange { @Test void testBug46817() throws IOException { - InputStream is = SAMPLES.openResourceAsStream( "Bug46817.doc" ); - HWPFDocument hwpfDocument = new HWPFDocument( is ); - is.close(); + try (InputStream is = SAMPLES.openResourceAsStream("Bug46817.doc"); + HWPFDocument hwpfDocument = new HWPFDocument(is)) { - final List<SEPX> sections = hwpfDocument.getSectionTable() - .getSections(); - assertEquals( sections.size(), 1 ); + final List<SEPX> sections = hwpfDocument.getSectionTable().getSections(); + assertEquals( 1, sections.size() ); - // whole document, including additional text from shape - SEPX sepx = sections.get( 0 ); - assertEquals( sepx.getStart(), 0 ); - assertEquals( sepx.getEnd(), 1428 ); + // whole document, including additional text from shape + SEPX sepx = sections.get( 0 ); + assertEquals( 0, sepx.getStart() ); + assertEquals( 1428, sepx.getEnd() ); - // only main range - Range range = hwpfDocument.getRange(); - assertEquals( range.getStartOffset(), 0 ); - assertEquals( range.getEndOffset(), 766 ); + // only main range + Range range = hwpfDocument.getRange(); + assertEquals( 0, range.getStartOffset() ); + assertEquals( 766, range.getEndOffset() ); - Paragraph lastInMainRange = range.getParagraph( range.numParagraphs() - 1); - assertTrue( lastInMainRange.getEndOffset() <= 766 ); + Paragraph lastInMainRange = range.getParagraph( range.numParagraphs() - 1); + assertTrue( lastInMainRange.getEndOffset() <= 766 ); - Section section = range.getSection( 0 ); - assertTrue( section.getEndOffset() <= 766 ); + Section section = range.getSection( 0 ); + assertTrue( section.getEndOffset() <= 766 ); - Paragraph lastInMainSection = section.getParagraph( section + Paragraph lastInMainSection = section.getParagraph( section .numParagraphs() - 1); - assertTrue( lastInMainSection.getEndOffset() <= 766 ); - hwpfDocument.close(); + assertTrue( lastInMainSection.getEndOffset() <= 766 ); + } } } |