Java hasStatusCode(int)的类型错误-Netbeans 8.0.2
我在玩游戏来测试我的Restful服务 从他们的github示例中,他们有:Java hasStatusCode(int)的类型错误-Netbeans 8.0.2,java,rest,netbeans,junit,Java,Rest,Netbeans,Junit,我在玩游戏来测试我的Restful服务 从他们的github示例中,他们有: Response response = get( "http://www.example.com" ); assertThat(response, hasStatusCode(200)); // Compilation error here! assertThat(response.asJson(), hasJsonPath("$.name", equalTo("jeff"))); 如果我将此代码放在测试类中的方法
Response response = get( "http://www.example.com" );
assertThat(response, hasStatusCode(200)); // Compilation error here!
assertThat(response.asJson(), hasJsonPath("$.name", equalTo("jeff")));
如果我将此代码放在测试类中的方法中,我会从Netbeans中得到一个奇怪的编译错误
错误是:hasStatusCode(int)的类型错误
(请参见上文中显示此错误的注释)
我无法得到关于这个错误的很多信息,我发现关于它的唯一好信息是来自另一个SO问题
我重新启动了netbeans,编译错误永远不会消失。我唯一的希望是它可能是netbeans错误,或者我导入了错误的类
这是我的班级代码:
import com.github.restdriver.serverdriver.Matchers;
import static com.github.restdriver.serverdriver.RestServerDriver.get;
import static com.github.restdriver.serverdriver.RestServerDriver.header;
import com.github.restdriver.serverdriver.http.response.Response;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
public class NewEmptyJUnitTest {
public NewEmptyJUnitTest() { }
@BeforeClass
public static void setUpClass() { }
@AfterClass
public static void tearDownClass() { }
@Before
public void setUp() { }
@After
public void tearDown() { }
@Test
public void getJsonResponse() {
Response response = get("google.com" + "/things/5", header("Accept", "application/json"));
// Hamcrest matcher for HTTP status code
assertThat(response, Matchers.hasStatusCode(200)); // Compilation error here -> "The type of hasStatusCode(int) is erroneous"
}
}
关于如何解决这个错误有什么帮助吗?我发现了这个问题
当我使用Maven构建我的项目时,我只是粘贴了他们的(Rest驱动程序)Maven依赖代码,我认为一切都是正确的
但事实并非如此,出于某种原因,它使用的是harmcrest core的1.1版,而不是1.3版
我添加了harmcrest core的1.3版作为我的依赖项,删除了1.1版,它编译得很好