[BAEL-7035] improvement to value based class (#14938)
Co-authored-by: Bhaskar <bhaskar.dastidar@freshworks.com>
This commit is contained in:
parent
3bd2e7eb3e
commit
a3148b3dd2
|
@ -30,6 +30,11 @@ public final class Point {
|
||||||
return new Point(x, y, z);
|
return new Point(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Point{" + "x=" + x + ", y=" + y + ", z=" + z + '}';
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object other) {
|
public boolean equals(Object other) {
|
||||||
if (other == null || getClass() != other.getClass())
|
if (other == null || getClass() != other.getClass())
|
||||||
|
|
|
@ -1,14 +1,17 @@
|
||||||
package com.baeldung.value_based_class;
|
package com.baeldung.value_based_class;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ValueBasedClassUnitTest {
|
public class ValueBasedClassUnitTest {
|
||||||
@Test
|
@Test
|
||||||
public void givenAutoboxedAndPrimitive_whenCompared_thenReturnEquals() {
|
public void givenAutoboxedAndPrimitive_whenCompared_thenReturnEquals() {
|
||||||
int primitive_a = 125;
|
List<Integer> list = new ArrayList<>();
|
||||||
Integer obj_a = 125; // this is autoboxed
|
list.add(1); // this is autoboxed
|
||||||
Assert.assertSame(primitive_a, obj_a);
|
Assert.assertEquals(list.get(0), Integer.valueOf(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue