I would like to use the Specs2 test framework for testing, but I am getting an java.lang.reflect.MalformedParameterizedTypeException when I try to integrate it with Spring.
There is a specs2-spring library, but that is using 2.10 and an old version of specs2. I looked at this question about scalaTest and it got me to this code:
@ContextConfiguration(Array("classpath:applicationContext.xml"))
class TryItTest extends SpecificationWithJUnit{
@Autowired val db:DriverManagerDataSource = null
new TestContextManager(this.getClass()).prepareTestInstance(this)
"this thing should" should{
"run ok" in {
db.getConnection
success
}
}
}
but when I try to run the test I get:
Nov 09, 2015 2:11:31 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [applicationContext.xml]
Nov 09, 2015 2:11:31 PM org.springframework.context.support.GenericApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.support.GenericApplicationContext@243d315f: startup date [Mon Nov 09 14:11:31 EST 2015]; root of context hierarchy
Nov 09, 2015 2:11:31 PM org.springframework.jdbc.datasource.DriverManagerDataSource setDriverClassName
INFO: Loaded JDBC driver: oracle.jdbc.driver.OracleDriver
Nov 09, 2015 2:11:31 PM org.springframework.test.context.TestContextManager prepareTestInstance
SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@131746d9] to prepare test instance [my.package.TryItTest@12474a03]
java.lang.reflect.MalformedParameterizedTypeException
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:58)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:51)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:92)
at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:105)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:140)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:49)
at sun.reflect.generics.repository.ConstructorRepository.getParameterTypes(ConstructorRepository.java:94)
at java.lang.reflect.Executable.getGenericParameterTypes(Executable.java:284)
at java.lang.reflect.Method.getGenericParameterTypes(Method.java:282)
at java.beans.FeatureDescriptor.getParameterTypes(FeatureDescriptor.java:387)
at java.beans.MethodDescriptor.setMethod(MethodDescriptor.java:116)
If I switch from SpecificationWithJUnit
to SpecWithJUnit
it runs the test without error, but I do not want to have in include all those traits by hand. I think (at least) one of the traits in Matchers is causing the problem. Has anyone else tried to do this with Specs2? Am I missing something important?
(I am using Spring V4.1.0.RELEASE)