TestComment2000public class TestComment2000 extends TestCase Tests that Comment2000 works properly.
TODO: Test Comment200Atom within |
Fields Summary |
---|
private byte[] | data_a | private byte[] | data_b | private SimpleDateFormat | sdf |
Methods Summary |
---|
public void | testAuthor()
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
assertEquals("Dumbledore", ca.getAuthor());
assertEquals("D", ca.getAuthorInitials());
| public void | testChange()
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
Comment2000 cb = new Comment2000(data_b, 0, data_b.length);
Comment2000 cn = new Comment2000();
ca.setAuthor("Hogwarts");
ca.setAuthorInitials("H");
ca.setText("Comments are fun things to add in, aren't they?");
cn.setAuthor("Hogwarts");
cn.setAuthorInitials("H");
cn.setText("Comments are fun things to add in, aren't they?");
// Change the Comment2000Atom
Comment2000Atom c2a = ca.getComment2000Atom();
Comment2000Atom c2n = cn.getComment2000Atom();
c2a.setNumber(1);
c2a.setXOffset(0x0a);
c2a.setYOffset(0x0a);
c2n.setNumber(1);
c2n.setXOffset(0x0a);
c2n.setYOffset(0x0a);
Date new_date = sdf.parse("2006-01-24 22:25:03.725");
c2a.setDate(new_date);
c2n.setDate(new_date);
// Check now the same
assertEquals(ca.getText(), cb.getText());
assertEquals(cn.getText(), cb.getText());
assertEquals(ca.getAuthor(), cb.getAuthor());
assertEquals(cn.getAuthor(), cb.getAuthor());
assertEquals(ca.getAuthorInitials(), cb.getAuthorInitials());
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]);
}
fail();
} catch(Error e) {
// Good, they're not the same
}
// Check bytes are now the same
ByteArrayOutputStream baosa = new ByteArrayOutputStream();
ByteArrayOutputStream baosn = new ByteArrayOutputStream();
ca.writeOut(baosa);
cn.writeOut(baosn);
byte[] ba = baosa.toByteArray();
byte[] bn = baosn.toByteArray();
// Should now be the same
assertEquals(data_b.length, ba.length);
for(int i=0; i<data_b.length; i++) {
assertEquals(data_b[i],ba[i]);
}
assertEquals(data_b.length, bn.length);
for(int i=0; i<data_b.length; i++) {
assertEquals(data_b[i],bn[i]);
}
| public void | testCommentAtom()
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
Comment2000Atom c2a = ca.getComment2000Atom();
assertEquals(1, c2a.getNumber());
assertEquals(0x92, c2a.getXOffset());
assertEquals(0x92, c2a.getYOffset());
Date exp_a = sdf.parse("2006-01-24 10:26:15.205");
assertEquals(exp_a, c2a.getDate());
| public void | testCommentAtomB()
Comment2000 cb = new Comment2000(data_b, 0, data_b.length);
Comment2000Atom c2b = cb.getComment2000Atom();
assertEquals(1, c2b.getNumber());
assertEquals(0x0a, c2b.getXOffset());
assertEquals(0x0a, c2b.getYOffset());
Date exp_b = sdf.parse("2006-01-24 22:25:03.725");
assertEquals(exp_b, c2b.getDate());
| public void | testRecordType()
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
assertEquals(12000l, ca.getRecordType());
| public void | testText()
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
assertEquals("Yes, they certainly are, aren't they!", ca.getText());
| public void | testWrite()
Comment2000 ca = new Comment2000(data_a, 0, data_a.length);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ca.writeOut(baos);
byte[] b = baos.toByteArray();
assertEquals(data_a.length, b.length);
for(int i=0; i<data_a.length; i++) {
assertEquals(data_a[i],b[i]);
}
|
|