Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements equals and hash code overrides for completion proposal #244

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package org.springframework.shell;

import java.util.Objects;

/**
* Represents a proposal for TAB completion, made not only of the text to append, but also metadata about the proposal.
*
Expand Down Expand Up @@ -102,4 +104,21 @@ public boolean dontQuote() {
public String toString() {
return value;
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
CompletionProposal that = (CompletionProposal) o;
return dontQuote == that.dontQuote &&
Objects.equals(value, that.value) &&
Objects.equals(displayText, that.displayText) &&
Objects.equals(description, that.description) &&
Objects.equals(category, that.category);
}

@Override
public int hashCode() {
return Objects.hash(value, displayText, description, category, dontQuote);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.springframework.shell;

import org.junit.Before;
import org.junit.Test;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.*;

public class CompletionProposalTest {

private final String PROPOSAL = "test proposal";
private final String DESCRIPTION = "description";
private final String DISPLAY_TEXT = "displayText";
private final boolean DONT_QUOTE = true;
private final String CATEGORY = "category";
CompletionProposal completionProposal;


@Before
public void setup() {
completionProposal = new CompletionProposal(PROPOSAL);
completionProposal.category(CATEGORY);
completionProposal.description(DESCRIPTION);
completionProposal.displayText(DISPLAY_TEXT);
completionProposal.dontQuote(DONT_QUOTE);
}

@Test
public void equals() {
CompletionProposal completionProposal2 = new CompletionProposal(PROPOSAL);
completionProposal2.category(CATEGORY);
completionProposal2.description(DESCRIPTION);
completionProposal2.displayText(DISPLAY_TEXT);
completionProposal2.dontQuote(DONT_QUOTE);

assertThat(completionProposal, is(completionProposal2));
}

@Test
public void hashcode() {
CompletionProposal completionProposal2 = new CompletionProposal(PROPOSAL);
completionProposal2.category(CATEGORY);
completionProposal2.description(DESCRIPTION);
completionProposal2.displayText(DISPLAY_TEXT);
completionProposal2.dontQuote(DONT_QUOTE);
assertThat(completionProposal.hashCode(), is(completionProposal2.hashCode()));
}
}