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;
};
private static SimpleDateFormat sdf;
-
+
@BeforeClass
public static void initDateFormat() {
sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS", Locale.ROOT);
@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);
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);
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();
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());
}
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);
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());
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());
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());
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());
}
@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;
}
@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
* 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,
* </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,
// the bitmask text properties will sanitize the bytes and thus the bytes differ
byte[] exptected = data.clone();
exptected[18] = 0;
-
+
doReadWrite(data, exptected, length);
}
-
}