我想斷言從方法返回的HashMap getPaymentMethod()與HashMap 預計。斷言兩個哈希映射失敗,斷言錯誤
public void testGetPaymentMethod() throws Exception {
List<Map<String, Object>> paymentOptionsList = new ArrayList<Map<String, Object>>();
Map<String, Object> pO = new HashMap<String, Object>();
Map<String, Object> pM = new HashMap<String, Object>();
Map<String, Object> capam = new HashMap<String, Object>();
Map<String, Object> preAuthDetail = new HashMap<String, Object>();
preAuthDetail.put("sourceSystem", "ABCD");
preAuthDetail.put("sourceLocation", "EFGH");
preAuthDetail.put("authorizationCode", "OL_DF161216J34491");
capam.put("paymentAmount", 850);
capam.put("preAuthDetail", preAuthDetail);
pM.put("capam", capam);
pO.put("pM",pM);
paymentOptionsList.add(pO);
@SuppressWarnings("unchecked")
HashMap<String, Object> result = (HashMap<String, Object>) myTransformation.getPaymentMethod(paymentOptionsList,null);
Map<String, Object> expected = new HashMap<String, Object>();
Map<String, Object> preAuthorizationProfile = new HashMap<String, Object>();
Map<String, Object> source = new HashMap<String, Object>();
Map<String, Object> amount = new HashMap<String, Object>();
source.put("sourceSystem", "ABCD");
source.put("sourceLocation", "EFGH");
amount.put("amount", 850);
amount.put("monetaryAmount", "UNITEDSTATES_DOLLAR");
preAuthorizationProfile.put("source", source);
preAuthorizationProfile.put("preAuthorizationId", "OL_DF161216J34491");
preAuthorizationProfile.put("amount", amount);
pM.clear();
pM.put("preAuthorizationProfile", preAuthorizationProfile);
expected.put("pM", pM);
assertThat(result,is(expected));
}
但是我得到斷言錯誤如下
預期:被< {PAYMENTMETHOD = {preAuthorizationProfile = {量= {量= 850,MONETARYAMOUNT = UNITEDSTATES_DOLLAR},源= {sourceSystem = ABCD ,源 位置= EFGH},preAuthorizationId = OL_DF161216J34491}}}> 但:是< {PAYMENTMETHOD = {preAuthorizationProfile = {源= {sourceSystem = ABCD,sourceLocation = EFGH}},preAuthorizationId = OL_DF161216J34491,一個 安裝= {量= 850,monetaryAmount = UNITEDSTATES_DOLLAR}}}>
期望有一個叫做'amount'的鍵,而實際上有一個'a mount'鍵(注意空格)。 –
@JoeC我想我從cmd提示中複製它,這就是爲什麼它顯示一個空格。 – Beginner