Mailgun实例
// method
public String loadJson(String url) {
StringBuilder json = new StringBuilder();
try {
URL urlObject = new URL(url);
URLConnection uc = urlObject.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(uc.getInputStream(), "utf-8"));
String inputLine = null;
while((inputLine = in.readLine()) != null) {
json.append(inputLine);
}
in.close();
} catch (Exception e) {
e.printStackTrace();
}
return json.toString();
}
// assert
Callable<Boolean> loadJsonSuccess(String url) {
return new Callable<Boolean>() {
public Boolean call() throws Exception {
String js = loadJson(url);
if (js.equals("[]")) {
return false;
} else {
return true;
}
}
};
}
// polling
public String loadJsonCompleted(String url, int timeoutSeconds) throws Exception {
try {
await().pollInterval(3, SECONDS).atMost(timeoutSeconds, SECONDS).until(loadJsonSuccess(url));
} catch (com.jayway.awaitility.core.ConditionTimeoutException e) {
throw new Exception(timeoutSeconds + " timeout");
}
return loadJson(url);
}
@Test
String url = "xxx.url";
String js = mailReceive.loadJsonCompleted(url, timeoutMill);
System.out.println(js);
assertThat(js).contains(xxx@.com);