Fix Sonar issues and IDE warnings

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1882842 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2020-10-25 16:07:30 +00:00
parent 02355346db
commit 8089682957
4 changed files with 47 additions and 57 deletions

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());
}
}
}

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 {
// Check bytes weren't the same
boolean equals = true;
for(int i=0; i<data_a.length; i++) {
assertEquals(data_a[i],data_b[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);

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;
@ -102,7 +102,7 @@ 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
@ -191,14 +191,14 @@ public final class TestComment2000 {
assertEquals(cn.getAuthorInitials(), cb.getAuthorInitials());
// Check bytes weren't the same
try {
boolean equals = true;
for(int i=0; i<data_a.length; i++) {
assertEquals(data_a[i],data_b[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();

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());
}
@ -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);
}
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,
@ -792,5 +783,4 @@ public final class TestStyleTextPropAtom {
doReadWrite(data, exptected, length);
}
}