Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Improve test on TypeName #544

Merged
merged 1 commit into from
Feb 1, 2017
Merged
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
2 changes: 2 additions & 0 deletions src/test/java/com/squareup/javapoet/TypeNameTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;

public class TypeNameTest {
Expand Down Expand Up @@ -178,5 +179,6 @@ private void assertEqualsHashCodeAndToString(TypeName a, TypeName b) {
assertEquals(a.toString(), b.toString());
assertThat(a.equals(b)).isTrue();
assertThat(a.hashCode()).isEqualTo(b.hashCode());
assertFalse(a.equals(null));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertThat(a).isNotNull();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

He, no: this specifically about testing the .equals(null) contract 😉

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@ronshapiro ronshapiro Feb 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh fair. What about assertThat(a).isNotEqualTo(null)?

Copy link
Contributor

@sormuras sormuras Feb 1, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be more inline with

assertThat(a.equals(b)).isTrue();
assertThat(a.hashCode()).isEqualTo(b.hashCode());

I think assertThat(a).isEqualTo(a); is missing, too. Testing the if (this == o) return true; contract.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True, but that's just an optimization. If a.equals(b) works then b.equals(a) must also work, thus we then know a.equals(a) will work.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. True. Stays true. 🥂

}
}