From ded6e1accaeb89a9f2a98c16e11f67f1149f3e8a Mon Sep 17 00:00:00 2001 From: MohamedHelmyKassab <137485958+MohamedHelmyKassab@users.noreply.github.com> Date: Tue, 11 Jul 2023 05:22:58 +0300 Subject: [PATCH] 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 --- ...tegerClassIntegerTYPEIntClassUnitTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/integerclassintegertypeintclass/IntegerClassIntegerTYPEIntClassUnitTest.java diff --git a/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/integerclassintegertypeintclass/IntegerClassIntegerTYPEIntClassUnitTest.java b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/integerclassintegertypeintclass/IntegerClassIntegerTYPEIntClassUnitTest.java new file mode 100644 index 0000000000..53d6c7f71e --- /dev/null +++ b/core-java-modules/core-java-numbers-6/src/test/java/com/baeldung/integerclassintegertypeintclass/IntegerClassIntegerTYPEIntClassUnitTest.java @@ -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 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); + } +}