Author: vyemialyanchyk
Date: 2009-04-08 08:59:32 -0400 (Wed, 08 Apr 2009)
New Revision: 14602
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/LaunchCC.properties
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/EclipseLaunchConsoleConfigurationPreferencesTest.java
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java
Log:
JBIDE-4138 - close fis in EclipseLaunchConsoleConfigurationPreferences.getProperties and
unit test
Modified:
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java
===================================================================
---
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java 2009-04-08
12:46:39 UTC (rev 14601)
+++
trunk/hibernatetools/plugins/org.hibernate.eclipse.console/src/org/hibernate/eclipse/console/EclipseLaunchConsoleConfigurationPreferences.java 2009-04-08
12:59:32 UTC (rev 14602)
@@ -164,14 +164,25 @@
public Properties getProperties() {
File propFile = getPropertyFile();
if(propFile==null) return null;
+ Properties p = new Properties();
+ FileInputStream fis = null;
try {
- Properties p = new Properties();
- p.load(new FileInputStream(propFile) );
- return p;
+ fis = new FileInputStream(propFile);
+ p.load(fis);
}
catch(IOException io) {
throw new
HibernateConsoleRuntimeException(HibernateConsoleMessages.EclipseLaunchConsoleConfigurationPreferences_could_not_load_property_file
+ propFile, io);
}
+ finally {
+ if (fis != null) {
+ try {
+ fis.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ return p;
}
public File getPropertyFile() {
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/LaunchCC.properties
===================================================================
--- trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/LaunchCC.properties
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/res/LaunchCC.properties 2009-04-08
12:59:32 UTC (rev 14602)
@@ -0,0 +1 @@
+org.hibernate.test = testValue
Added:
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/EclipseLaunchConsoleConfigurationPreferencesTest.java
===================================================================
---
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/EclipseLaunchConsoleConfigurationPreferencesTest.java
(rev 0)
+++
trunk/hibernatetools/tests/org.hibernate.eclipse.console.test/src/org/hibernate/eclipse/console/test/EclipseLaunchConsoleConfigurationPreferencesTest.java 2009-04-08
12:59:32 UTC (rev 14602)
@@ -0,0 +1,76 @@
+/*******************************************************************************
+ * Copyright (c) 2007-2009 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.hibernate.eclipse.console.test;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.Properties;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.hibernate.eclipse.console.EclipseLaunchConsoleConfigurationPreferences;
+import org.hibernate.eclipse.launch.IConsoleConfigurationLaunchConstants;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.lib.legacy.ClassImposteriser;
+import org.osgi.framework.Bundle;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ *
+ * @author Vitali Yemialyanchyk
+ */
+public class EclipseLaunchConsoleConfigurationPreferencesTest extends TestCase {
+
+ public Mockery context = new Mockery() {{
+ setImposteriser(ClassImposteriser.INSTANCE);
+ }};
+
+ static public String getPropertiesFilePath() {
+ Bundle bundle = HibernateConsoleTestPlugin.getDefault().getBundle();
+ String resPath = null;
+ try {
+ URL url = FileLocator.resolve(bundle.getEntry("/res/LaunchCC.properties"));
//$NON-NLS-1$
+ resPath = url.getPath();
+ } catch (IOException e) {
+ //ignore
+ }
+ return resPath;
+ }
+
+ /**
+ * test method for eclipseLaunchConsoleConfigurationPreferences.getProperties
+ * @throws CoreException
+ */
+ public void testCloseStream() throws CoreException {
+
+ final ILaunchConfiguration launchConfiguration =
context.mock(ILaunchConfiguration.class);
+
+ final EclipseLaunchConsoleConfigurationPreferences
eclipseLaunchConsoleConfigurationPreferences =
+ new EclipseLaunchConsoleConfigurationPreferences(launchConfiguration);
+ final String propertiesFilePath = getPropertiesFilePath();
+
+ context.checking(new Expectations() {{
+
+
allowing(launchConfiguration).getAttribute(IConsoleConfigurationLaunchConstants.PROPERTY_FILE,
(String)null);
+ will(returnValue(propertiesFilePath));
+ }});
+ Properties properties = eclipseLaunchConsoleConfigurationPreferences.getProperties();
+ assertNotNull(properties);
+ assertTrue(properties.size() == 1);
+ context.assertIsSatisfied();
+
+ }
+
+}