Browse Source

Fix Sonar issues and IDE warnings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1882842 13f79535-47bb-0310-9956-ffa450edef68
tags/before_ooxml_3rd_edition
Dominik Stadler 3 years ago
parent
commit
8089682957

+ 2
- 3
src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTableColumn.java View File

@@ -71,9 +71,8 @@ public final class TestXSSFTableColumn {

assertNotNull(tableColumns.get(0).getXmlColumnPr());
assertNull(tableColumns.get(1).getXmlColumnPr()); // unmapped column
assertNotNull(tableColumns.get(2).getColumnIndex());
assertNotNull(tableColumns.get(3).getColumnIndex());

assertEquals(2, tableColumns.get(2).getColumnIndex());
assertEquals(3, tableColumns.get(3).getColumnIndex());
}
}
}

+ 8
- 7
src/scratchpad/testcases/org/apache/poi/hslf/record/TestCString.java View File

@@ -19,7 +19,7 @@ package org.apache.poi.hslf.record;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.junit.Assert.assertFalse;

import java.io.ByteArrayOutputStream;

@@ -97,14 +97,15 @@ public final class TestCString {
ca.setText("Comments");
ca.setOptions(0x10);

try {
for(int i=0; i<data_a.length; i++) {
assertEquals(data_a[i],data_b[i]);
// Check bytes weren't the same
boolean equals = true;
for(int i=0; i<data_a.length; i++) {
if (data_a[i] != data_b[i]) {
equals = false;
break;
}
fail();
} catch(Error e) {
// Good, they're not the same
}
assertFalse("Arrays should not be equals", equals);

ByteArrayOutputStream baos = new ByteArrayOutputStream();
ca.writeOut(baos);

+ 13
- 13
src/scratchpad/testcases/org/apache/poi/hslf/record/TestComment2000.java View File

@@ -19,9 +19,9 @@ package org.apache.poi.hslf.record;


import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.ByteArrayOutputStream;
import java.text.SimpleDateFormat;
@@ -92,7 +92,7 @@ public final class TestComment2000 {
};

private static SimpleDateFormat sdf;
@BeforeClass
public static void initDateFormat() {
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.ROOT);
@@ -102,22 +102,22 @@ public final class TestComment2000 {
@Test
public void testRecordType() {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
assertEquals(12000l, ca.getRecordType());
assertEquals(12000L, ca.getRecordType());
}
@Test
public void testAuthor() {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
assertEquals("Dumbledore", ca.getAuthor());
assertEquals("D", ca.getAuthorInitials());
}
@Test
public void testText() {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
assertEquals("Yes, they certainly are, aren't they!", ca.getText());
}
@Test
public void testCommentAtom() throws Exception {
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
@@ -129,7 +129,7 @@ public final class TestComment2000 {
Date exp_a = sdf.parse("2006-01-24 10:26:15.205");
assertEquals(exp_a, c2a.getDate());
}
@Test
public void testCommentAtomB() throws Exception {
Comment2000 cb = new Comment2000(data_b, 0, data_b.length);
@@ -191,14 +191,14 @@ public final class TestComment2000 {
assertEquals(cn.getAuthorInitials(), cb.getAuthorInitials());

// Check bytes weren't the same
try {
for(int i=0; i<data_a.length; i++) {
assertEquals(data_a[i],data_b[i]);
boolean equals = true;
for(int i=0; i<data_a.length; i++) {
if (data_a[i] != data_b[i]) {
equals = false;
break;
}
fail();
} catch(Error e) {
// Good, they're not the same
}
assertFalse("Arrays should not be equals", equals);

// Check bytes are now the same
ByteArrayOutputStream baosa = new ByteArrayOutputStream();

+ 24
- 34
src/scratchpad/testcases/org/apache/poi/hslf/record/TestStyleTextPropAtom.java View File

@@ -143,9 +143,9 @@ public final class TestStyleTextPropAtom {
StyleTextPropAtom stpa = new StyleTextPropAtom(data_a,0,data_a.length);
StyleTextPropAtom stpb = new StyleTextPropAtom(data_b,0,data_b.length);
StyleTextPropAtom stpc = new StyleTextPropAtom(data_c,0,data_c.length);
assertEquals(4001l, stpa.getRecordType());
assertEquals(4001l, stpb.getRecordType());
assertEquals(4001l, stpc.getRecordType());
assertEquals(4001L, stpa.getRecordType());
assertEquals(4001L, stpb.getRecordType());
assertEquals(4001L, stpc.getRecordType());
}


@@ -392,12 +392,12 @@ public final class TestStyleTextPropAtom {
TextPropCollection b_ch_2 = b_ch_l.get(1);
TextPropCollection b_ch_3 = b_ch_l.get(2);
TextPropCollection b_ch_4 = b_ch_l.get(3);
assertNotNull(b_p_1);
assertNotNull(b_p_2);
assertNotNull(b_p_3);
assertNotNull(b_p_4);
assertNotNull(b_ch_1);
assertNotNull(b_ch_2);
assertNotNull(b_ch_3);
@@ -524,8 +524,7 @@ public final class TestStyleTextPropAtom {

tp = tpca.addWithName("font.size");
tp.setValue(20);
CharFlagsTextProp cftp = (CharFlagsTextProp)
tpca.addWithName("char_flags");
CharFlagsTextProp cftp = tpca.addWithName("char_flags");
assertEquals(0, cftp.getValue());
cftp.setSubValue(true, CharFlagsTextProp.BOLD_IDX);
assertEquals(1, cftp.getValue());
@@ -537,7 +536,7 @@ public final class TestStyleTextPropAtom {
tp.setValue(20);
tp = tpcb.addWithName("font.color");
tp.setValue(0x05000000);
cftp = (CharFlagsTextProp)tpcb.addWithName("char_flags");
cftp = tpcb.addWithName("char_flags");
cftp.setSubValue(true, CharFlagsTextProp.ITALIC_IDX);
assertEquals(2, cftp.getValue());

@@ -556,7 +555,7 @@ public final class TestStyleTextPropAtom {
tp.setValue(24);
tp = tpcd.addWithName("font.index");
tp.setValue(1);
cftp = (CharFlagsTextProp)tpcd.addWithName("char_flags");
cftp = tpcd.addWithName("char_flags");
cftp.setSubValue(true, CharFlagsTextProp.UNDERLINE_IDX);
assertEquals(4, cftp.getValue());

@@ -569,7 +568,7 @@ public final class TestStyleTextPropAtom {
tp.setValue(1);
tp = tpce.addWithName("font.color");
tp.setValue(0xfe0033ff);
cftp = (CharFlagsTextProp)tpce.addWithName("char_flags");
cftp = tpce.addWithName("char_flags");
cftp.setSubValue(true, CharFlagsTextProp.UNDERLINE_IDX);
assertEquals(4, cftp.getValue());

@@ -646,28 +645,28 @@ public final class TestStyleTextPropAtom {
}

@Test
public void testWriteA() {
public void testWriteA() throws IOException {
doReadWrite(data_a, -1);
}

@Test
public void testLoadWriteA() {
public void testLoadWriteA() throws IOException {
doReadWrite(data_b, data_b_text_len);
}


@Test
public void testWriteB() {
public void testWriteB() throws IOException {
doReadWrite(data_b, -1);
}

@Test
public void testLoadWriteB() {
public void testLoadWriteB() throws IOException {
doReadWrite(data_b, data_b_text_len);
}

@Test
public void testLoadWriteC() {
public void testLoadWriteC() throws IOException {
// BitMaskTextProperties will sanitize the output
byte[] expected = data_c.clone();
expected[56] = 0;
@@ -676,33 +675,25 @@ public final class TestStyleTextPropAtom {
}

@Test
public void testLoadWriteD() {
public void testLoadWriteD() throws IOException {
doReadWrite(data_d, data_d_text_len);
}

protected void doReadWrite(byte[] data, int textlen) {
protected void doReadWrite(byte[] data, int textlen) throws IOException {
doReadWrite(data, data, textlen);
}
protected void doReadWrite(byte[] data, byte[] expected, int textlen) {
protected void doReadWrite(byte[] data, byte[] expected, int textlen) throws IOException {
StyleTextPropAtom stpb = new StyleTextPropAtom(data, 0,data.length);
if(textlen != -1) stpb.setParentTextSize(textlen);

ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
stpb.writeOut(out);
} catch (IOException e) {
throw new RuntimeException(e);
}
stpb.writeOut(out);
byte[] bytes = out.toByteArray();

assertEquals(expected.length, bytes.length);
try {
assertArrayEquals(expected, bytes);
} catch (Throwable e){
//print hex dump if failed
assertEquals(HexDump.toHex(expected), HexDump.toHex(bytes));
}
assertArrayEquals("Had: " + HexDump.toHex(expected) + "\nand: " + HexDump.toHex(bytes),
expected, bytes);
}

@Test
@@ -743,7 +734,7 @@ public final class TestStyleTextPropAtom {
* Check the test data for Bug 42677.
*/
@Test
public void test42677() {
public void test42677() throws IOException {
int length = 18;
byte[] data = {
0x00, 0x00, (byte)0xA1, 0x0F, 0x28, 0x00, 0x00, 0x00,
@@ -769,7 +760,7 @@ public final class TestStyleTextPropAtom {
* </StyleTextPropAtom>
*/
@Test
public void test45815() {
public void test45815() throws IOException {
int length = 19;
byte[] data = {
0x00, 0x00, (byte)0xA1, 0x0F, 0x5E, 0x00, 0x00, 0x00, 0x14, 0x00,
@@ -789,8 +780,7 @@ public final class TestStyleTextPropAtom {
// the bitmask text properties will sanitize the bytes and thus the bytes differ
byte[] exptected = data.clone();
exptected[18] = 0;
doReadWrite(data, exptected, length);
}

}

Loading…
Cancel
Save