@Override
public JsonNode getCities() throws Exception {
String cityListUrl; // get from properties file
List<Integer> cityIds = dao.getCities();
StringBuilder cityIds = new StringBuilder();
for (Integer cityId : cityIds) {
cityIds.append(cityId).append(",");
}
// gets city names.returns cityId,cityName.
// How to mock this?
Promise<JsonNode> jsonPromise = WS
.url(cityListUrl+ cityIds.toString()).get()
.map(wsresponse -> {
return wsresponse.asJson();
});
JsonNode node = jsonPromise.get(100000);
return node;
}
@Test
public void testGetCities() {
JsonNode cities = Ws.url() call to the API /cities/.
Assert statement.
}
当作为应用程序运行时,它应该调用其他服务。当以JUnit运行时,应该模拟对其他服务的REST调用。
我只能想象嘲笑一个类的依赖关系。这怎么可以实现?