From c0ad53cb700389c5b138a552c352b7f71f8d597f Mon Sep 17 00:00:00 2001 From: HubbardRika Date: Fri, 25 Apr 2025 22:31:41 -0400 Subject: [PATCH 01/10] 1st test case. Test: StringAssert.isNotEmpty() Expectation: Assertion passes when string is not empty --- .../StringAssert_isNotEmpty_Test.java | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 RikaHubbardTestCases/StringAssert_isNotEmpty_Test.java diff --git a/RikaHubbardTestCases/StringAssert_isNotEmpty_Test.java b/RikaHubbardTestCases/StringAssert_isNotEmpty_Test.java new file mode 100644 index 0000000000..3ba1dd7bca --- /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(); +} + +} From 8ca35a87dc963c7e02afbef4b073cbd8e4e6ed36 Mon Sep 17 00:00:00 2001 From: HubbardRika Date: Fri, 25 Apr 2025 22:33:39 -0400 Subject: [PATCH 02/10] Test Case 2 Test: IntegerAssert.isPositive() Expectation: Assertion passes when integer is greater than 0 --- .../IntegerAssert_isPositive_Test.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 RikaHubbardTestCases/IntegerAssert_isPositive_Test.java diff --git a/RikaHubbardTestCases/IntegerAssert_isPositive_Test.java b/RikaHubbardTestCases/IntegerAssert_isPositive_Test.java new file mode 100644 index 0000000000..a5de819f09 --- /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 From 3a8539746092d89db9e0f1a69c88b261d4be77f5 Mon Sep 17 00:00:00 2001 From: HubbardRika Date: Fri, 25 Apr 2025 22:36:26 -0400 Subject: [PATCH 03/10] Test Case 3 Test: IntegerAssert.isNegative() Expectation: Assertion passes when integer is less than 0. --- .../IntegerAssert_isNegative_Test.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 RikaHubbardTestCases/IntegerAssert_isNegative_Test.java diff --git a/RikaHubbardTestCases/IntegerAssert_isNegative_Test.java b/RikaHubbardTestCases/IntegerAssert_isNegative_Test.java new file mode 100644 index 0000000000..c4bfadd114 --- /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 From 177fa17980ea245cd42de846ad00a5a0f3f0409b Mon Sep 17 00:00:00 2001 From: HubbardRika Date: Fri, 25 Apr 2025 22:38:24 -0400 Subject: [PATCH 04/10] test case 4 Test: ListAssert.contains() Expectation: Assertion passes when the list contains the given element. --- .../ListAssert_contains_Test.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 RikaHubbardTestCases/ListAssert_contains_Test.java diff --git a/RikaHubbardTestCases/ListAssert_contains_Test.java b/RikaHubbardTestCases/ListAssert_contains_Test.java new file mode 100644 index 0000000000..9efac05a5c --- /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 From 9280d48c229a9aec0563185b19487e245110fa68 Mon Sep 17 00:00:00 2001 From: HubbardRika Date: Fri, 25 Apr 2025 23:01:50 -0400 Subject: [PATCH 05/10] Test Case 5 Test: ListAssert.doesNotContain() Expectation: Assertion passes when the list does not contain the specified element. --- .../ListAssert_doesNotContain_Test.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 RikaHubbardTestCases/ListAssert_doesNotContain_Test.java diff --git a/RikaHubbardTestCases/ListAssert_doesNotContain_Test.java b/RikaHubbardTestCases/ListAssert_doesNotContain_Test.java new file mode 100644 index 0000000000..30d6222d4e --- /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"); +} +} From f415509c4f93d2f0dc4b8b31ecf0282351457a7e Mon Sep 17 00:00:00 2001 From: HubbardRika Date: Fri, 25 Apr 2025 23:03:20 -0400 Subject: [PATCH 06/10] Test Case 6 Test: MapAssert.hasSize() Expectation: Assertion passes when map has the expected number of entries. --- .../MapAssert_hasSize_Test.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 RikaHubbardTestCases/MapAssert_hasSize_Test.java diff --git a/RikaHubbardTestCases/MapAssert_hasSize_Test.java b/RikaHubbardTestCases/MapAssert_hasSize_Test.java new file mode 100644 index 0000000000..29895e50bf --- /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 From 046b3db018989aba6d773515b78350bb4bad1a23 Mon Sep 17 00:00:00 2001 From: HubbardRika Date: Fri, 25 Apr 2025 23:04:22 -0400 Subject: [PATCH 07/10] Test Case 7 Test: MapAssert.containsKeys() Expectation: Assertion passes when map contains all specified keys. --- .../MapAssert_containsKeys_Test.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 RikaHubbardTestCases/MapAssert_containsKeys_Test.java diff --git a/RikaHubbardTestCases/MapAssert_containsKeys_Test.java b/RikaHubbardTestCases/MapAssert_containsKeys_Test.java new file mode 100644 index 0000000000..e441a11275 --- /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 From 7817f5f7c6bcaa495f1b9ca27902e75aaf0b8653 Mon Sep 17 00:00:00 2001 From: HubbardRika Date: Fri, 25 Apr 2025 23:12:38 -0400 Subject: [PATCH 08/10] Test Case 8 Test: exception assertion Expectation: IllegalArgumentException to be thrown --- .../Exception_Assertions_Test.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 RikaHubbardTestCases/Exception_Assertions_Test.java diff --git a/RikaHubbardTestCases/Exception_Assertions_Test.java b/RikaHubbardTestCases/Exception_Assertions_Test.java new file mode 100644 index 0000000000..76c9c618e0 --- /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 From ad8a5584f4389d618a120d2824dbea5159b31387 Mon Sep 17 00:00:00 2001 From: HubbardRika Date: Fri, 25 Apr 2025 23:16:01 -0400 Subject: [PATCH 09/10] Test Case 9 Test: Soft Assert Expectation: 3 assertions, 2 of which will fail --- RikaHubbardTestCases/Soft_Assert_Test.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 RikaHubbardTestCases/Soft_Assert_Test.java diff --git a/RikaHubbardTestCases/Soft_Assert_Test.java b/RikaHubbardTestCases/Soft_Assert_Test.java new file mode 100644 index 0000000000..2768a464f0 --- /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 From 38da112bed1f292adb90517016e017e012deb7a3 Mon Sep 17 00:00:00 2001 From: HubbardRika Date: Fri, 25 Apr 2025 23:18:23 -0400 Subject: [PATCH 10/10] Test Case 10 Test: ArrayAssertions Expectations: Expect integer array to contain specific elements in correct order --- .../Array_Assertions_Test.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 RikaHubbardTestCases/Array_Assertions_Test.java diff --git a/RikaHubbardTestCases/Array_Assertions_Test.java b/RikaHubbardTestCases/Array_Assertions_Test.java new file mode 100644 index 0000000000..d987dae035 --- /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