assertj-mockito is a library integrating mockito with AssertJ's soft assertions.
Usage
-
- Dependency
- gradle
testCompile 'org.assertj:assertj-mockito-junit4:1.0-SNAPSHOT'
- maven
<dependency> <groupId>org.assertj</groupId> <artifactId>assertj-mockito-junit4</artifactId> <version>1.0-SNAPSHOT</version> <scope>test</scope> </dependency>
- gradle
- Example
public class ValidCalculatorTest { @Rule public AssertJMockitoSoftAssertions softly = new AssertJMockitoSoftAssertions(); @Rule public MockitoRule rule = rule(); @Mock private Adder adder; @Test public void test() { ValidCalculator calculator = new ValidCalculator(adder); when(adder.add(1, 2)).thenReturn(3); int result = calculator.add(1, 2); verify(adder, times(1)).add(1, 2); softly.assertThat(result).isEqualTo(3); verifyNoMoreInteractions(adder); } }
- Dependency
-
- Dependency
- gradle
testCompile 'org.assertj:assertj-mockito-junit5:1.0-SNAPSHOT'
- maven
<dependency> <groupId>org.assertj</groupId> <artifactId>assertj-mockito-junit5</artifactId> <version>1.0-SNAPSHOT</version> <scope>test</scope> </dependency>
- gradle
- Example
@ExtendWith(AssertJMockitoExtension.class) public class ValidCalculatorTest { @Mock private Adder adder; @Test public void test(SoftAssertions softly) { ValidCalculator calculator = new ValidCalculator(adder); when(adder.add(1, 2)).thenReturn(3); int result = calculator.add(1, 2); verify(adder, times(1)).add(1, 2); softly.assertThat(result).isEqualTo(3); verifyNoMoreInteractions(adder); } }
- Dependency