Merge pull request #12555 from dkapil/task/JAVA-13627_2

JAVA-13627 Updated code to use assertThatThrownBy instead of assertTh…
This commit is contained in:
kwoyke 2022-07-31 22:12:24 +02:00 committed by GitHub
commit 6356579778
1 changed files with 5 additions and 6 deletions

View File

@ -2,7 +2,7 @@ package com.baeldung.mockito;
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
@ -33,11 +33,10 @@ public class MockitoMockUnitTest {
MyList listMock = mock(MyList.class, "myMock");
when(listMock.add(anyString())).thenReturn(false);
listMock.add(randomAlphabetic(6));
Throwable exceptionThrown = assertThrows(TooFewActualInvocations.class,
() -> verify(listMock, times(2)).add(anyString()));
assertThat(exceptionThrown.getMessage()).contains("myMock.add");
assertThatThrownBy(() -> verify(listMock, times(2)).add(anyString()))
.isInstanceOf(TooFewActualInvocations.class)
.hasMessageContaining("myMock.add");
}
private static class CustomAnswer implements Answer<Boolean> {