From 0828e8c3cd5afdcf811c514ea23f8a16c1e9909a Mon Sep 17 00:00:00 2001 From: Mona Mohamadinia Date: Tue, 2 Jun 2020 04:41:34 +0430 Subject: [PATCH] Added the Binary Examples --- .../StringToIntOrIntegerUnitTest.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/stringtoint/StringToIntOrIntegerUnitTest.java b/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/stringtoint/StringToIntOrIntegerUnitTest.java index 106f1fc974..4300e86c99 100644 --- a/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/stringtoint/StringToIntOrIntegerUnitTest.java +++ b/core-java-modules/core-java-string-conversions/src/test/java/com/baeldung/stringtoint/StringToIntOrIntegerUnitTest.java @@ -17,6 +17,15 @@ public class StringToIntOrIntegerUnitTest { assertThat(result).isEqualTo(42); } + @Test + public void givenBinaryString_whenParsingInt_shouldConvertToInt() { + String givenString = "101010"; + + int result = Integer.parseInt(givenString, 2); + + assertThat(result).isEqualTo(42); + } + @Test public void givenString_whenCallingIntegerValueOf_shouldConvertToInt() { String givenString = "42"; @@ -26,6 +35,15 @@ public class StringToIntOrIntegerUnitTest { assertThat(result).isEqualTo(new Integer(42)); } + @Test + public void givenBinaryString_whenCallingIntegerValueOf_shouldConvertToInt() { + String givenString = "101010"; + + Integer result = Integer.valueOf(givenString, 2); + + assertThat(result).isEqualTo(new Integer(42)); + } + @Test public void givenString_whenCallingIntegerConstructor_shouldConvertToInt() { String givenString = "42";