M
M
Makaron30002021-05-21 16:17:51
Java
Makaron3000, 2021-05-21 16:17:51

How to solve an error in a test?

Please help, the test fails: assertEquals("Clint Eastwood", new Dinglemouse("Clint", "Eastwood").getFullName()); Throws an error: expected: Clint[] but was:Clint[ ]

public class Dinglemouse {

  private String firstName;
  private String lastName;
  
  public Dinglemouse(String firstName, String lastName) {
    this.firstName = firstName;
    this.lastName = lastName;
  }
  
  public String getFullName() { 
    if(firstName != "" && lastName != "") {
        return this.firstName + " " + this.lastName;
   }
    if(firstName == "" && lastName == "") {
     return "";
   }
    return firstName == "" ? lastName : firstName;
  }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Makaron3000, 2021-05-21
@Makaron3000

Decision:

public class Dinglemouse {

  private String firstName;
  private String lastName;
  
  public Dinglemouse(String firstName, String lastName){
    this.firstName = firstName;
    this.lastName = lastName;
  }
  
  public String getFullName() { 
    if(!firstName.equals("") && !lastName.equals("")){
        return this.firstName + " " + this.lastName;
   }
    if(firstName.equals("") && lastName.equals("")){
     return "";
   }
    return firstName.equals("") ? lastName : firstName;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question