jeudi 3 décembre 2015

Why my test to assertEquals() for Object fails when output is same?

My method is a part of RESTful service but I think it doesn't matter in this case.

I have a test to check if method which parse XML to Object working correctly:

public void test() {
    MemberEurope testMemberObject = new MemberEurope();
    testMemberObject.setFirstName("Marcin");    
    testMemberObject.setLastName("Kruglik");
    testMemberObject.setStreet("256 Clarendon Street");
    testMemberObject.setCity("Boston");
    testMemberObject.setCounty("MA");
    testMemberObject.setPostcode("02115");
    testMemberObject.setCountry("USA");
    testMemberObject.setId(1);
    String testMember = "<member>"
            + "<first-name>Marcin</first-name>"
            + "<last-name>Burke</last-name>"
            + "<street>256 Clarendon Street</street>"
            + "<city>Boston</city>"
            + "<county>MA</county>"
            + "<postcode>02115</postcode>"
            + "<country>USA</country>"
            + "</member>";
    MemberResourceServiceEU testCase = new MemberResourceServiceEU();
    byte[] data = testMember.getBytes();
    InputStream is = new ByteArrayInputStream(data); 
    testCase.createMember(is);
    assertEquals(testMemberObject, testCase.memberNamesDB.get("Bill Burke"));

Why my jUnit test fail, when actual output displayed in Failure Trace window is same?

java.lang.AssertionError: expected:  com.restfully.member.domain.MemberEurope<Member
First Name: Marcin
Last Name: Kruglik
Address
Street:256 Clarendon Street
City:Boston
County: MA
Postcode: 02115
Country: USA
Id:1> but was: com.restfully.member.domain.MemberEurope<Member
First Name: Marcin
Last Name: Kruglik
Address
Street:256 Clarendon Street
City:Boston
County: MA
Postcode: 02115
Country: USA
Id:1>

Test calls to overridden by me toString() method of Member. Track Failure shows some more trace informations, but I don't think so they are important here, if they are, then I will paste it here as well.

Aucun commentaire:

Enregistrer un commentaire