Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<String> names = List.of("Adam", "Bob", "Chandler");

// Test
ListAssert<String> result = assertThat(names).filteredOn(name -> name.startsWith("A"));

// Verify
result.containsExactly("Adam");
}

@Test
void shouldNotContainNullElements() {
// Setup
List<String> names = List.of("Adam", "Bob", "Chandler");

// Test and Verify
assertThat(names).doesNotContainNull();
}

}
32 changes: 32 additions & 0 deletions assertj-core/src/test/java/org/assertj/core/api/ConditionTest.java
Original file line number Diff line number Diff line change
@@ -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<String> 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<String> mockCondition = mock(Condition.class);
when(mockCondition.matches("fail")).thenReturn(false);

boolean result = mockCondition.matches("fail");

assertThat(result).isFalse();

verify(mockCondition).matches("fail");
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
40 changes: 40 additions & 0 deletions assertj-core/src/test/java/org/assertj/core/util/ListsTest.java
Original file line number Diff line number Diff line change
@@ -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<String> 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<Integer> 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<String> 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));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}