nus-cs2103-AY2223S2 / forum

12 stars 0 forks source link

EditCommandTest cases failing on assertEquals inside CommandUtilTest#assertCommandSuccess #249

Closed tituswe closed 1 year ago

tituswe commented 1 year ago

IntelliJ Version

IntelliJ IDEA 2022.3.1 (Community Edition) Build #IC-223.8214.52, built on December 20, 2022 Runtime version: 17.0.5+1-b653.23 aarch64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. macOS 12.6.3 GC: G1 Young Generation, G1 Old Generation Memory: 1024M Cores: 8 Metal Rendering is ON Non-Bundled Plugins: com.vermouthx.xcode-theme (1.6.1) IdeaVIM (2.1.0) CheckStyle-IDEA (5.76.0)

Kotlin: 223-1.7.21-release-272-IJ8214.52

Reference Image

IMAGE 2023-03-10 21:22:19

Problem

I made some edits to my team's CommandResult whereby I store the target Client of each command as a field as opposed to the previous version of CommandResult where the Client was formatted into the feedbackToUser field.

Before:

public class CommandResult {

    private final String feedbackToUser;

    /** Help information should be shown to the user. */
    private final boolean showHelp;

    /** The application should exit. */
    private final boolean exit;

    /**
     * Constructs a {@code CommandResult} with the specified fields.
     */
    public CommandResult(String feedbackToUser, boolean showHelp, boolean exit) {
        this.feedbackToUser = requireNonNull(feedbackToUser);
        this.showHelp = showHelp;
        this.exit = exit;
    }
    @Override
    public boolean equals(Object other) {
        if (other == this) {
            return true;
        }

        // instanceof handles nulls
        if (!(other instanceof CommandResult)) {
            return false;
        }

        CommandResult otherCommandResult = (CommandResult) other;
        return feedbackToUser.equals(otherCommandResult.feedbackToUser)
                && showHelp == otherCommandResult.showHelp
                && exit == otherCommandResult.exit;
    }

After:

public class CommandResult {

    private final String feedbackToUser;

    private final Client targetClient;

    /**
     * Selects a particular client
     */
    private final boolean select;

    /**
     * Help information should be shown to the user.
     */
    private final boolean showHelp;

    /**
     * The application should exit.
     */
    private final boolean exit;

    /**
     * Constructs a {@code CommandResult} with the specified fields.
     */
    public CommandResult(String feedbackToUser, Client targetClient, boolean select, boolean showHelp, boolean exit) {
        this.feedbackToUser = requireNonNull(feedbackToUser);
        this.targetClient = targetClient;
        this.select = select;
        this.showHelp = showHelp;
        this.exit = exit;
    }
    @Override
    public boolean equals(Object other) {
        if (other == this) {
            return true;
        }

        // instanceof handles nulls
        if (!(other instanceof CommandResult)) {
            return false;
        }

        CommandResult otherCommandResult = (CommandResult) other;
        return feedbackToUser.equals(otherCommandResult.feedbackToUser)
                && targetClient == otherCommandResult.targetClient
                && select == otherCommandResult.select
                && showHelp == otherCommandResult.showHelp
                && exit == otherCommandResult.exit;
    }

Details

As you can see from the screenshot attached, inside the debug console the parameters being compared in the assertEquals(...) are all the same, yet the test cases fail specific to the EditCommandTest file.

I get the following: Screenshot 2023-03-10 at 9 29 20 PM

Would anyone know what cld be possibly wrong? Do feel free to post more questions for me to clarify. Thank you!

tituswe commented 1 year ago

** I have confirmed that the issue is with the assertEquals statement on line 82 in the first attached image. Commenting out the line passes the testcases that are failing

damithc commented 1 year ago

@tituswe push your code to a branch and give the link here so that others can look at the scenario more closely

tituswe commented 1 year ago

Sorry all, I have fixed the bug... it was just an issue with checking Client#equals(). Haha :')