Automated g4 rollback of changelist 99529535.
*** Reason for rollback ***
Lots of newly failing tests. Most (but not all) probably should fail, but we will clean things up before resubmitting.
*** Original change description ***
Fix int/long comparisons bug by adding:
-IntegerSubject.isEqualTo(Long)
-IntegerSubject.isNotEqualTo(Long)
-LongSubject.isEqualTo(Integer)
-LongSubject.isNotEqualTo(Integer)
***
-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=99568145
diff --git a/core/src/main/java/com/google/common/truth/IntegerSubject.java b/core/src/main/java/com/google/common/truth/IntegerSubject.java
index d6454fd..b59bf90 100644
--- a/core/src/main/java/com/google/common/truth/IntegerSubject.java
+++ b/core/src/main/java/com/google/common/truth/IntegerSubject.java
@@ -15,13 +15,15 @@
*/
package com.google.common.truth;
+import com.google.common.primitives.Ints;
+
import javax.annotation.Nullable;
/**
* Propositions for {@link Integer} subjects.
*
* @author David Saff
- * @author Christian Gruber
+ * @author Christian Gruber (cgruber@israfil.net)
* @author Kurt Alfred Kluever
*/
// Can't be final because we use codegen to generate a subclass
@@ -46,27 +48,7 @@
super.isNotEqualTo(other);
}
- public void isEqualTo(@Nullable Long other) {
- if (other == null) {
- super.isEqualTo(null);
- } else {
- if (other.intValue() == other) {
- super.isEqualTo(other.intValue());
- } else {
- super.isEqualTo(other); // this will certainly fail...
- }
- }
- }
-
- public void isNotEqualTo(@Nullable Long other) {
- if (other == null) {
- super.isNotEqualTo(null);
- } else {
- if (other.intValue() == other) {
- super.isNotEqualTo(other.intValue());
- } else {
- super.isNotEqualTo(other); // this will certainly fail...
- }
- }
+ public void isEqualTo(long other) {
+ super.isEqualTo(Ints.saturatedCast(other));
}
}
diff --git a/core/src/main/java/com/google/common/truth/LongSubject.java b/core/src/main/java/com/google/common/truth/LongSubject.java
index c341d24..416c7c3 100644
--- a/core/src/main/java/com/google/common/truth/LongSubject.java
+++ b/core/src/main/java/com/google/common/truth/LongSubject.java
@@ -21,7 +21,7 @@
* Propositions for {@code long} subjects.
*
* @author David Saff
- * @author Christian Gruber
+ * @author Christian Gruber (cgruber@israfil.net)
* @author Kurt Alfred Kluever
*/
// Can't be final because we use codegen to generate a subclass
@@ -46,11 +46,7 @@
super.isNotEqualTo(other);
}
- public void isEqualTo(@Nullable Integer other) {
- super.isEqualTo((other == null) ? null : (long) other);
- }
-
- public void isNotEqualTo(@Nullable Integer other) {
- super.isNotEqualTo((other == null) ? null : (long) other);
+ public void isEqualTo(int other) {
+ isEqualTo((long) other);
}
}
diff --git a/core/src/test/java/com/google/common/truth/IntegerTest.java b/core/src/test/java/com/google/common/truth/IntegerTest.java
index dc6ad4f..9c585fb 100644
--- a/core/src/test/java/com/google/common/truth/IntegerTest.java
+++ b/core/src/test/java/com/google/common/truth/IntegerTest.java
@@ -32,7 +32,7 @@
* Tests for Integer Subjects.
*
* @author David Saff
- * @author Christian Gruber
+ * @author Christian Gruber (cgruber@israfil.net)
*/
@RunWith(JUnit4.class)
public class IntegerTest {
@@ -44,18 +44,6 @@
}
@Test
- public void equalityWithLongs() {
- int x = 0;
- assertThat(x).isEqualTo(0L);
- try {
- assertThat(x).isNotEqualTo(0L);
- fail("Should have thrown");
- } catch (AssertionError expected) {
- assertThat(expected).hasMessage("Not true that <0> is not equal to <0>");
- }
- }
-
- @Test
public void intIsInt() {
assertThat(4).isEqualTo(4);
}
@@ -117,24 +105,8 @@
@Test
public void inequalityOfNulls() {
- assertThat(4).isNotEqualTo((Long) null);
- assertThat(4).isNotEqualTo((Integer) null);
- assertThat(4).isNotEqualTo((Object) null);
- assertThat(4L).isNotEqualTo((Long) null);
- assertThat(4L).isNotEqualTo((Integer) null);
- assertThat(4L).isNotEqualTo((Object) null);
assertThat((Long) null).isNotEqualTo(4);
- assertThat((Long) null).isNotEqualTo(4L);
- assertThat((Integer) null).isNotEqualTo(4);
- assertThat((Integer) null).isNotEqualTo(4L);
-
- assertThat((Integer) null).isEqualTo((Integer) null);
- assertThat((Integer) null).isEqualTo((Long) null);
- assertThat((Integer) null).isEqualTo((Object) null);
-
- assertThat((Long) null).isEqualTo((Integer) null);
- assertThat((Long) null).isEqualTo((Long) null);
- assertThat((Long) null).isEqualTo((Object) null);
+ assertThat(4).isNotEqualTo((Long) null);
}
@Test
@@ -143,37 +115,7 @@
assertThat((Long) null).isNotEqualTo((Integer) null);
fail("Should have thrown");
} catch (AssertionError e) {
- assertThat(e).hasMessage("Not true that <null> is not equal to <null>");
- }
- try {
- assertThat((Long) null).isNotEqualTo((Long) null);
- fail("Should have thrown");
- } catch (AssertionError e) {
- assertThat(e).hasMessage("Not true that <null> is not equal to <null>");
- }
- try {
- assertThat((Integer) null).isNotEqualTo((Integer) null);
- fail("Should have thrown");
- } catch (AssertionError e) {
- assertThat(e).hasMessage("Not true that <null> is not equal to <null>");
- }
- try {
- assertThat((Integer) null).isNotEqualTo((Long) null);
- fail("Should have thrown");
- } catch (AssertionError e) {
- assertThat(e).hasMessage("Not true that <null> is not equal to <null>");
- }
- try {
- assertThat((Integer) null).isNotEqualTo((Object) null);
- fail("Should have thrown");
- } catch (AssertionError e) {
- assertThat(e).hasMessage("Not true that <null> is not equal to <null>");
- }
- try {
- assertThat((Long) null).isNotEqualTo((Object) null);
- fail("Should have thrown");
- } catch (AssertionError e) {
- assertThat(e).hasMessage("Not true that <null> is not equal to <null>");
+ assertThat(e.getMessage()).contains("Not true that <null> is not equal to <null>");
}
}
@@ -208,31 +150,9 @@
} catch (AssertionError expected) {
}
- // But boxed primitives are equal to "similar" unboxed primitives
- assertThat(new Integer(4)).isEqualTo(4L);
- assertThat(new Long(4L)).isEqualTo(4);
- }
-
- @Test
- public void newInteger_isNotEqualTo_Long() {
- try {
- assertThat(new Integer(4)).isNotEqualTo(new Long(4L));
- } catch (AssertionError expected) {
- assertThat(expected).hasMessage("Not true that <4> is not equal to <4>");
- return;
- }
- fail("Expected an AssertionError to be thrown but wasn't");
- }
-
- @Test
- public void newLong_isNotEqualTo_Integer() {
- try {
- assertThat(new Long(4L)).isNotEqualTo(new Integer(4));
- } catch (AssertionError expected) {
- assertThat(expected).hasMessage("Not true that <4> is not equal to <4>");
- return;
- }
- fail("Expected an AssertionError to be thrown but wasn't");
+ // Truth says boxed primitives are not .equals()
+ assertThat(new Integer(4)).isNotEqualTo(new Long(4L));
+ assertThat(new Long(4L)).isNotEqualTo(new Integer(4));
}
@Test
@@ -248,61 +168,11 @@
// Assert.assertEquals(new Integer(4), 4L);
// Assert.assertEquals(4L, new Integer(4));
- assertThat(new Integer(4)).isEqualTo(4L);
- assertThat(new Long(4L)).isEqualTo(4);
- }
-
- @Test
- public void int_isNotEqualTo_Long() {
- try {
- assertThat(4).isNotEqualTo(new Long(4L));
- } catch (AssertionError expected) {
- assertThat(expected).hasMessage("Not true that <4> is not equal to <4>");
- return;
- }
- fail("Expected an AssertionError to be thrown but wasn't");
- }
-
- @Test
- public void long_isNotEqualTo_Integer() {
- try {
- assertThat(4L).isNotEqualTo(new Integer(4));
- } catch (AssertionError expected) {
- assertThat(expected).hasMessage("Not true that <4> is not equal to <4>");
- return;
- }
- fail("Expected an AssertionError to be thrown but wasn't");
- }
-
- @Test
- public void isEqualTo_biggerThanIntegerMaxValue() {
- try {
- assertThat(4).isEqualTo(new Long(Integer.MAX_VALUE) + 1L);
- } catch (AssertionError expected) {
- assertThat(expected).hasMessage("Not true that <4> is equal to <2147483648>");
- return;
- }
- fail("Expected an AssertionError to be thrown but wasn't");
- }
-
- @Test
- public void isNotEqualTo_biggerThanIntegerMaxValue() {
- assertThat(4).isNotEqualTo(new Long(Integer.MAX_VALUE) + 1L);
- }
-
- @Test
- public void isEqualTo_lessThanIntegerMinValue() {
- try {
- assertThat(4).isEqualTo(new Long(Integer.MIN_VALUE) - 1L);
- } catch (AssertionError expected) {
- assertThat(expected).hasMessage("Not true that <4> is equal to <-2147483649>");
- return;
- }
- fail("Expected an AssertionError to be thrown but wasn't");
- }
-
- @Test
- public void isNotEqualTo_lessThanIntegerMinValue() {
- assertThat(4).isNotEqualTo(new Long(Integer.MIN_VALUE) - 1L);
+ // Truth says boxed primitives are not .equals() to an unboxed primitive
+ assertThat(new Integer(4)).isNotEqualTo(4L);
+ assertThat(new Long(4L)).isNotEqualTo(4);
+ // And vice-versa
+ assertThat(4L).isNotEqualTo(new Integer(4));
+ assertThat(4).isNotEqualTo(new Long(4L));
}
}
diff --git a/core/src/test/java/com/google/common/truth/LongTest.java b/core/src/test/java/com/google/common/truth/LongTest.java
index 31d77d3..65d639b 100644
--- a/core/src/test/java/com/google/common/truth/LongTest.java
+++ b/core/src/test/java/com/google/common/truth/LongTest.java
@@ -31,7 +31,7 @@
* Tests for Long Subjects.
*
* @author David Saff
- * @author Christian Gruber
+ * @author Christian Gruber (cgruber@israfil.net)
*/
@RunWith(JUnit4.class)
public class LongTest {
@@ -53,18 +53,6 @@
}
@Test
- public void equalityWithInts() {
- long x = 0;
- assertThat(x).isEqualTo(0);
- try {
- assertThat(x).isNotEqualTo(0);
- fail("Should have thrown");
- } catch (AssertionError expected) {
- assertThat(expected).hasMessage("Not true that <0> is not equal to <0>");
- }
- }
-
- @Test
public void equalityFail() {
try {
assertThat(2L + 2).isEqualTo(5L);