Skip to content

Commit

Permalink
Add more test cases for SelfEquals
Browse files Browse the repository at this point in the history
MOE_MIGRATED_REVID=130441140
  • Loading branch information
sumitbhagwani authored and cushon committed Aug 17, 2016
1 parent 4587aea commit 30d408d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 4 deletions.
Expand Up @@ -16,8 +16,13 @@

package com.google.errorprone.bugpatterns.testdata;

import static com.google.common.truth.Truth.assertThat;

/**
* Negative test cases for {@link SelfEquals} check.
*
* @author alexeagle@google.com (Alex Eagle)
* @author bhagwani@google.com (Sumit Bhagwani)
*/
public class SelfEqualsNegativeCases {
private String field;
Expand All @@ -26,18 +31,26 @@ public class SelfEqualsNegativeCases {
public int hashCode() {
return field != null ? field.hashCode() : 0;
}

@Override
public boolean equals(Object o) {
if (!(o instanceof SelfEqualsNegativeCases)) {
return false;
}

SelfEqualsNegativeCases other = (SelfEqualsNegativeCases) o;
return field.equals(other.field);
}

public boolean test() {
return Boolean.TRUE.toString().equals(Boolean.FALSE.toString());
}

public void testAssertThatEq(SelfEqualsNegativeCases obj) {
assertThat(obj).isEqualTo(obj);
}

public void testAssertThatNeq(SelfEqualsNegativeCases obj) {
assertThat(obj).isNotEqualTo(obj);
}
}
Expand Up @@ -16,8 +16,13 @@

package com.google.errorprone.bugpatterns.testdata;

import org.junit.Assert;

/**
* Positive test cases for {@link SelfEquals} check.
*
* @author eaftan@google.com (Eddie Aftandilian)
* @author bhagwani@google.com (Sumit Bhagwani)
*/
public class SelfEqualsPositiveCase {
private String simpleField;
Expand Down Expand Up @@ -66,7 +71,12 @@ public boolean test5(SelfEqualsPositiveCase obj) {
// BUG: Diagnostic contains: An object is tested for equality to itself
return equals(this);
}


public void testAssertTrue(SelfEqualsPositiveCase obj) {
// BUG: Diagnostic contains: An object is tested for equality to itself
Assert.assertTrue(obj.equals(obj));
}

@Override
public boolean equals(Object obj) {
if (obj == null || getClass() != obj.getClass()) {
Expand Down

0 comments on commit 30d408d

Please sign in to comment.