2015-04-29 56 views
1

我在玩REST Driver API來測試我的Restful服務。hasStatusCode(int)的類型是錯誤的 - Netbeans 8.0.2

從他們的GitHub的例子,他們有:

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

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

如果我把一個方法,這裏面的代碼在我的測試類我從Netbeans的一個奇怪的編譯錯誤。

的錯誤是:The type of hasStatusCode(int) is erroneous(見註釋(代碼)以上,其中顯示該錯誤

我無法獲得有關這個錯誤,唯一的好信息,我發現它是很多信息。從另一個SO問題,here

我已經重新啓動NetBeans和編譯錯誤永遠不會消失。我唯一的希望是它要麼是NetBeans錯誤或我已經導入了錯誤的類(ES)。

這裏是我的班級代碼:

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" 

    } 
} 

有關如何解決此錯誤的任何幫助?

回答

2

我發現了這個問題。

當我使用Maven構建我的項目時,我只是粘貼了他們的(Rest Driver)Maven依賴項代碼,並且我認爲一切正常。

嗯,這是不是由於某種原因它用的是1.1版本harmcrest-core依賴而不是版本1.3

我添加的harmcrest-core 1.3版本,我的依賴,去掉了1.1版本,它只是編譯精細。

相關問題