diff --git a/api/src/test/java/org/openmrs/obs/BinaryStreamHandlerTest.java b/api/src/test/java/org/openmrs/obs/BinaryStreamHandlerTest.java index 2a3c6bcd0854..140fe8b1d32f 100644 --- a/api/src/test/java/org/openmrs/obs/BinaryStreamHandlerTest.java +++ b/api/src/test/java/org/openmrs/obs/BinaryStreamHandlerTest.java @@ -17,6 +17,7 @@ import java.io.ByteArrayInputStream; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Path; import org.junit.jupiter.api.BeforeEach; @@ -84,6 +85,8 @@ public void saveObs_shouldRetrieveCorrectMimetype() throws IOException { String filename = "TestingComplexObsSaving"; byte[] content = "Teststring".getBytes(); + Obs complexObs1 = null; + Obs complexObs2 = null; try (ByteArrayInputStream byteIn = new ByteArrayInputStream(content)) { ComplexData complexData = new ComplexData(filename, byteIn); // Construct 2 Obs to also cover the case where the filename exists already @@ -95,11 +98,14 @@ public void saveObs_shouldRetrieveCorrectMimetype() throws IOException { handler.saveObs(obs1); handler.saveObs(obs2); - Obs complexObs1 = handler.getObs(obs1, "RAW_VIEW"); - Obs complexObs2 = handler.getObs(obs2, "RAW_VIEW"); + complexObs1 = handler.getObs(obs1, "RAW_VIEW"); + complexObs2 = handler.getObs(obs2, "RAW_VIEW"); assertEquals(complexObs1.getComplexData().getMimeType(), mimetype); assertEquals(complexObs2.getComplexData().getMimeType(), mimetype); + } finally { + ((InputStream) complexObs1.getComplexData().getData()).close(); + ((InputStream) complexObs1.getComplexData().getData()).close(); } } } diff --git a/api/src/test/java/org/openmrs/obs/MediaHandlerTest.java b/api/src/test/java/org/openmrs/obs/MediaHandlerTest.java index 041c3d963cc0..a2d8930c8cf9 100644 --- a/api/src/test/java/org/openmrs/obs/MediaHandlerTest.java +++ b/api/src/test/java/org/openmrs/obs/MediaHandlerTest.java @@ -18,6 +18,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Path; import org.junit.jupiter.api.BeforeEach; @@ -82,7 +83,9 @@ public void saveObs_shouldRetrieveCorrectMimetype() throws IOException { File sourceFile = new File( "src" + File.separator + "test" + File.separator + "resources" + File.separator + "ComplexObsTestAudio.mp3"); - + + Obs complexObs1 = null; + Obs complexObs2 = null; try (FileInputStream in1 = new FileInputStream(sourceFile); FileInputStream in2 = new FileInputStream(sourceFile) ) { @@ -98,11 +101,14 @@ public void saveObs_shouldRetrieveCorrectMimetype() throws IOException { handler.saveObs(obs1); handler.saveObs(obs2); - Obs complexObs1 = handler.getObs(obs1, "RAW_VIEW"); - Obs complexObs2 = handler.getObs(obs2, "RAW_VIEW"); + complexObs1 = handler.getObs(obs1, "RAW_VIEW"); + complexObs2 = handler.getObs(obs2, "RAW_VIEW"); assertEquals( "audio/mpeg", complexObs1.getComplexData().getMimeType()); assertEquals("audio/mpeg", complexObs2.getComplexData().getMimeType()); + } finally { + ((InputStream) complexObs1.getComplexData().getData()).close(); + ((InputStream) complexObs1.getComplexData().getData()).close(); } } }