Merge pull request #322 from jclouds/fix-c473da3-regression-take-2

Fixing test regression from c473da3
This commit is contained in:
Jason King 2012-01-17 00:09:42 -08:00
commit 5b00a46c30
2 changed files with 15 additions and 15 deletions

View File

@ -59,13 +59,18 @@ public class JcloudsVersion {
@VisibleForTesting
JcloudsVersion() {
this(readVersionPropertyFromClasspath());
this(JcloudsVersion.class.getClassLoader());
}
private static String readVersionPropertyFromClasspath() {
@VisibleForTesting
JcloudsVersion(ClassLoader resourceLoader) {
this(readVersionPropertyFromClasspath(resourceLoader));
}
private static String readVersionPropertyFromClasspath(ClassLoader resourceLoader) {
Properties versionProperties = new Properties();
try {
versionProperties.load(checkNotNull(JcloudsVersion.class.getClassLoader().getResourceAsStream(VERSION_RESOURCE_FILE), VERSION_RESOURCE_FILE));
versionProperties.load(checkNotNull(resourceLoader.getResourceAsStream(VERSION_RESOURCE_FILE), VERSION_RESOURCE_FILE));
} catch (IOException exception) {
throw new IllegalStateException(format("Unable to load version resource file '%s'", VERSION_RESOURCE_FILE), exception);
}

View File

@ -19,7 +19,10 @@
package org.jclouds;
import static org.jclouds.JcloudsVersion.VERSION_RESOURCE_FILE;
import static org.testng.Assert.*;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import java.io.InputStream;
import java.util.List;
@ -35,18 +38,10 @@ import com.google.common.collect.Iterables;
@Test(singleThreaded = true)
public class JcloudsVersionTest {
@Test
@Test(expectedExceptions = { NullPointerException.class })
public void testFailsIfResourceFileMissing() {
ClassLoader original = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(
new ResourceHidingClassLoader(original, VERSION_RESOURCE_FILE));
try {
new JcloudsVersion();
fail("Expected NullPointerException");
} catch (NullPointerException expected) {
} finally {
Thread.currentThread().setContextClassLoader(original);
}
new JcloudsVersion(new ResourceHidingClassLoader(JcloudsVersion.class.getClassLoader(),
VERSION_RESOURCE_FILE));
}
@Test(expectedExceptions = { IllegalArgumentException.class })