Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Waibel2015-05-24 05:23:41 -0400
committerFlorian Waibel2015-05-24 05:23:41 -0400
commitf5db4fbf1ade0b85baa642d372468bcfed849a21 (patch)
tree89ffd02b3ab3feb062869444d57411aab1f17943
parent5938d5d2d4f5069b49bac136eeb73026d1e623ef (diff)
downloadorg.eclipse.virgo.medic-f5db4fbf1ade0b85baa642d372468bcfed849a21.tar.gz
org.eclipse.virgo.medic-f5db4fbf1ade0b85baa642d372468bcfed849a21.tar.xz
org.eclipse.virgo.medic-f5db4fbf1ade0b85baa642d372468bcfed849a21.zip
Fixes resource leak(s) in JUnit test
-rw-r--r--org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/eventlog/impl/StandardMessageResolverTests.java29
1 files changed, 16 insertions, 13 deletions
diff --git a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/eventlog/impl/StandardMessageResolverTests.java b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/eventlog/impl/StandardMessageResolverTests.java
index 680f55c..3fd3366 100644
--- a/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/eventlog/impl/StandardMessageResolverTests.java
+++ b/org.eclipse.virgo.medic.core/src/test/java/org/eclipse/virgo/medic/eventlog/impl/StandardMessageResolverTests.java
@@ -23,13 +23,13 @@ import static org.junit.Assert.assertNull;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.Locale;
import java.util.PropertyResourceBundle;
import org.junit.Test;
-
import org.eclipse.virgo.medic.eventlog.impl.LocaleResolver;
import org.eclipse.virgo.medic.eventlog.impl.MessageResolver;
import org.eclipse.virgo.medic.eventlog.impl.PropertyResourceBundleResolver;
@@ -51,22 +51,25 @@ public class StandardMessageResolverTests {
@Test
public void resolve() throws FileNotFoundException, IOException {
-
- expect(this.localeResolver.getLocale()).andReturn(Locale.GERMAN);
- expect(this.resourceBundleResolver.getResourceBundles(this.primaryBundle, "EventLogMessages_de.properties")).andReturn(
- Arrays.asList(new PropertyResourceBundle(new FileInputStream("src/test/resources/messages.properties"))));
- replay(this.localeResolver, this.resourceBundleResolver);
- assertEquals("Bar", this.messageResolver.resolveLogEventMessage("ABC123"));
- verify(this.localeResolver, this.resourceBundleResolver);
+ try (InputStream messageProperties = new FileInputStream("src/test/resources/messages.properties")) {
+ expect(this.localeResolver.getLocale()).andReturn(Locale.GERMAN);
+ expect(this.resourceBundleResolver.getResourceBundles(this.primaryBundle, "EventLogMessages_de.properties")).andReturn(
+ Arrays.asList(new PropertyResourceBundle(messageProperties)));
+ replay(this.localeResolver, this.resourceBundleResolver);
+ assertEquals("Bar", this.messageResolver.resolveLogEventMessage("ABC123"));
+ verify(this.localeResolver, this.resourceBundleResolver);
+ }
}
@Test
public void resolveWithLocale() throws FileNotFoundException, IOException {
- expect(this.resourceBundleResolver.getResourceBundles(this.primaryBundle, "EventLogMessages_it.properties")).andReturn(
- Arrays.asList(new PropertyResourceBundle(new FileInputStream("src/test/resources/messages.properties"))));
- replay(this.localeResolver, this.resourceBundleResolver);
- assertEquals("Bar", this.messageResolver.resolveLogEventMessage("ABC123", Locale.ITALIAN));
- verify(this.localeResolver, this.resourceBundleResolver);
+ try (InputStream messageProperties = new FileInputStream("src/test/resources/messages.properties")) {
+ expect(this.resourceBundleResolver.getResourceBundles(this.primaryBundle, "EventLogMessages_it.properties")).andReturn(
+ Arrays.asList(new PropertyResourceBundle(messageProperties)));
+ replay(this.localeResolver, this.resourceBundleResolver);
+ assertEquals("Bar", this.messageResolver.resolveLogEventMessage("ABC123", Locale.ITALIAN));
+ verify(this.localeResolver, this.resourceBundleResolver);
+ }
}
@Test

Back to the top