Skip to content

Instantly share code, notes, and snippets.

@ittaiz
Created April 24, 2013 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ittaiz/5452280 to your computer and use it in GitHub Desktop.
Save ittaiz/5452280 to your computer and use it in GitHub Desktop.
A test which checks which jar files some spring classes arrive from on runtime. This was needed since "mvn dependency:tree" showed incorrect results
package com.wixpress.springVersionBug;
import org.junit.*;
import org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory;
import org.springframework.core.GenericTypeResolver;
import java.security.CodeSource;
import static org.hamcrest.Matchers.endsWith;
/**
* @author ittaiz
* @since 3/24/13
*/
public class SpringVersionTest {
@Test
public void verifySpringBeans311InClasspath(){
verifyCorrectSpringVersionInClasspathFor(AbstractAutowireCapableBeanFactory.class,"spring-beans-3.1.1.RELEASE.jar");
}
@Test
public void verifySpringCore311InClasspath(){
verifyCorrectSpringVersionInClasspathFor(GenericTypeResolver.class,"spring-core-3.1.1.RELEASE.jar");
}
public void verifyCorrectSpringVersionInClasspathFor(Class springClass,String expectedJarFileName){
CodeSource springClassCodeSource = springClass.getProtectionDomain().getCodeSource();
Assert.assertNotNull("expecting "+expectedJarFileName+" to be loaded by non-system class loader",springClassCodeSource);
Assert.assertThat(springClassCodeSource.getLocation().toString(),endsWith(expectedJarFileName));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment