2017-06-17 1 views
0

ich die HashMap zu behaupten, ich versuche, das von dem Verfahren getPaymentMethod() mit dem HashMap erwartet.Assert zwei HashMaps mit Assertionsfehler versagt

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)); 
} 

Aber ich bin immer Assertion Fehler wie

folgt

Erwartet: < ist {payment = {preAuthorizationProfile = {amount = {amount = 850, MonetaryAmount = UNITEDSTATES_DOLLAR} source = {sourceSystem = ABCD , Quelle Location = EFGH}, preAuthorizationId = OL_DF161216J34491}}}> aber: war < {payment = {preAuthorizationProfile = {source = {sourceSystem = ABCD, Sourcelocation = EFGH}}, preAuthorizationId = OL_DF161216J34491, eine Mount = {amount = 850, monetaryAmount = UNITEDSTATES_DOLLAR}}}>

+0

Der erwartete hat einen Schlüssel namens 'Betrag', während der tatsächliche hat einen Schlüssel von' a mount' (beachten Sie das Leerzeichen). –

+0

@JoeC Ich denke, ich habe es von der Eingabeaufforderung cmd kopiert, weshalb es ein Leerzeichen zeigt. – Beginner

Antwort

3

Ich habe Ihre Fehlermeldung genommen und so formatiert, dass die Ebenen Ihrer verschachtelten Karten klarer werden. Beachten Sie, wie amount und preAuthorizationId auf verschiedenen Ebenen zwischen den beiden Karten sind.

Expected: is < 
{ 
    paymentMethod={ 
     preAuthorizationProfile={ 
      amount={ 
       amount=850, 
       monetaryAmount=UNITEDSTATES_DOLLAR 
      }, 
      source={ 
       sourceSystem=ABCD, 
       sourceLocation=EFGH 
      }, 
      preAuthorizationId=OL_DF161216J34491 
     } 
    } 
} 
> but: was < 
{ 
    paymentMethod={ 
     preAuthorizationProfile={ 
      source={ 
       sourceSystem=ABCD, 
       sourceLocation=EFGH 
      } 
     }, 
     preAuthorizationId=OL_DF161216J34491, 
     amount={ 
      amount=850, monetaryAmount=UNITEDSTATES_DOLLAR 
     } 
    } 
} 
> 

Darf ich vorschlagen, anstatt Karten Karten Karten verwenden, versuchen Sie mit Klassen zu entwickeln, die das darstellen, was Sie zu tun versuchen. Dadurch wird Ihr Code viel widerstandsfähiger und weniger anfällig für Fehler wie diese.