Issue { @Override public int hashCode() { int result = 13; result += 17 * getSeverity().hashCode(); result += 19 * getSummary().hashCode(); result += 23 * getDescription().hashCode(); result += 29 * getCategory().hashCode(); NlComponent source = getSource(); if (source != null) { result += 31 * source.hashCode(); } return result; }  @NotNull abstract String getSummary(); @NotNull abstract String getDescription(); @NotNull abstract HighlightSeverity getSeverity(); @Nullable abstract NlComponent getSource(); @NotNull abstract String getCategory(); @Nullable HyperlinkListener getHyperlinkListener(); @NotNull Stream<Fix> getFixes(); @Override boolean equals(Object object); @Override int hashCode(); static final String EXECUTE_FIX; }
@Test public void testHashCode() { int hash1 = new TestIssue("a", "b", component1, "d", HighlightSeverity.ERROR).hashCode(); int hash2 = new TestIssue("a", "b", component1, "d", HighlightSeverity.ERROR).hashCode(); int hash3 = new TestIssue("a", "e", component2, "d", HighlightSeverity.ERROR).hashCode(); int hash4 = new TestIssue("a", "e", null, "d", HighlightSeverity.ERROR).hashCode(); int hash5 = new TestIssue("a", "e", null, "d", HighlightSeverity.ERROR).hashCode(); Assert.assertEquals(hash1, hash2); Assert.assertEquals(hash4, hash5); Assert.assertNotEquals(hash1, hash3); Assert.assertNotEquals(hash1, hash3); Assert.assertNotEquals(hash1, hash4); }
@Test public void testEqual() { TestIssue er1 = new TestIssue("a", "b", component1, "d", HighlightSeverity.ERROR); TestIssue er2 = new TestIssue("a", "b", component1, "d", HighlightSeverity.ERROR); Assert.assertEquals(er1, er2); Assert.assertEquals(er1.hashCode(), er2.hashCode()); TestIssue er3 = new TestIssue("a", "b", component1, "d", HighlightSeverity.ERROR); TestIssue er4 = new TestIssue("a", "e", component2, "d", HighlightSeverity.ERROR); TestIssue er5 = new TestIssue("a", "e", null, "d", HighlightSeverity.ERROR); TestIssue er6 = new TestIssue("a", "e", null, "d", HighlightSeverity.ERROR); Assert.assertNotEquals(er3, er4); Assert.assertNotEquals(er4, er5); Assert.assertEquals(er5, er6); Assert.assertNotEquals(er3.hashCode(), er4.hashCode()); }
@Test public void testNlLintIssueEqual() { LintAnnotationsModel model = new LintAnnotationsModel(); NlComponent sameComponent = mock(NlComponent.class); PsiElement startElement = mock(PsiElement.class); PsiElement endElement = mock(PsiElement.class); MockIssueFactory.addLintIssue(model, HighlightDisplayLevel.ERROR, sameComponent, startElement, endElement); MockIssueFactory.addLintIssue(model, HighlightDisplayLevel.ERROR, sameComponent, startElement, endElement); MockIssueFactory.addLintIssue(model, HighlightDisplayLevel.ERROR, sameComponent); List<LintAnnotationsModel.IssueData> issues = model.getIssues(); Assert.assertEquals(new LintIssueProvider.LintIssueWrapper(issues.get(0)), new LintIssueProvider.LintIssueWrapper(issues.get(1))); Assert.assertEquals(new LintIssueProvider.LintIssueWrapper(issues.get(0)).hashCode(), new LintIssueProvider.LintIssueWrapper(issues.get(1)).hashCode()); Assert.assertNotEquals(new LintIssueProvider.LintIssueWrapper(issues.get(0)), new LintIssueProvider.LintIssueWrapper(issues.get(2))); Assert.assertNotEquals(new LintIssueProvider.LintIssueWrapper(issues.get(0)).hashCode(), new LintIssueProvider.LintIssueWrapper(issues.get(2)).hashCode()); }