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 8623949
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:24:19+00:00 2026-06-12T07:24:19+00:00

I have this Java program, but my test gives me this message: testEmployeeTostring: failed

  • 0

I have this Java program, but my test gives me this message:

testEmployeeTostring: failed testEmployeeTostring expected <[id[=
1013, name= Jubal Early, job = ]procurement]> but was: <[id[= 1013,
name= Jubal Early, job = ] procurement]>

I had to use @Override and I think that’s the problem. I hope someone can figure out the problem with this:

public class Employee {

        int id;
        String name;
        JobType job;

        public Employee(int id, String name, JobType job)
        {
                this.id = id;
                this.name = name;
                this.job = job;
        }

        @Override public String toString()
        {
                return ("["+ "id =" + id + ", name = "  + name + ", job = " + job + "]");
        }
}
  • 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-06-12T07:24:21+00:00Added an answer on June 12, 2026 at 7:24 am

    Are you sure you have equals() method overriden? JUnit uses equals() to compare objects. Overriding hashCode() is always a good idea as well:

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Employee)) return false;
        Employee employee = (Employee) o;
        return id == employee.id && job == employee.job && name.equals(employee.name);
    
    }
    
    @Override
    public int hashCode() {
        int result = id;
        result = 31 * result + name.hashCode();
        result = 31 * result + job.hashCode();
        return result;
    }
    

    The code above assumes all fields are non-nullable and that JobType is an enum. And BTW toString() might have nothing to do here, as long as you are comparing objects, not toString() of objects (bad practice).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Dear all,Now i have this question in my java program,I think it should be
i have this java code: ArrayList<MessageMap> ids = getNewMail(UserID, type, maxIdMessage); Message[] message =
I have 2 java program located seperately One in c:\test and the other in
In my JAVA program, i have this if condition : if( (!pccoNettNoAff && !transOPCVM
I have this Java code, and I want to do the same thing in
I have this java servlet that grabs information from a form, I need to
I have this Java code which is used for JSF pagination: public List<ActiveSessionObj> list(int
I have this algorithm in Java to store passwords in database. I'd like to
Context I have this piece of Java Code btn.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent
I have a short question i have wrote this in java. Old code: class

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.