Added code examples for BAEL-4300 article.

This commit is contained in:
Jordan Simpson
2020-06-25 15:16:48 -05:00
parent 86121f29f4
commit d42d817ac3
5 changed files with 98 additions and 0 deletions

View File

@@ -0,0 +1,29 @@
package com.baeldung.stringtoboolean;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
public class StringToBooleanUnitTest
{
@Test
public void givenStringTrue_whenUsingParseBoolean_thenTrue() {
assertThat(Boolean.parseBoolean("true")).isTrue();
}
@Test
public void givenStringTrue_whenUsingValueOf_thenTrue() {
assertThat(Boolean.valueOf("true")).isTrue();
}
@Test
public void givenStringTrue_whenUsingGetBoolean_thenFalse() {
assertThat(Boolean.getBoolean("true")).isFalse();
}
@Test
public void givenSystemProperty_whenUsingGetBoolean_thenTrue() {
System.setProperty("CODING_IS_FUN", "true");
assertThat(Boolean.getBoolean("CODING_IS_FUN")).isTrue();
}
}