diff --git a/RikaHubbardTestCases/Array_Assertions_Test.java b/RikaHubbardTestCases/Array_Assertions_Test.java new file mode 100644 index 00000000000..d987dae035c --- /dev/null +++ b/RikaHubbardTestCases/Array_Assertions_Test.java @@ -0,0 +1,19 @@ +package org.assertj.examples; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ArrayAssertionsTest { + + @Test + void shouldAssertArrayProperties() { + int[] numbers = {1, 2, 3, 4}; + + assertThat(numbers) + .hasSize(4) + .contains(3) + .containsExactly(1, 2, 3, 4) + .doesNotContain(5); + } +} \ No newline at end of file diff --git a/RikaHubbardTestCases/Exception_Assertions_Test.java b/RikaHubbardTestCases/Exception_Assertions_Test.java new file mode 100644 index 00000000000..76c9c618e0d --- /dev/null +++ b/RikaHubbardTestCases/Exception_Assertions_Test.java @@ -0,0 +1,17 @@ +package org.assertj.examples; + +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class ExceptionAssertionsTest { + + @Test + void shouldAssertExceptionThrown() { + assertThatThrownBy(() -> { + throw new IllegalArgumentException("Invalid argument"); + }) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Invalid"); + } +} \ No newline at end of file diff --git a/RikaHubbardTestCases/IntegerAssert_isNegative_Test.java b/RikaHubbardTestCases/IntegerAssert_isNegative_Test.java new file mode 100644 index 00000000000..c4bfadd1146 --- /dev/null +++ b/RikaHubbardTestCases/IntegerAssert_isNegative_Test.java @@ -0,0 +1,16 @@ +package org.assertj.core.api.integer; + +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.BDDAssertions.then; + +class IntegerAssert_isNegative_Test extends BaseTest { + + @Test + void should_pass_when_integer_is_negative() { + // Given + int value = -5; + + // When/then + then(value).isNegative(); + } +} \ No newline at end of file diff --git a/RikaHubbardTestCases/IntegerAssert_isPositive_Test.java b/RikaHubbardTestCases/IntegerAssert_isPositive_Test.java new file mode 100644 index 00000000000..a5de819f094 --- /dev/null +++ b/RikaHubbardTestCases/IntegerAssert_isPositive_Test.java @@ -0,0 +1,16 @@ +package org.assertj.core.api.integer; + +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.BDDAssertions.then; + +class IntegerAssert_isPositive_Test { + + @Test + void should_pass_when_integer_is_positive() { + // GIVEN + int value = 42; + + // WHEN/THEN + then(value).isPositive(); + } +} \ No newline at end of file diff --git a/RikaHubbardTestCases/ListAssert_contains_Test.java b/RikaHubbardTestCases/ListAssert_contains_Test.java new file mode 100644 index 00000000000..9efac05a5c2 --- /dev/null +++ b/RikaHubbardTestCases/ListAssert_contains_Test.java @@ -0,0 +1,19 @@ +package org.assertj.core.api.list; + +import org.junit.jupiter.api.Test; +import java.util.Arrays; +import java.util.List; +import static org.assertj.core.api.BDDAssertions.then; + + +class ListAssert_contains_Test extends BaseTest { + + @Test + void should_pass_when_list_contains_element() { + // GIVEN + List names = Arrays.asList("Alice", "Bob", "Charlie"); + + // WHEN/THEN + then(names).contains("Bob"); + } +} \ No newline at end of file diff --git a/RikaHubbardTestCases/ListAssert_doesNotContain_Test.java b/RikaHubbardTestCases/ListAssert_doesNotContain_Test.java new file mode 100644 index 00000000000..30d6222d4e6 --- /dev/null +++ b/RikaHubbardTestCases/ListAssert_doesNotContain_Test.java @@ -0,0 +1,15 @@ +package org.assertj.core.api.list; + +import org.junit.jupiter.api.Test; +import java.util.Arrays; +import java.util.List; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; + +Class ListAssert_doesNotContain_Test { + +@Test +void should_pass_when_list_does_not_contain_element() { + List names = Arrays.asList("Alice", "Bob", "Charlie"); + assertThat(names).doesNotContain("David"); +} +} diff --git a/RikaHubbardTestCases/MapAssert_containsKeys_Test.java b/RikaHubbardTestCases/MapAssert_containsKeys_Test.java new file mode 100644 index 00000000000..e441a11275e --- /dev/null +++ b/RikaHubbardTestCases/MapAssert_containsKeys_Test.java @@ -0,0 +1,18 @@ +package org.assertj.core.api.map; + +import org.junit.jupiter.api.Test; +import java.util.Map; +import static org.assertj.core.api.BDDAssertions.then; + + +class MapAssert_containsKeys_Test { + + @Test + void should_pass_when_map_contains_keys() { + + Map ageMap = Map.of("Alice", 30, "Bob", 25); + + + then(ageMap).containsKeys("Alice", "Bob"); + } +} \ No newline at end of file diff --git a/RikaHubbardTestCases/MapAssert_hasSize_Test.java b/RikaHubbardTestCases/MapAssert_hasSize_Test.java new file mode 100644 index 00000000000..29895e50bf6 --- /dev/null +++ b/RikaHubbardTestCases/MapAssert_hasSize_Test.java @@ -0,0 +1,18 @@ +package org.assertj.core.api.map; + +import org.junit.jupiter.api.Test; +import java.util.Map; +import static org.assertj.core.api.BDDAssertions.then; + + +class MapAssert_hasSize_Test extends BaseTest { + + @Test + void should_pass_when_map_has_expected_size() { + + Map ageMap = Map.of("Alice", 30, "Bob", 25); + + + then(ageMap).hasSize(2); + } +} \ No newline at end of file diff --git a/RikaHubbardTestCases/Soft_Assert_Test.java b/RikaHubbardTestCases/Soft_Assert_Test.java new file mode 100644 index 00000000000..2768a464f0a --- /dev/null +++ b/RikaHubbardTestCases/Soft_Assert_Test.java @@ -0,0 +1,18 @@ +package org.assertj.examples; + +import org.assertj.core.api.SoftAssertions; +import org.junit.jupiter.api.Test; + +public class SoftAssertionsTest { + + @Test + void shouldAssertMultipleConditionsSoftly() { + SoftAssertions softly = new SoftAssertions(); + + softly.assertThat("Hello").startsWith("H"); // passes + softly.assertThat(42).isGreaterThan(50); // fails + softly.assertThat(true).isFalse(); // fails + + softly.assertAll(); // will show all failed assertions + } +} \ No newline at end of file diff --git a/RikaHubbardTestCases/StringAssert_isNotEmpty_Test.java b/RikaHubbardTestCases/StringAssert_isNotEmpty_Test.java new file mode 100644 index 00000000000..3ba1dd7bcae --- /dev/null +++ b/RikaHubbardTestCases/StringAssert_isNotEmpty_Test.java @@ -0,0 +1,11 @@ +import static org.assertj.core.api.BDDAssertions.then; +import static org.assertj.core.util.AssertionsUtil.expectAssertionError; + +Class StringAssert_isNotEmpty_Test extends BaseTest { + + @Test +void should_pass_when_string_is_not_empty() { + assertThat("AssertJ").isNotEmpty(); +} + +}