Skip to content

Commit c75daff

Browse files
authored
Refactor Mockito snippets (eugenp#1616)
1 parent 0acc76d commit c75daff

2 files changed

Lines changed: 4 additions & 11 deletions

File tree

‎mockito/src/test/java/org/baeldung/mockito/MockitoConfigExamplesTest.java‎

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import org.junit.Test;
44
import org.mockito.Mockito;
5-
import org.mockito.invocation.InvocationOnMock;
6-
import org.mockito.stubbing.Answer;
75

86
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
97
import static org.hamcrest.Matchers.equalTo;
@@ -69,22 +67,17 @@ public final void givenBehaviorIsConfiguredToThrowExceptionOnSecondCall_whenCall
6967
}
7068

7169
@Test
72-
public final void whenMockMethodCallIsConfiguredToCallTheRealMethod_thenRealMetehodIsCalled() {
70+
public final void whenMockMethodCallIsConfiguredToCallTheRealMethod_thenRealMethodIsCalled() {
7371
final MyList listMock = Mockito.mock(MyList.class);
7472
when(listMock.size()).thenCallRealMethod();
7573

7674
assertThat(listMock.size(), equalTo(1));
7775
}
7876

7977
@Test
80-
public final void whenMockMethodCallIsConfiguredWithCustomAnswer_thenRealMetehodIsCalled() {
78+
public final void whenMockMethodCallIsConfiguredWithCustomAnswer_thenRealMethodIsCalled() {
8179
final MyList listMock = Mockito.mock(MyList.class);
82-
doAnswer(new Answer<String>() {
83-
@Override
84-
public final String answer(final InvocationOnMock invocation) {
85-
return "Always the same";
86-
}
87-
}).when(listMock).get(anyInt());
80+
doAnswer(invocation -> "Always the same").when(listMock).get(anyInt());
8881

8982
final String element = listMock.get(1);
9083
assertThat(element, is(equalTo("Always the same")));

‎spring-all/pom.xml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@
302302
<ehcache.version>3.1.3</ehcache.version>
303303
<easymock.version>3.4</easymock.version>
304304
<assertj.version>3.6.1</assertj.version>
305-
<jasperreports.version>6.4.0</jasperreports.version>
305+
<jasperreports.version>6.4.0</jasperreports.version>
306306

307307
</properties>
308308

0 commit comments

Comments
 (0)