diff options
author | Dominik Stadler <centic@apache.org> | 2014-06-11 20:36:30 +0000 |
---|---|---|
committer | Dominik Stadler <centic@apache.org> | 2014-06-11 20:36:30 +0000 |
commit | 427d733469c6a0c7293b60debeb6622d39d19238 (patch) | |
tree | 55813e78030a3a3bd6f28eeb2fd8e5cf237be6eb /src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java | |
parent | 267d70569ade0505d90564648979351ced3f24c6 (diff) | |
download | poi-427d733469c6a0c7293b60debeb6622d39d19238.tar.gz poi-427d733469c6a0c7293b60debeb6622d39d19238.zip |
Add missing @Overrides, reformat some files, increase coverage slightly,
comments, fix Eclipse warnings and add close() calls in some tests and
in HMEFMessage() to close files during tests correctly.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1602008 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java')
-rw-r--r-- | src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java | 60 |
1 files changed, 32 insertions, 28 deletions
diff --git a/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java b/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java index 674a3a9fdb..c010a6bf28 100644 --- a/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java +++ b/src/scratchpad/testcases/org/apache/poi/hmef/TestCompressedRTF.java @@ -18,6 +18,7 @@ package org.apache.poi.hmef; import java.io.ByteArrayInputStream; +import java.io.InputStream; import junit.framework.TestCase; @@ -157,34 +158,37 @@ public final class TestCompressedRTF extends TestCase { assertNotNull(attr); MAPIRtfAttribute rtfAttr = (MAPIRtfAttribute)attr; - byte[] expected = IOUtils.toByteArray( - _samples.openResourceAsStream("quick-contents/message.rtf") - ); - - CompressedRTF comp = new CompressedRTF(); - byte[] data = rtfAttr.getRawData(); - byte[] decomp = comp.decompress(new ByteArrayInputStream(data)); - - // Check the length was as expected - assertEquals(data.length, comp.getCompressedSize() + 16); - assertEquals(expected.length, comp.getDeCompressedSize()); - - // Will have been padded though - assertEquals(expected.length+2, decomp.length); - byte[] tmp = new byte[expected.length]; - System.arraycopy(decomp, 0, tmp, 0, tmp.length); - decomp = tmp; - - // By byte - assertEquals(expected.length, decomp.length); - for(int i=0; i<expected.length; i++) { - assertEquals(expected[i], decomp[i]); + InputStream stream = _samples.openResourceAsStream("quick-contents/message.rtf"); + try { + byte[] expected = IOUtils.toByteArray(stream); + + CompressedRTF comp = new CompressedRTF(); + byte[] data = rtfAttr.getRawData(); + byte[] decomp = comp.decompress(new ByteArrayInputStream(data)); + + // Check the length was as expected + assertEquals(data.length, comp.getCompressedSize() + 16); + assertEquals(expected.length, comp.getDeCompressedSize()); + + // Will have been padded though + assertEquals(expected.length+2, decomp.length); + byte[] tmp = new byte[expected.length]; + System.arraycopy(decomp, 0, tmp, 0, tmp.length); + decomp = tmp; + + // By byte + assertEquals(expected.length, decomp.length); + for(int i=0; i<expected.length; i++) { + assertEquals(expected[i], decomp[i]); + } + + // By String + String expString = new String(expected, "ASCII"); + String decompStr = rtfAttr.getDataString(); + assertEquals(expString.length(), decompStr.length()); + assertEquals(expString, decompStr); + } finally { + stream.close(); } - - // By String - String expString = new String(expected, "ASCII"); - String decompStr = rtfAttr.getDataString(); - assertEquals(expString.length(), decompStr.length()); - assertEquals(expString, decompStr); } } |