1
1
/*
2
- * Copyright 2010-2019 the original author or authors.
2
+ * Copyright 2010-2020 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
20
20
import static org .mockito .ArgumentMatchers .any ;
21
21
import static org .mockito .ArgumentMatchers .anyInt ;
22
22
import static org .mockito .ArgumentMatchers .anyString ;
23
+ import static org .mockito .BDDMockito .given ;
24
+ import static org .mockito .BDDMockito .willCallRealMethod ;
25
+ import static org .mockito .BDDMockito .willReturn ;
23
26
import static org .mockito .Mockito .atLeastOnce ;
24
- import static org .mockito .Mockito .doCallRealMethod ;
25
- import static org .mockito .Mockito .doReturn ;
26
27
import static org .mockito .Mockito .mock ;
27
28
import static org .mockito .Mockito .never ;
28
29
import static org .mockito .Mockito .spy ;
29
30
import static org .mockito .Mockito .times ;
30
31
import static org .mockito .Mockito .verify ;
31
- import static org .mockito .Mockito .when ;
32
32
33
33
import java .util .Collections ;
34
34
import java .util .concurrent .ExecutorService ;
@@ -62,7 +62,7 @@ public void testWithListener() throws Exception {
62
62
com .rabbitmq .client .ConnectionFactory mockConnectionFactory = mock (com .rabbitmq .client .ConnectionFactory .class );
63
63
com .rabbitmq .client .Connection mockConnection = mock (com .rabbitmq .client .Connection .class );
64
64
65
- when (mockConnectionFactory .newConnection (any (ExecutorService .class ), anyString ())).thenReturn (mockConnection );
65
+ given (mockConnectionFactory .newConnection (any (ExecutorService .class ), anyString ())).willReturn (mockConnection );
66
66
67
67
final AtomicInteger called = new AtomicInteger (0 );
68
68
AbstractConnectionFactory connectionFactory = createConnectionFactory (mockConnectionFactory );
@@ -81,7 +81,7 @@ public void onClose(Connection connection) {
81
81
}));
82
82
83
83
Log logger = spy (TestUtils .getPropertyValue (connectionFactory , "logger" , Log .class ));
84
- doReturn (true ).when (logger ).isInfoEnabled ();
84
+ willReturn (true ).given (logger ).isInfoEnabled ();
85
85
new DirectFieldAccessor (connectionFactory ).setPropertyValue ("logger" , logger );
86
86
Connection con = connectionFactory .createConnection ();
87
87
assertThat (called .get ()).isEqualTo (1 );
@@ -122,7 +122,7 @@ public void testWithListenerRegisteredAfterOpen() throws Exception {
122
122
com .rabbitmq .client .ConnectionFactory mockConnectionFactory = mock (com .rabbitmq .client .ConnectionFactory .class );
123
123
com .rabbitmq .client .Connection mockConnection = mock (com .rabbitmq .client .Connection .class );
124
124
125
- when (mockConnectionFactory .newConnection (any (ExecutorService .class ), anyString ())).thenReturn (mockConnection );
125
+ given (mockConnectionFactory .newConnection (any (ExecutorService .class ), anyString ())).willReturn (mockConnection );
126
126
127
127
final AtomicInteger called = new AtomicInteger (0 );
128
128
AbstractConnectionFactory connectionFactory = createConnectionFactory (mockConnectionFactory );
@@ -166,11 +166,11 @@ public void testCloseInvalidConnection() throws Exception {
166
166
com .rabbitmq .client .Connection mockConnection1 = mock (com .rabbitmq .client .Connection .class );
167
167
com .rabbitmq .client .Connection mockConnection2 = mock (com .rabbitmq .client .Connection .class );
168
168
169
- when (mockConnectionFactory .newConnection (any (ExecutorService .class ), anyString ()))
170
- .thenReturn (mockConnection1 , mockConnection2 );
169
+ given (mockConnectionFactory .newConnection (any (ExecutorService .class ), anyString ()))
170
+ .willReturn (mockConnection1 , mockConnection2 );
171
171
// simulate a dead connection
172
- when (mockConnection1 .isOpen ()).thenReturn (false );
173
- when (mockConnection2 .createChannel ()).thenReturn (mock (Channel .class ));
172
+ given (mockConnection1 .isOpen ()).willReturn (false );
173
+ given (mockConnection2 .createChannel ()).willReturn (mock (Channel .class ));
174
174
175
175
AbstractConnectionFactory connectionFactory = createConnectionFactory (mockConnectionFactory );
176
176
@@ -199,9 +199,9 @@ public void testDestroyBeforeUsed() throws Exception {
199
199
@ Test
200
200
public void testCreatesConnectionWithGivenFactory () {
201
201
com .rabbitmq .client .ConnectionFactory mockConnectionFactory = mock (com .rabbitmq .client .ConnectionFactory .class );
202
- doCallRealMethod ().when (mockConnectionFactory ).params (any (ExecutorService .class ));
203
- doCallRealMethod ().when (mockConnectionFactory ).setThreadFactory (any (ThreadFactory .class ));
204
- doCallRealMethod ().when (mockConnectionFactory ).getThreadFactory ();
202
+ willCallRealMethod ().given (mockConnectionFactory ).params (any (ExecutorService .class ));
203
+ willCallRealMethod ().given (mockConnectionFactory ).setThreadFactory (any (ThreadFactory .class ));
204
+ willCallRealMethod ().given (mockConnectionFactory ).getThreadFactory ();
205
205
206
206
AbstractConnectionFactory connectionFactory = createConnectionFactory (mockConnectionFactory );
207
207
ThreadFactory connectionThreadFactory = new CustomizableThreadFactory ("connection-thread-" );
0 commit comments