Testing
AssertJDemoTest
- Path
- pkg14testing/src/test/java/pkg14testing/AssertJDemoTest.java
- Package
- pkg14testing
- Study order
- 0
- Run
- Read this file. It has no standalone main method.
- Dependencies
- org.junit.jupiter.api.Test
There is no in-browser runner. This is the file from the curriculum, unchanged.
1package pkg14testing;2 3import org.junit.jupiter.api.Test;4 5import java.util.List;6 7import static org.assertj.core.api.Assertions.*;8 9class AssertJDemoTest {10 11 @Test12 void fluentAssertions() {13 Calculator calc = new Calculator();14 assertThat(calc.add(2, 3)).isEqualTo(5).isGreaterThan(4);15 assertThat("hello").containsIgnoringCase("HE");16 assertThat(List.of(1, 2, 3)).hasSize(3).contains(2);17 }18 19 @Test20 void exceptionAssertion() {21 assertThatThrownBy(() -> new Calculator().divide(1, 0))22 .isInstanceOf(IllegalArgumentException.class)23 .hasMessageContaining("zero");24 }25}