Author: yurize
Date: Sun Dec 16 21:26:49 2012
New Revision: 1422694

URL: http://svn.apache.org/viewvc?rev=1422694&view=rev
Log:
Fixes failed tests in AttachmentStoreTest. By Nikolay Volnov
https://reviews.apache.org/r/8254

Modified:
    
incubator/wave/trunk/test/org/waveprotocol/box/server/persistence/AttachmentStoreTestBase.java

Modified: 
incubator/wave/trunk/test/org/waveprotocol/box/server/persistence/AttachmentStoreTestBase.java
URL: 
http://svn.apache.org/viewvc/incubator/wave/trunk/test/org/waveprotocol/box/server/persistence/AttachmentStoreTestBase.java?rev=1422694&r1=1422693&r2=1422694&view=diff
==============================================================================
--- 
incubator/wave/trunk/test/org/waveprotocol/box/server/persistence/AttachmentStoreTestBase.java
 (original)
+++ 
incubator/wave/trunk/test/org/waveprotocol/box/server/persistence/AttachmentStoreTestBase.java
 Sun Dec 16 21:26:49 2012
@@ -22,6 +22,7 @@ package org.waveprotocol.box.server.pers
 import junit.framework.TestCase;
 
 import org.waveprotocol.box.server.persistence.AttachmentStore.AttachmentData;
+import org.waveprotocol.wave.media.model.AttachmentId;
 
 import java.io.BufferedReader;
 import java.io.ByteArrayInputStream;
@@ -29,7 +30,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
-import org.waveprotocol.wave.media.model.AttachmentId;
 
 /**
  * Test cases for the Attachment Stores.
@@ -80,8 +80,13 @@ public abstract class AttachmentStoreTes
     AttachmentData data = store.getAttachment(id);
 
     ByteArrayOutputStream stream = new ByteArrayOutputStream();
-    AttachmentUtil.writeTo(data.getInputStream(), stream);
-    assertEquals(testData, stream.toString("UTF-8"));
+    InputStream io = data.getInputStream();
+    try {
+      AttachmentUtil.writeTo(io, stream);
+      assertEquals(testData, stream.toString("UTF-8"));
+    } finally {
+      io.close();
+    }
   }
 
   public void testAttachmentHasWorkingInputStream() throws Exception {
@@ -94,14 +99,17 @@ public abstract class AttachmentStoreTes
 
     StringBuilder builder = new StringBuilder();
     String line;
-    while ((line = reader.readLine()) != null) {
-      // This little snippet will discard any "\n" characters, but it shouldn't
-      // matter.
-      builder.append(line);
+    try {
+      while ((line = reader.readLine()) != null) {
+        // This little snippet will discard any "\n" characters, but it 
shouldn't
+        // matter.
+        builder.append(line);
+      }
+    } finally {
+      reader.close();
     }
 
     assertEquals(testData, builder.toString());
-    reader.close();
   }
 
   public void testGetStreamReturnsNewStream() throws Exception {
@@ -112,18 +120,24 @@ public abstract class AttachmentStoreTes
 
     InputStream is1 = data.getInputStream();
     InputStream is2 = data.getInputStream();
-    assertNotSame(is1, is2);
+    InputStream is3 = null;
+    try {
+      assertNotSame(is1, is2);
 
-    int firstByte = is1.read();
-    assertSame(firstByte, is2.read());
+      int firstByte = is1.read();
+      assertSame(firstByte, is2.read());
 
-    // Check that a new input stream created now still has the same first byte.
-    InputStream is3 = data.getInputStream();
-    assertSame(firstByte, is3.read());
-
-    is1.close();
-    is2.close();
-    is3.close();
+      // Check that a new input stream created now still has the same first
+      // byte.
+      is3 = data.getInputStream();
+      assertSame(firstByte, is3.read());
+    } finally {
+      is1.close();
+      is2.close();
+      if (is3 != null) {
+        is3.close();
+      }
+    }
   }
 
   public void testOverwriteAttachmentThrowsException() throws Exception {
@@ -165,7 +179,12 @@ public abstract class AttachmentStoreTes
 
   protected String dataToString(AttachmentData data) throws IOException {
     ByteArrayOutputStream out = new ByteArrayOutputStream();
-    AttachmentUtil.writeTo(data.getInputStream(), out);
+    InputStream io = data.getInputStream();
+    try {
+      AttachmentUtil.writeTo(io, out);
+    } finally {
+      io.close();
+    }
     return out.toString("UTF-8");
   }
-}
+}
\ No newline at end of file


Reply via email to