mirror of https://github.com/apache/jclouds.git
Fixing test regression from c473da3
by allowing a different resource classloader to be supplied in testing
This commit is contained in:
parent
d9b04c3cc4
commit
a55081bcc6
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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 })
|
||||
|
|
Loading…
Reference in New Issue