当尝试运行maven build(mvn clean install
)来测试我的集成,测试时,我得到了以下错误:
[ERROR] Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.219 s <<< FAILURE! - in com.ots.gateway.service.OtsMobTokensServiceTest
[ERROR] testFindByOttNumber(com.ots.gateway.service.OtsMobTokensServiceTest) Time elapsed: 0.219 s <<< ERROR!
ma.glasnost.orika.MappingException: 'destinationClass' is required
at com.ots.gateway.service.OtsMobTokensServiceTest.testFindByOttNumber(OtsMobTokensServiceTest.java:26)
JDK :jdk1.8.0_144
Maven :apache-maven-3.2.5
Orika :1.5.1
我相信这是因为使用了Orika。有人可以帮忙吗?
我的代码:
/**
* Maps a source object(Entity or DTO) to its matching target(Entity or DTO).
*
* @param <T> the generic type
* @param o - entity or dto
* @return the t
*/
@SuppressWarnings("unchecked")
protected <T extends Object> T map(Object o) {
T mappedObject = null;
Mapper mapperProvider = mapperFactory.createMapper(o);
try {
if (SanityCheck.isValid(mapperProvider)) {
mappedObject = (T) mapperProvider.map(o);
} else {
if(SanityCheck.isValid(o)){
LOGGER.error("No Mapper found for object: " + o.getClass().getName() + " Service: "
+ this.getClass().getName());
}
}
} catch (ClassCastException e) {
LOGGER.error("Casting error", e);
}
return mappedObject;
}
答案 0 :(得分:0)
我终于想出了如何通过使用surefire插件来解决它:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<useSystemClassLoader>false</useSystemClassLoader>
</configuration>
</plugin>
问题是我在我的项目中使用org.reflections来加载我的包的所有实体和dtos。运行maven测试时,它不起作用。通过不使用系统类加载器,测试成功。更多信息可以在这里找到: http://maven.apache.org/surefire/maven-surefire-plugin/examples/class-loading.html