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中进行模拟的?