2013-04-22 60 views
0

我試圖嘲笑Model.finder來測試我的服務,但似乎mockito沒有被注入某種原因,我不明白爲什麼。請幫忙。Play Framework 2.1.1不會調用mockito。

public static Result deals() { 
    List<Product> finder = new Model.Finder<Long, Product>(Long.class, Product.class).all(); 
    JsonNode jsonNode = Json.toJson(finder); 

    return ok(Json.stringify(jsonNode)); 
} 

這是我的測試

@Mock 
    private Model.Finder finder; 

    @Before 
    public void setUp() throws Exception { 
     initMocks(this); 
     start(fakeApplication()); 

     Product product = new Product(); 
     product.id = 1L; 
     product.title = "Milk"; 

     List<Product> products = Arrays.asList(product); 

     when(finder.all()).thenReturn(products); 

    } 

    @Test 
    public void shouldGetDeals() { 
     Result result = routeAndCall(fakeRequest(GET, "/products")); 
     assertThat(status(result), is(200)); 

     String deals = contentAsString(result); 

     assertThat(deals, containsString("Milk")); 
    } 

所以,結果是Model.Finder因爲不調用模擬返回0。我不確定這是如何在Play 2.1中進行模擬的?

回答