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 0000000000..4a208d7192 --- /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(); + } + +} 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 0000000000..9307bee189 --- /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"); + } +} 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 0000000000..f90ebbbc41 --- /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); + } +} 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 0000000000..cf430edf9d --- /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(); + } +} 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 0000000000..a3cce90c0d --- /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)); + } +} 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 0000000000..63eb505ce3 --- /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); + } +}