Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6193957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:12:44+00:00 2026-05-24T03:12:44+00:00

I have created a value object MarketVO and two instances of this value object

  • 0

I have created a value object MarketVO and two instances of this value object have same elements and same value for each element.

My value object class is:

public class MarketVO {

    private double floatAmt;
    private Date marketDate;
    private long marketCap;
}

Here are the values:

returnedData:

FloatAmt: 247657.5418618201, MarketCap: 5249164,
MarketDate: 2011-07-29 00:00:00.0 

expectedData:

FloatAmt: 247657.5418618201, MarketCap: 5249164, 
MarketDate: 2011-07-29 00:00:00.0

Now in my unit test class, I want to assert that my returned and expected type is same containing same value in same order so am doing something like

assertTrue(returnedData.equals(expectedData)), now this is returning false value but if I do

assertEquals(testObject.getfloatAmt(), testObject2.getfloatAmt());
assertEquals(testObject.getmarketCap(), testObject2.getmarketCap());
assertEquals(testObject.getmarketDate(), testObject2.getmarketDate());

this test passes and so am not sure as to why .equals method is not working in here? Any suggestions?

Update: I want to put emphasize here that we are using this for doing Unit Testing.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:12:46+00:00Added an answer on May 24, 2026 at 3:12 am

    The default implementation of .equals compares object references, not object content.

    You probably want to override the equals (and hashCode) methods. Something like this:

    public class MarketVO {
    
        private double floatAmt;
        private Date marketDate;
        private long marketCap;
    
        @Override
        public boolean equals(Object o) {
            if (!(o instanceof MarketVO))
                return false;
            MarketVO other = (MarketVO) o;
            return other.floatAmt == floatAmt &&
                   other.marketDate.equals(marketDate) &&
                   other.marketCap == marketCap;
        }
    
        @Override
        public int hashCode() {
            ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created the below object: public class GameProperties : ModelBase { private int
I have created a class for adding numbers: public class Add { private int
I have 3 select boxes and all are having same value (clones) & created
I have created a Custom Validation Attribute: public sealed class DateAttribute : DataTypeAttribute {
I have created NSUserDefaults object, it will be updated with the new value whenever
I have created a clone of an object in my code. Class<?> oc =
I have a ghashtable object as member of my class. I have created new
I have created a custom HandlerInterceptorAdapter to override the postHandle method: public class AcmeInterceptor
I have created my own custom ValidationAttribute : public class UrlValidationAttribute : ValidationAttribute {
Apologies for the vague question. Here it is: I have a table object created

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.