我正在尝试使用 junit 和 hamcrest 测试一个类。这是我的测试:
@Test
public void testConvert()
{
assertNull(converter.convert(null));
assertNull(converter.convert(CommonentityFactory.eINSTANCE.createOrganization()));
OrganizationMID organizationMID = OrganizationMID.create(DOMAIN, 1234L);
String organizationName = "organizationName";
com.demographics.app.commonentity.Organization fromOrganization = CommonentityFactory.eINSTANCE
.createOrganization();
fromOrganization.setMID(organizationMID);
fromOrganization.setNameFormatted(organizationName);
com.search.organization.ui.Organization organization = converter
.convert(fromOrganization);
assertThat(organization.getOrganizationMID(), is(organizationMID));
assertThat(organization.getOrganizationName(), is(organizationName));
}
当我将测试作为 pde 测试运行时,我得到,
java.lang.LinkageError: loader constraint violation: loader (instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) previously initiated loading for a different type with name "org/hamcrest/Matcher"
这是我的进口:
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import org.junit.Test;
我正在使用org.junit v4.8.2-v370
,mockito-core v1.8.5
和org.hamcrest.osgi v1.1
我不确定这里出了什么问题,但我觉得我的 pom.xml 中没有正确设置依赖项。谁能帮我解决这个问题?