即使满足条件,控件也不会退出循环。就像recipientEmailAddressList
尺寸是> 1,即使foundEmail
对于第一次尝试本身是正确的,它也不会退出循环。这个while循环有什么问题?
请告诉我下面的代码有什么问题。
do {
if(reTry>=1){
Thread.sleep(15000);
}
response = RestAssured.given().accept("application/json").get(url);
String responseBody = response.asString();
JsonPath jsonPath = new JsonPath(responseBody);
List<String> recipientEmailAddressList = jsonPath.get("recipientEmail");
System.out.println("receipeinet email list size "+recipientEmailAddressList.size());
for (int i=0;i<recipientEmailAddressList.size();i++) {
if(recipientEmailAddressList.get(i).equalsIgnoreCase(studentEmail)){
System.out.println(recipientEmailAddressList.get(i));
List<Object> rawRequest = jsonPath.get("rawRequest");
JsonPath rawRequestJsonPath = new JsonPath(rawRequest.get(0).toString());
String claimURL=rawRequestJsonPath.getString("parameters.claim_url");
NewTempData.storedata(6, 1, claimURL);
System.out.println("Credential Claim URL "+claimURL);
foundEmail = true;
}else{
foundEmail = false;
}
}
reTry++;
} while (reTry < 30 &!foundEmail);
if(foundEmail){
return true;
}
答案 0 :(得分:0)
正如其他人所建议的,使用&amp;&amp;而不是&amp;。
另一方面,即使您确实找到了电子邮件,您的for循环也会继续浏览电子邮件列表。基本上,foundEmail设置为true,然后你继续下一封电子邮件并将其设置为false。 或者,放置“休息”;或“回归真实;”在“foundEmail = true”之后
此外,您可以使用recipientEmailAddressList.contains(studentEmail)
而不是自己遍历电子邮件列表。