From e3afaf7996ebaa8832598dd63afee8d1125856be Mon Sep 17 00:00:00 2001 From: Bahaa El-Din Helmy Date: Sat, 17 Jun 2023 00:34:34 +0300 Subject: [PATCH] Difference Between Boolean.TRUE and true in Java (#14253) This commit is related to the article "Difference Between Boolean.TRUE and true in Java" --- .../booleans/BooleanTrueVsTrueUnitTest.java | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 core-java-modules/core-java-booleans/src/test/java/com/baeldung/booleans/BooleanTrueVsTrueUnitTest.java diff --git a/core-java-modules/core-java-booleans/src/test/java/com/baeldung/booleans/BooleanTrueVsTrueUnitTest.java b/core-java-modules/core-java-booleans/src/test/java/com/baeldung/booleans/BooleanTrueVsTrueUnitTest.java new file mode 100644 index 0000000000..d8c43913fb --- /dev/null +++ b/core-java-modules/core-java-booleans/src/test/java/com/baeldung/booleans/BooleanTrueVsTrueUnitTest.java @@ -0,0 +1,34 @@ +package com.baeldung.booleans; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +public class BooleanTrueVsTrueUnitTest { + + + @Test + public void given_BooleanValues_whenUsingBooleanTrue_thenTestBooleanEquality() { + assertEquals(Boolean.TRUE, Boolean.valueOf(true)); + } + + @Test + public void given_BooleanValues_whenUsingBooleanTrue_thenTestBooleanIdentity() { + assertTrue(Boolean.TRUE == Boolean.valueOf(true)); + } + + @Test + public void given_TrueValue_whenUsingTrue_thenTestPrimitiveEquality() { + assertTrue(true == true); + } + + @Test + public void given_TrueStringValue_whenUsingBooleanTrue_thenTestBooleanToString() { + assertEquals("true", Boolean.TRUE.toString()); + } + + @Test + public void given_PrimitiveValue_whenUsingStringValueOf_thenTestPrimitiveToString() { + assertEquals("true", String.valueOf(true)); + } + +}