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

Migrate off constructors of boxed primitive types. #1771

Merged
merged 1 commit into from
Feb 22, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/test/java/junit/samples/SimpleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public void testDivideByZero() {
public void testEquals() {
assertEquals(12, 12);
assertEquals(12L, 12L);
assertEquals(new Long(12), new Long(12));
assertEquals(Long.valueOf(12), Long.valueOf(12));

assertEquals("Size", 12, 13);
assertEquals("Capacity", 12.0, 11.99, 0.0);
Expand Down
33 changes: 28 additions & 5 deletions src/test/java/junit/tests/framework/AssertTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,19 @@ public void testAssertSame() {
Object o = new Object();
assertSame(o, o);
try {
assertSame(new Integer(1), new Integer(1));
assertSame(new MyInt(1), new MyInt(1));
} catch (AssertionFailedError e) {
return;
}
fail();
}

public void testAssertNotSame() {
assertNotSame(new Integer(1), null);
assertNotSame(null, new Integer(1));
assertNotSame(new Integer(1), new Integer(1));
assertNotSame(new MyInt(1), null);
assertNotSame(null, new MyInt(1));
assertNotSame(new MyInt(1), new MyInt(1));
try {
Integer obj = new Integer(1);
MyInt obj = new MyInt(1);
assertNotSame(obj, obj);
} catch (AssertionFailedError e) {
return;
Expand All @@ -168,4 +168,27 @@ public void testAssertNotSameFailsNull() {
}
fail();
}

private static final class MyInt {
private final int value;

MyInt(int value) {
this.value = value;
}

@Override
public boolean equals(Object obj) {
return obj instanceof MyInt && value == ((MyInt) obj).value;
}

@Override
public int hashCode() {
return value;
}

@Override
public String toString() {
return Integer.toString(value);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void isNotEqualToTestWithDifferentParameters() {
public void isNotEqualToObjectWithDifferentClass() {
TestWithParameters test = new TestWithParameters(DUMMY_NAME,
DUMMY_TEST_CLASS, DUMMY_PARAMETERS);
assertNotEquals(test, new Integer(3));
assertNotEquals(test, Integer.valueOf(3));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/junit/samples/ListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public void removeAll() {

@Test
public void removeElement() {
fFull.remove(new Integer(3));
fFull.remove(Integer.valueOf(3));
assertTrue(!fFull.contains(3));
}
}
2 changes: 1 addition & 1 deletion src/test/java/org/junit/samples/SimpleTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void divideByZero() {
public void testEquals() {
assertEquals(12, 12);
assertEquals(12L, 12L);
assertEquals(new Long(12), new Long(12));
assertEquals(Long.valueOf(12), Long.valueOf(12));

assertEquals("Size", 12, 13);
assertEquals("Capacity", 12.0, 11.99, 0.0);
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/org/junit/tests/assertion/AssertionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public void oneDimensionalBooleanArraysAreNotEqual() {

@Test(expected = AssertionError.class)
public void IntegerDoesNotEqualLong() {
assertEquals(new Integer(1), new Long(1));
assertEquals(Integer.valueOf(1), Long.valueOf(1));
}

@Test
Expand Down Expand Up @@ -678,7 +678,7 @@ public void implicitTypecastEquality() {
@Test
public void errorMessageDistinguishesDifferentValuesWithSameToString() {
try {
assertEquals("4", new Integer(4));
assertEquals("4", Integer.valueOf(4));
} catch (AssertionError e) {
assertEquals("expected: java.lang.String<4> but was: java.lang.Integer<4>", e.getMessage());
return;
Expand Down Expand Up @@ -788,8 +788,8 @@ public void objectsWithDifferentReferencesAreNotEqual() {

@Test
public void assertNotEqualsIncludesCorrectMessage() {
Integer value1 = new Integer(1);
Integer value2 = new Integer(1);
Integer value1 = 1;
Integer value2 = 1;
String message = "The values should be different";

try {
Expand All @@ -804,8 +804,8 @@ public void assertNotEqualsIncludesCorrectMessage() {

@Test
public void assertNotEqualsIncludesTheValueBeingTested() {
Integer value1 = new Integer(1);
Integer value2 = new Integer(1);
Integer value1 = 1;
Integer value2 = 1;

try {
assertNotEquals(value1, value2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void equalsIsCorrect() {
assertFalse(childless.equals(namedB));
assertEquals(childless, twoKids);
assertEquals(twoKids, anotherTwoKids);
assertFalse(twoKids.equals(new Integer(5)));
assertFalse(twoKids.equals(Integer.valueOf(5)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
public class TestDescriptionTest {
@Test
public void equalsIsFalseForNonTestDescription() {
assertFalse(Description.createTestDescription(getClass(), "a").equals(new Integer(5)));
assertFalse(Description.createTestDescription(getClass(), "a").equals(Integer.valueOf(5)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,4 @@ public void dataPointsCollectionShouldBeRecognizedIgnoringStrangeTypes() throws

assertEquals(1, assignments.size());
}
}
}
Loading