Skip to content

Commit c9a6b0f

Browse files
committed
prevent abuse of mock
1 parent 4126b80 commit c9a6b0f

File tree

4 files changed

+22
-22
lines changed

4 files changed

+22
-22
lines changed

Diff for: aliyun-java-sdk-core/src/test/java/com/aliyuncs/http/HttpUtilTest.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public void testHttpDebug() {
4444

4545
@Test
4646
public void testDebugHttpRequest() throws ClientException {
47-
HttpRequest request = mock(HttpRequest.class);
47+
HttpRequest request = new HttpRequest("mock url");
4848
Mockito.when(request.getSysMethod()).thenReturn(MethodType.GET);
4949
Mockito.when(request.getSysUrl()).thenReturn("http://test.domain");
5050
Map<String, String> requestHeaders = new HashMap<String, String>();
@@ -110,7 +110,7 @@ public void testDebugHttpResponse() throws ClientException {
110110

111111
@Test
112112
public void testDebugHttpRquestException() throws ClientException {
113-
HttpRequest request = mock(HttpRequest.class);
113+
HttpRequest request = new HttpRequest("mock url");
114114
Mockito.when(request.getSysMethod()).thenReturn(MethodType.GET);
115115
Mockito.when(request.getSysUrl()).thenReturn("httpss://test.domain/jdj");
116116
Map<String, String> requestHeaders = new HashMap<String, String>();
@@ -163,44 +163,44 @@ public void testDebugHttpResponseException() throws ClientException {
163163

164164
@Test
165165
public void testGetJDKProxyException() throws ClientException {
166-
HttpRequest request = mock(HttpRequest.class);
166+
HttpRequest request = new HttpRequest("mock url");
167167
thrown.expect(ClientException.class);
168168
Proxy proxy = HttpUtil.getJDKProxy("http0://www.aliyun.com", null, request);
169169
Assert.assertNotNull(proxy);
170170
}
171171

172172
@Test
173173
public void testGetJDKProxyEnvProxyHasUserInfo() throws ClientException {
174-
HttpRequest request = mock(HttpRequest.class);
174+
HttpRequest request = new HttpRequest("mock url");
175175
Proxy proxy = HttpUtil.getJDKProxy(null, "http://user:[email protected]", request);
176176
Assert.assertNotNull(proxy);
177177
}
178178

179179
@Test
180180
public void testGetJDKProxyEnvProxyNoUserInfo() throws ClientException {
181-
HttpRequest request = mock(HttpRequest.class);
181+
HttpRequest request = new HttpRequest("mock url");
182182
Proxy proxy = HttpUtil.getJDKProxy(null, "http://www.aliyun.com:80", request);
183183
Assert.assertNotNull(proxy);
184184
}
185185

186186
@Test
187187
public void testGetApacheProxyException() throws ClientException {
188-
HttpRequest request = mock(HttpRequest.class);
188+
HttpRequest request = new HttpRequest("mock url");
189189
thrown.expect(ClientException.class);
190190
HttpHost proxy = HttpUtil.getApacheProxy("http0://www.aliyun.com", null, request);
191191
Assert.assertNotNull(proxy);
192192
}
193193

194194
@Test
195195
public void testGetApacheProxyEnvProxyHasUserInfo() throws ClientException {
196-
HttpRequest request = mock(HttpRequest.class);
196+
HttpRequest request = new HttpRequest("mock url");
197197
HttpHost proxy = HttpUtil.getApacheProxy(null, "http://user:[email protected]", request);
198198
Assert.assertNotNull(proxy);
199199
}
200200

201201
@Test
202202
public void testGetApacheProxyEnvProxyNoUserInfo() throws ClientException {
203-
HttpRequest request = mock(HttpRequest.class);
203+
HttpRequest request = new HttpRequest("mock url");
204204
HttpHost proxy = HttpUtil.getApacheProxy(null, "http://www.aliyun.com:80", request);
205205
Assert.assertNotNull(proxy);
206206
}

Diff for: aliyun-java-sdk-core/src/test/java/com/aliyuncs/http/clients/CompatibleUrlConnClientTest.java

+12-12
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public void asyncInvokeTest() throws ClientException, IOException {
7171
when(config.getSslSocketFactory()).thenReturn(sslSocketFactory);
7272
when(config.isIgnoreSSLCerts()).thenReturn(false);
7373
CompatibleUrlConnClient client = new CompatibleUrlConnClient(config);
74-
HttpRequest request = mock(HttpRequest.class);
74+
HttpRequest request = new HttpRequest("mockurl");
7575
CallBack callback = mock(CallBack.class);
7676
client.asyncInvoke(request, callback);
7777
client.close();
@@ -121,7 +121,7 @@ public void buildHttpConnectionNullSysUrlTest() throws Exception {
121121
when(config.isIgnoreSSLCerts()).thenReturn(true);
122122
CompatibleUrlConnClient client = new CompatibleUrlConnClient(config);
123123
thrown.expect(IllegalArgumentException.class);
124-
HttpRequest request = mock(HttpRequest.class);
124+
HttpRequest request = new HttpRequest("mock url");
125125
Whitebox.invokeMethod(client, "buildHttpConnection", request);
126126
}
127127

@@ -133,7 +133,7 @@ public void buildHttpConnectionNullSysMethodTest() throws Exception {
133133
when(config.isIgnoreSSLCerts()).thenReturn(true);
134134
CompatibleUrlConnClient client = new CompatibleUrlConnClient(config);
135135
thrown.expect(IllegalArgumentException.class);
136-
HttpRequest request = mock(HttpRequest.class);
136+
HttpRequest request = new HttpRequest("mock url");
137137
when(request.getSysUrl()).thenReturn("sysUrl");
138138
Whitebox.invokeMethod(client, "buildHttpConnection", request);
139139
}
@@ -148,7 +148,7 @@ public void buildHttpConnectionPOSTMethodAndNullContentAndHttpsTest() throws Exc
148148
CompatibleUrlConnClient client = PowerMockito.spy(client0);
149149
Proxy proxy = Proxy.NO_PROXY;
150150
PowerMockito.doReturn(proxy).when(client, "calcProxy", any(URL.class), any(HttpRequest.class));
151-
HttpRequest request = mock(HttpRequest.class);
151+
HttpRequest request = new HttpRequest("mock url");
152152
when(request.getSysMethod()).thenReturn(MethodType.POST);
153153
when(request.getSysUrl()).thenReturn("https://www.aliyun.com");
154154
when(request.getSysConnectTimeout()).thenReturn(120);
@@ -178,7 +178,7 @@ public void buildHttpConnectionPOSTMethodAndHttpTest() throws Exception {
178178
CompatibleUrlConnClient client = PowerMockito.spy(client0);
179179
Proxy proxy = Proxy.NO_PROXY;
180180
PowerMockito.doReturn(proxy).when(client, "calcProxy", any(URL.class), any(HttpRequest.class));
181-
HttpRequest request = mock(HttpRequest.class);
181+
HttpRequest request = new HttpRequest("mock url");
182182
when(request.getHttpContent()).thenReturn("content".getBytes());
183183
when(request.getSysMethod()).thenReturn(MethodType.POST);
184184
when(request.getSysUrl()).thenReturn("http://www.aliyun.com");
@@ -196,7 +196,7 @@ public void buildHttpConnectionGETMethodAndHttpsTest() throws Exception {
196196
CompatibleUrlConnClient client = PowerMockito.spy(client0);
197197
Proxy proxy = Proxy.NO_PROXY;
198198
PowerMockito.doReturn(proxy).when(client, "calcProxy", any(URL.class), any(HttpRequest.class));
199-
HttpRequest request = mock(HttpRequest.class);
199+
HttpRequest request = new HttpRequest("mock url");
200200
when(request.getHttpContent()).thenReturn("content".getBytes());
201201
when(request.getSysMethod()).thenReturn(MethodType.POST);
202202
when(request.getSysUrl()).thenReturn("https://www.aliyun.com");
@@ -216,7 +216,7 @@ public void buildHttpConnectionGETMethodAndNullContentTest() throws Exception {
216216
CompatibleUrlConnClient client = PowerMockito.spy(client0);
217217
Proxy proxy = Proxy.NO_PROXY;
218218
PowerMockito.doReturn(proxy).when(client, "calcProxy", any(URL.class), any(HttpRequest.class));
219-
HttpRequest request = mock(HttpRequest.class);
219+
HttpRequest request = new HttpRequest("mock url");
220220
when(request.getHttpContent()).thenReturn(null);
221221
when(request.getSysMethod()).thenReturn(MethodType.GET);
222222
when(request.getSysUrl()).thenReturn("http://www.aliyun.com");
@@ -271,7 +271,7 @@ public void syncInvokeIOExceptionTest() throws Exception {
271271
when(config.isIgnoreSSLCerts()).thenReturn(true);
272272
CompatibleUrlConnClient client0 = new CompatibleUrlConnClient(config);
273273
CompatibleUrlConnClient client = PowerMockito.spy(client0);
274-
HttpRequest request = mock(HttpRequest.class);
274+
HttpRequest request = new HttpRequest("mock url");
275275
HttpURLConnection connection = mock(HttpURLConnection.class);
276276
doThrow(new IOException()).when(connection).connect();
277277
PowerMockito.doReturn(connection).when(client, "buildHttpConnection", request);
@@ -292,7 +292,7 @@ public void syncInvokeNormalAndNoneMethodAndContentIsNotEmptyTest() throws Excep
292292
when(config.isIgnoreSSLCerts()).thenReturn(true);
293293
CompatibleUrlConnClient client0 = new CompatibleUrlConnClient(config);
294294
CompatibleUrlConnClient client = PowerMockito.spy(client0);
295-
HttpRequest request = mock(HttpRequest.class);
295+
HttpRequest request = new HttpRequest("mock url");
296296
when(request.getHttpContent()).thenReturn("http content".getBytes());
297297
HttpURLConnection connection = mock(HttpURLConnection.class);
298298
doNothing().when(connection).connect();
@@ -316,7 +316,7 @@ public void syncInvokeNormalAndGetMethodAndContentIsNotEmptyTest() throws Except
316316
when(config.isIgnoreSSLCerts()).thenReturn(true);
317317
CompatibleUrlConnClient client0 = new CompatibleUrlConnClient(config);
318318
CompatibleUrlConnClient client = PowerMockito.spy(client0);
319-
HttpRequest request = mock(HttpRequest.class);
319+
HttpRequest request = new HttpRequest("mock url");
320320
when(request.getSysMethod()).thenReturn(MethodType.GET);
321321
when(request.getHttpContent()).thenReturn("http content".getBytes());
322322
HttpURLConnection connection = mock(HttpURLConnection.class);
@@ -345,7 +345,7 @@ public void syncInvokeNormalAndPostMethodAndContentIsNotEmptyTest() throws Excep
345345
when(config.isIgnoreSSLCerts()).thenReturn(true);
346346
CompatibleUrlConnClient client0 = new CompatibleUrlConnClient(config);
347347
CompatibleUrlConnClient client = PowerMockito.spy(client0);
348-
HttpRequest request = mock(HttpRequest.class);
348+
HttpRequest request = new HttpRequest("mock url");
349349
when(request.getSysMethod()).thenReturn(MethodType.POST);
350350
when(request.getHttpContent()).thenReturn("http content".getBytes());
351351
HttpURLConnection connection = mock(HttpURLConnection.class);
@@ -373,7 +373,7 @@ public void syncInvokeNormalAndContentIsEmptyTest() throws Exception {
373373
when(config.isIgnoreSSLCerts()).thenReturn(true);
374374
CompatibleUrlConnClient client0 = new CompatibleUrlConnClient(config);
375375
CompatibleUrlConnClient client = PowerMockito.spy(client0);
376-
HttpRequest request = mock(HttpRequest.class);
376+
HttpRequest request = new HttpRequest("mock url");
377377
when(request.getSysMethod()).thenReturn(MethodType.GET);
378378
when(request.getHttpContent()).thenReturn("".getBytes());
379379
HttpURLConnection connection = mock(HttpURLConnection.class);

Diff for: aliyun-java-sdk-core/src/test/java/com/aliyuncs/policy/retry/RetryPolicyTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public void retryTest() throws InterruptedException {
8282
.build();
8383

8484
String coordinate = "nanhe:test";
85-
HttpRequest request = mock(HttpRequest.class);
85+
HttpRequest request = new HttpRequest("mock url");
8686
RetryPolicyContext context = RetryPolicyContext.builder()
8787
.coordinate(coordinate)
8888
.httpRequest(request)

Diff for: aliyun-java-sdk-core/src/test/java/com/aliyuncs/utils/LogUtilsTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public void logUnitGetSetTest() throws ClientException {
164164
null, resHeaders);
165165
mockLogUtils();
166166
LogUtils.LogUnit logUnit = new LogUtils.LogUnit(httpRequest, httpResponse);
167-
HttpRequest request = mock(HttpRequest.class);
167+
HttpRequest request = new HttpRequest("mock url");
168168
logUnit.setHttpRequest(request);
169169
Assert.assertEquals(request, logUnit.getHttpRequest());
170170

0 commit comments

Comments
 (0)