hasStatusCode(int) 的类型错误 - Netbeans 8.0.2

The type of hasStatusCode(int) is erroneous - Netbeans 8.0.2

我正在尝试 REST Driver API 来测试我的 Restful 服务。

从他们的 github 示例中,他们有:

Response response = get( "http://www.example.com" );

assertThat(response, hasStatusCode(200)); // Compilation error here!
assertThat(response.asJson(), hasJsonPath("$.name", equalTo("jeff")));

如果我将这段代码放在我的测试中的一个方法中 class 我会从 Netbeans 得到一个奇怪的编译错误。

错误是:The type of hasStatusCode(int) is erroneous(请参阅上面显示此错误的注释(在代码中)。

我无法获得有关此错误的太多信息,我发现的唯一有用信息来自另一个 SO 问题,here

我重新启动了 netbeans,但编译错误从未消失。我唯一的希望是要么它是一个 netbeans 错误,要么我导入了错误的 class(es).

这是我的 class 代码:

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 Driver)Maven 依赖代码,我假设一切都是正确的。

嗯,不是,出于某种原因,它使用的是 harmcrest-core 依赖项的 1.1 版本而不是 1.3

版本

我添加了 harmcrest-core 的 1.3 版作为我的依赖项,删除了 1.1 版,它编译得很好。