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.tests;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;

public class ListAssertContainsOnlyTest {

// Valid partition: matches expected elements
@Test
void testContainsOnlyValidPartition() {
List<Integer> actual = List.of(1, 2, 3);
Assertions.assertThat(actual).containsOnly(1, 2, 3);
}

// Invalid partition: has an extra element
@Test
void testContainsOnlyInvalidPartition() {
List<Integer> actual = List.of(1, 2, 3, 4);
Assertions.assertThat(actual).doesNotContain(5);
}

// Valid partition with duplicates
@Test
void testContainsOnlyWithDuplicates() {
List<Integer> actual = List.of(1, 1, 2, 3);
Assertions.assertThat(actual).containsOnly(1, 2, 3);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package org.assertj.core.api;

import static org.assertj.core.api.Assertions.assertThat;

import java.util.ArrayList;
import java.util.List;

import org.junit.jupiter.api.Test;

/**
* Boundary Value Test for ListAssert.hasSize().
* This test checks how AssertJ handles lists with boundary sizes.
*/
class ListAssert_hasSize_Test {

// Lower boundary: empty list
@Test
void should_pass_if_list_is_empty() {
List<String> emptyList = new ArrayList<>();
assertThat(emptyList).hasSize(0);
}

// Nominal boundary: single item
@Test
void should_pass_if_list_has_one_item() {
List<String> singleItem = List.of("AssertJ");
assertThat(singleItem).hasSize(1);
}

// Upper boundary: large list
@Test
void should_pass_if_list_has_1000_items() {
List<Integer> largeList = new ArrayList<>();
for (int i = 0; i < 1000; i++) {
largeList.add(i);
}
assertThat(largeList).hasSize(1000);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.example;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class ObjectAssertInstanceTest {

@Test
void should_pass_if_object_is_instance_of_expected_type() {
Number obj = Integer.valueOf(42); // Definition of obj

// Use of obj in assertion - expected to pass
Assertions.assertThat(obj).isInstanceOf(Integer.class);
}

@Test
void should_fail_if_object_is_not_instance_of_expected_type() {
Number obj = Double.valueOf(3.14); // Definition of obj

// Use of obj in assertion - should NOT be Integer
Assertions.assertThat(obj).isNotInstanceOf(Integer.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.assertj.core.api;

import org.junit.jupiter.api.Test;

import java.util.Optional;

import static org.assertj.core.api.Assertions.assertThat;

public class OptionalAssertPathTest {

// Path 1: Optional is empty
@Test
void should_fail_if_optional_is_empty() {
Optional<String> empty = Optional.empty();
assertThat(empty).isEmpty();
}

// Path 2: Optional is present
@Test
void should_pass_if_optional_is_present() {
Optional<String> value = Optional.of("AssertJ");
assertThat(value).isPresent();
assertThat(value.get()).isEqualTo("AssertJ");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.example;

import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;

public class StringAssertIntegrationTest {

@Test
void should_pass_when_string_matches_all_conditions() {
String sentence = "AssertJ makes testing easier.";

Assertions.assertThat(sentence)
.startsWith("AssertJ")
.contains("testing")
.endsWith("easier.");
}

@Test
void should_fail_when_any_condition_does_not_match() {
String sentence = "Assertions help simplify tests.";

Assertions.assertThat(sentence)
.doesNotContain("difficult")
.startsWith("Assertions")
.endsWith("tests.");
}
}