From 580dd06fcb2e8a763b4981ccc04efc58f36fd43f Mon Sep 17 00:00:00 2001 From: Nicklavi11 Date: Sat, 29 Mar 2025 16:47:48 -0400 Subject: [PATCH 1/6] Added JUnit test for AbstractIterableAssert --- .../core/api/AbstractIterableAssertTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 assertj-core/src/test/java/org/assertj/core/api/AbstractIterableAssertTest.java diff --git a/assertj-core/src/test/java/org/assertj/core/api/AbstractIterableAssertTest.java b/assertj-core/src/test/java/org/assertj/core/api/AbstractIterableAssertTest.java new file mode 100644 index 00000000000..4a208d71929 --- /dev/null +++ b/assertj-core/src/test/java/org/assertj/core/api/AbstractIterableAssertTest.java @@ -0,0 +1,30 @@ +package org.assertj.core.api; + +import org.junit.jupiter.api.Test; +import java.util.List; +import static org.assertj.core.api.Assertions.*; + +public class AbstractIterableAssertTest { + + @Test + void shouldFilterListBasedOnCondition() { + // Setup + List names = List.of("Adam", "Bob", "Chandler"); + + // Test + ListAssert result = assertThat(names).filteredOn(name -> name.startsWith("A")); + + // Verify + result.containsExactly("Adam"); + } + + @Test + void shouldNotContainNullElements() { + // Setup + List names = List.of("Adam", "Bob", "Chandler"); + + // Test and Verify + assertThat(names).doesNotContainNull(); + } + +} From dbfc34859a6785b740819a42422c5613c148e2ed Mon Sep 17 00:00:00 2001 From: Nicklavi11 Date: Mon, 31 Mar 2025 21:59:55 -0400 Subject: [PATCH 2/6] Added test for Strings --- .../core/util/StringEmptyOrNullTest.java | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 assertj-core/src/test/java/org/assertj/core/util/StringEmptyOrNullTest.java diff --git a/assertj-core/src/test/java/org/assertj/core/util/StringEmptyOrNullTest.java b/assertj-core/src/test/java/org/assertj/core/util/StringEmptyOrNullTest.java new file mode 100644 index 00000000000..63eb505ce37 --- /dev/null +++ b/assertj-core/src/test/java/org/assertj/core/util/StringEmptyOrNullTest.java @@ -0,0 +1,42 @@ +package org.assertj.core.util; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.Test; + +public class StringEmptyOrNullTest { + @Test + void returnTrueIfStringIsNull() { + // setup + String input = null; + + // test + boolean result = Strings.isNullOrEmpty(input); + + //verify + assertTrue(result); + } + + @Test + void returnTrueIfStringIsEmpty() { + // setup + String input = ""; + + // test + boolean result = Strings.isNullOrEmpty(input); + + // verify + assertTrue(result); + } + + @Test + void returnFalseIfStringIsNotEmpty() { + // setup + String input = "Hello World!"; + + // test + boolean result = Strings.isNullOrEmpty(input); + + // verify + assertFalse(result); + } +} From b83f5987744687cca825e3ebee3eacf8d9477c40 Mon Sep 17 00:00:00 2001 From: Nicklavi11 Date: Wed, 2 Apr 2025 09:36:50 -0400 Subject: [PATCH 3/6] added test for NumberAssert.java --- .../org/assertj/core/api/NumberRangeTest.java | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 assertj-core/src/test/java/org/assertj/core/api/NumberRangeTest.java diff --git a/assertj-core/src/test/java/org/assertj/core/api/NumberRangeTest.java b/assertj-core/src/test/java/org/assertj/core/api/NumberRangeTest.java new file mode 100644 index 00000000000..f90ebbbc417 --- /dev/null +++ b/assertj-core/src/test/java/org/assertj/core/api/NumberRangeTest.java @@ -0,0 +1,46 @@ +package org.assertj.core.api; + +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; + +public class NumberRangeTest { + // typical case + @Test + void testTypicalNumber(){ + int number = 50; + + assertThat(number).isBetween(1, 100); + } + + // min + @Test + void testMinNumber(){ + int number = 1; + + assertThat(number).isBetween(1, 100); + } + + // min + 1 + @Test + void testMinPlusOneNumber(){ + int number = 2; + + assertThat(number).isBetween(1, 100); + } + + // max + @Test + void testMaxNumber(){ + int number = 100; + + assertThat(number).isBetween(1, 100); + } + + // max - 1 + @Test + void testMaxMinusOneNumber(){ + int number = 99; + + assertThat(number).isBetween(1, 100); + } +} From 2f6fc249846d916be63b50dee93f92483ff977ba Mon Sep 17 00:00:00 2001 From: Nicklavi11 Date: Wed, 2 Apr 2025 15:34:22 -0400 Subject: [PATCH 4/6] added test for AbstractCharSequenceAssert.java --- .../core/api/StringValidationTest.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 assertj-core/src/test/java/org/assertj/core/api/StringValidationTest.java diff --git a/assertj-core/src/test/java/org/assertj/core/api/StringValidationTest.java b/assertj-core/src/test/java/org/assertj/core/api/StringValidationTest.java new file mode 100644 index 00000000000..cf430edf9d8 --- /dev/null +++ b/assertj-core/src/test/java/org/assertj/core/api/StringValidationTest.java @@ -0,0 +1,45 @@ +package org.assertj.core.api; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Disabled; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +public class StringValidationTest { + // Equivalence class: Valid Strings + @Test + public void shouldPassForValidString() { + // These tests are expected to pass + assertThat("Hello").isNotBlank(); + assertThat("Hello World!").isNotBlank(); + assertThat("12345").isNotBlank(); + assertThat("!!!").isNotBlank(); + } + + // Equivalence class: Empty Strings + @Disabled // remove to test if the build fails + @Test + public void shouldFailForEmptyString() { + // This test is expected to fail + assertThatThrownBy(() -> assertThat("").isNotBlank()) + .isInstanceOf(AssertionError.class) + .hasMessageContaining("blank"); + } + + // Equivalence class: Whitespace Strings + @Disabled // remove to test if the build fails + @Test + public void shouldFailForWhitespaceString() { + // This test is expected to fail + assertThat(" ").isNotBlank(); + } + + // Equivalence class: Null Strings + @Disabled // remove to test if the build fails + @Test + public void shouldFailForNullString() { + // This test is expected to fail + String nullString = null; + assertThat(nullString).isNotBlank(); + } +} From 12653c350b12e00fe1e46b44e78ed95e95d51d91 Mon Sep 17 00:00:00 2001 From: Nicklavi11 Date: Wed, 9 Apr 2025 14:15:02 -0400 Subject: [PATCH 5/6] Added JUnit test for Lists.java --- .../java/org/assertj/core/util/ListsTest.java | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 assertj-core/src/test/java/org/assertj/core/util/ListsTest.java diff --git a/assertj-core/src/test/java/org/assertj/core/util/ListsTest.java b/assertj-core/src/test/java/org/assertj/core/util/ListsTest.java new file mode 100644 index 00000000000..a3cce90c0d9 --- /dev/null +++ b/assertj-core/src/test/java/org/assertj/core/util/ListsTest.java @@ -0,0 +1,40 @@ +package org.assertj.core.util; + +import org.junit.jupiter.api.Test; +import java.util.List; +import static org.junit.jupiter.api.Assertions.*; + +public class ListsTest { + // No elements in list, tests to make sure it returns an empty list + @Test + void testNewEmptyList() { + List emptyList = Lists.newArrayList(); + + // Checks if list is not null + assertNotNull(emptyList); + // List should be true if it is empty + assertTrue(emptyList.isEmpty()); + } + + // Single element list test, makes sure list knows the size and the value of the element + @Test + void testSingleElementList() { + List singleElementList = Lists.newArrayList(15); + // Tests the size of the list + assertEquals(1, singleElementList.size()); + // Tests the value of the element in the list + assertEquals(15, singleElementList.get(0)); + } + + // Multiple element list test, makes sure list knows the size and the values of each element + @Test + void testMultipleElementsList() { + List multipleElementsList = Lists.newArrayList("a", "b", "c"); + // Tests the size of the list + assertEquals(3, multipleElementsList.size()); + // Tests the values of each element in the list + assertEquals("a", multipleElementsList.get(0)); + assertEquals("b", multipleElementsList.get(1)); + assertEquals("c", multipleElementsList.get(2)); + } +} From f44931f6a0275f9c0c1f750aa369fd5296bcca88 Mon Sep 17 00:00:00 2001 From: Nicklavi11 Date: Wed, 9 Apr 2025 23:24:11 -0400 Subject: [PATCH 6/6] Added Mockito test for ConditionTest.java --- .../org/assertj/core/api/ConditionTest.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 assertj-core/src/test/java/org/assertj/core/api/ConditionTest.java diff --git a/assertj-core/src/test/java/org/assertj/core/api/ConditionTest.java b/assertj-core/src/test/java/org/assertj/core/api/ConditionTest.java new file mode 100644 index 00000000000..9307bee1894 --- /dev/null +++ b/assertj-core/src/test/java/org/assertj/core/api/ConditionTest.java @@ -0,0 +1,32 @@ +package org.assertj.core.api; + +import org.junit.jupiter.api.Test; +import static org.assertj.core.api.Assertions.assertThat; +import static org.mockito.Mockito.*; + +public class ConditionTest { + + @Test + void returnTrueWhenConditionIsMet() { + Condition mockCondition = mock(Condition.class); + when(mockCondition.matches("hello")).thenReturn(true); + + boolean result = mockCondition.matches("hello"); + + assertThat(result).isTrue(); + + verify(mockCondition).matches("hello"); + } + + @Test + void returnFalseWhenConditionIsNotMet() { + Condition mockCondition = mock(Condition.class); + when(mockCondition.matches("fail")).thenReturn(false); + + boolean result = mockCondition.matches("fail"); + + assertThat(result).isFalse(); + + verify(mockCondition).matches("fail"); + } +}