[BAEL-6297_boolean-to-str] convert boolean to java article (#13729)
* [BAEL-6297_boolean-to-str] convert boolean to java article * [BAEL-6297_boolean-to-str] using Boolean.FALSE instead of false for the Boolean variable * [BAEL-6297_boolean-to-str] rename test methods
This commit is contained in:
		
							parent
							
								
									11f740192c
								
							
						
					
					
						commit
						c40bdd9f36
					
				
							
								
								
									
										5
									
								
								core-java-modules/core-java-booleans/README.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								core-java-modules/core-java-booleans/README.md
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,5 @@ | ||||
| ## Core Java Booleans | ||||
| 
 | ||||
| This module contains articles about Java Booleans. | ||||
| 
 | ||||
| ### Relevant Articles:  | ||||
							
								
								
									
										16
									
								
								core-java-modules/core-java-booleans/pom.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										16
									
								
								core-java-modules/core-java-booleans/pom.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,16 @@ | ||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||||
|          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||
|          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||
|   <modelVersion>4.0.0</modelVersion> | ||||
|   <artifactId>core-java-booleans</artifactId> | ||||
|   <version>0.1.0-SNAPSHOT</version> | ||||
|   <name>core-java-booleans</name> | ||||
|   <packaging>jar</packaging> | ||||
| 
 | ||||
|   <parent> | ||||
|     <groupId>com.baeldung.core-java-modules</groupId> | ||||
|     <artifactId>core-java-modules</artifactId> | ||||
|     <version>0.0.1-SNAPSHOT</version> | ||||
|   </parent> | ||||
| </project> | ||||
| @ -0,0 +1,48 @@ | ||||
| package com.baeldung.booleans; | ||||
| 
 | ||||
| import org.junit.jupiter.api.Test; | ||||
| 
 | ||||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||||
| 
 | ||||
| public class BooleanToStringUnitTest { | ||||
|     String optionToString(String optionName, boolean optionValue) { | ||||
|         return String.format("The option '%s' is %s.", optionName, optionValue ? "Enabled" : "Disabled"); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void givenPrimitiveBoolean_whenConvertingUsingTernaryOperator_thenSuccess() { | ||||
|         boolean primitiveBoolean = true; | ||||
|         assertEquals("true", primitiveBoolean ? "true" : "false"); | ||||
| 
 | ||||
|         primitiveBoolean = false; | ||||
|         assertEquals("false", primitiveBoolean ? "true" : "false"); | ||||
| 
 | ||||
|         assertEquals("The option 'IgnoreWarnings' is Enabled.", optionToString("IgnoreWarnings", true)); | ||||
|     } | ||||
| 
 | ||||
| 
 | ||||
|     @Test | ||||
|     void givenBooleanObject_whenConvertingUsingBooleanToString_thenSuccess() { | ||||
|         Boolean myBoolean = Boolean.TRUE; | ||||
|         assertEquals("true", myBoolean.toString()); | ||||
| 
 | ||||
|         myBoolean = Boolean.FALSE; | ||||
|         assertEquals("false", myBoolean.toString()); | ||||
| 
 | ||||
|         Boolean nullBoolean = null; | ||||
|         assertThrows(NullPointerException.class, () -> nullBoolean.toString()); | ||||
|     } | ||||
| 
 | ||||
|     @Test | ||||
|     void givenBooleanObject_whenConvertingUsingStringValueOf_thenSuccess() { | ||||
|         Boolean myBoolean = Boolean.TRUE; | ||||
|         assertEquals("true", String.valueOf(myBoolean)); | ||||
| 
 | ||||
|         myBoolean = Boolean.FALSE; | ||||
|         assertEquals("false", String.valueOf(myBoolean)); | ||||
| 
 | ||||
|         Boolean nullBoolean = null; | ||||
|         assertEquals("null", String.valueOf(nullBoolean)); | ||||
|     } | ||||
| } | ||||
| @ -38,6 +38,7 @@ | ||||
|         <module>core-java-arrays-convert</module> | ||||
|         <module>core-java-arrays-operations-basic</module> | ||||
|         <module>core-java-arrays-operations-advanced</module> | ||||
|         <module>core-java-booleans</module> | ||||
|         <module>core-java-char</module> | ||||
|         <module>core-java-collections</module> | ||||
|         <module>core-java-collections-2</module> | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user