BAEL-6418 (#14311)
* BAEL-6418 This commit aims to add a test class for the article BAEL-6418 * Update IntegerClassIntegerTYPEIntClassUnitTest.java * Update IntegerClassIntegerTYPEIntClassUnitTest.java * Update IntegerClassIntegerTYPEIntClassUnitTest.java * Update IntegerClassIntegerTYPEIntClassUnitTest.java
This commit is contained in:
parent
89d83168ae
commit
ded6e1acca
|
@ -0,0 +1,45 @@
|
||||||
|
package com.baeldung.integerclassintegertypeintclass;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
|
||||||
|
public class IntegerClassIntegerTYPEIntClassUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenIntegerClass_whenGetName_thenVerifyClassName() {
|
||||||
|
Class<Integer> integerClass = Integer.class;
|
||||||
|
Assertions.assertEquals("java.lang.Integer", integerClass.getName());
|
||||||
|
Assertions.assertEquals(Number.class, integerClass.getSuperclass());
|
||||||
|
Assertions.assertFalse(integerClass.isPrimitive());
|
||||||
|
}
|
||||||
|
|
||||||
|
public int sum(int a, int b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int sum(Integer a, Integer b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int sum(int a, Integer b) {
|
||||||
|
return a + b;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenIntAndInteger_whenAddingValues_thenVerifySum() {
|
||||||
|
int primitiveValue = 10;
|
||||||
|
Integer wrapperValue = Integer.valueOf(primitiveValue);
|
||||||
|
Assertions.assertEquals(20, sum(primitiveValue, primitiveValue));
|
||||||
|
Assertions.assertEquals(20, sum(primitiveValue, wrapperValue));
|
||||||
|
Assertions.assertEquals(20, sum(wrapperValue, wrapperValue));
|
||||||
|
Assertions.assertEquals(Integer.TYPE.getName(), int.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenIntValue_whenUsingIntClass_thenVerifyIntClassProperties() {
|
||||||
|
Class<?> intClass = int.class;
|
||||||
|
Assertions.assertEquals("int", intClass.getName());
|
||||||
|
Assertions.assertTrue(intClass.isPrimitive());
|
||||||
|
Assertions.assertEquals(int.class, intClass);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue