Skip to content

Commit 452f76b

Browse files
ssy352959096JacksonTian
authored andcommitted
修改代码符合规范
1 parent 86e6845 commit 452f76b

10 files changed

+174
-119
lines changed

aliyun-java-sdk-core/src/test/java/com/aliyuncs/AcsErrorTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
package com.aliyuncs;
22

3-
import com.aliyuncs.transform.UnmarshallerContext;
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
46
import org.junit.Assert;
57
import org.junit.Test;
68

7-
import java.util.HashMap;
8-
import java.util.Map;
9+
import com.aliyuncs.transform.UnmarshallerContext;
910

1011
public class AcsErrorTest {
1112

12-
1313
@Test
1414
public void toStringTest() {
15-
AcsErrorUnmarshaller unmarshaller = new AcsErrorUnmarshaller();
1615
AcsError acsError = new AcsError();
17-
Assert.assertEquals("AcsError{statusCode=0, errorCode='null', errorMessage='null', " +
18-
"requestId='null'}", acsError.toString());
16+
Assert.assertEquals("AcsError{statusCode=0, errorCode='null', errorMessage='null', " + "requestId='null'}",
17+
acsError.toString());
1918
}
2019

2120
@Test
@@ -51,5 +50,7 @@ public void acsErrorUnmarshallerTest() {
5150
Assert.assertEquals("Error.message", acsError.getErrorMessage());
5251
Assert.assertEquals(200, acsError.getStatusCode());
5352

53+
AcsErrorUnmarshaller unmarshaller = new AcsErrorUnmarshaller();
54+
Assert.assertTrue(unmarshaller instanceof AcsErrorUnmarshaller);
5455
}
5556
}

aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/AuthTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@
2525
import com.aliyuncs.http.FormatType;
2626
import org.junit.Test;
2727

28-
import java.security.InvalidKeyException;
2928
import java.util.Map;
3029

3130
import static org.junit.Assert.assertEquals;
32-
import static org.junit.Assert.fail;
3331

3432
@SuppressWarnings("unchecked")
3533
public class AuthTest {

aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/ECSMetadataServiceCredentialsFetcherTest.java

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
11
package com.aliyuncs.auth;
22

3-
import com.aliyuncs.exceptions.ClientException;
4-
import com.aliyuncs.http.HttpRequest;
5-
import com.aliyuncs.http.HttpResponse;
6-
import com.aliyuncs.http.clients.CompatibleUrlConnClient;
3+
import static org.mockito.Matchers.any;
4+
import static org.mockito.Mockito.mock;
5+
import static org.mockito.Mockito.when;
6+
7+
import java.io.IOException;
8+
import java.net.HttpURLConnection;
9+
import java.net.MalformedURLException;
10+
import java.net.URL;
11+
712
import org.junit.Assert;
813
import org.junit.Rule;
914
import org.junit.Test;
@@ -14,14 +19,10 @@
1419
import org.powermock.core.classloader.annotations.PrepareForTest;
1520
import org.powermock.modules.junit4.PowerMockRunner;
1621

17-
import java.io.IOException;
18-
import java.net.HttpURLConnection;
19-
import java.net.MalformedURLException;
20-
import java.net.URL;
21-
22-
import static org.mockito.Matchers.any;
23-
import static org.mockito.Mockito.mock;
24-
import static org.mockito.Mockito.when;
22+
import com.aliyuncs.exceptions.ClientException;
23+
import com.aliyuncs.http.HttpRequest;
24+
import com.aliyuncs.http.HttpResponse;
25+
import com.aliyuncs.http.clients.CompatibleUrlConnClient;
2526

2627
@RunWith(PowerMockRunner.class)
2728
@PrepareForTest(CompatibleUrlConnClient.class)
@@ -31,7 +32,8 @@ public class ECSMetadataServiceCredentialsFetcherTest {
3132

3233
@Test
3334
public void test() throws MalformedURLException {
34-
String url = "http://1abfwefwe/f\\fwe000))00.100.100.200/latest/meta-data/ram/security-credentials//%%http:///\\ ```////~!@#$%^&*()_+|:<>?|MN";
35+
String url = "http://1abfwefwe/f\\fwe000))00.100.100.200/latest/meta-data/ram/security-credentials//"
36+
+ "%%http:///\\ ```////~!@#$%^&*()_+|:<>?|MN";
3537
new URL(url);
3638
}
3739

@@ -77,8 +79,7 @@ public void getMetadataNormal() throws IOException, ClientException {
7779
String content = "content";
7880
when(response.getHttpContent()).thenReturn(content.getBytes());
7981
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
80-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
81-
.willReturn(response);
82+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willReturn(response);
8283
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
8384
fetcher.setRoleName("role");
8485
String res = fetcher.getMetadata();
@@ -89,8 +90,8 @@ public void getMetadataNormal() throws IOException, ClientException {
8990
public void getMetadataThrowClientException1() throws IOException, ClientException {
9091
thrown.expect(ClientException.class);
9192
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
92-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
93-
.willThrow(new ClientException("client exception"));
93+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willThrow(
94+
new ClientException("client exception"));
9495
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
9596
fetcher.setRoleName("role");
9697
String res = fetcher.getMetadata();
@@ -104,8 +105,7 @@ public void getMetadataThrowClientException2() throws IOException, ClientExcepti
104105
String content = "content";
105106
when(response.getHttpContent()).thenReturn(content.getBytes());
106107
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
107-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
108-
.willReturn(response);
108+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willReturn(response);
109109
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
110110
fetcher.setRoleName("role");
111111
String res = fetcher.getMetadata();
@@ -115,11 +115,11 @@ public void getMetadataThrowClientException2() throws IOException, ClientExcepti
115115
public void fetchNormal() throws IOException, ClientException {
116116
HttpResponse response = mock(HttpResponse.class);
117117
when(response.getStatus()).thenReturn(HttpURLConnection.HTTP_OK);
118-
String content = "{\"Code\":\"Success\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\",\"SecurityToken\":\"token\",\"Expiration\":\"2020-11-11 11:11:11\"}";
118+
String content = "{\"Code\":\"Success\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\","
119+
+ "\"SecurityToken\":\"token\",\"Expiration\":\"2020-11-11 11:11:11\"}";
119120
when(response.getHttpContent()).thenReturn(content.getBytes());
120121
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
121-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
122-
.willReturn(response);
122+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willReturn(response);
123123
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
124124
fetcher.setRoleName("role");
125125
InstanceProfileCredentials credentials = fetcher.fetch();
@@ -131,11 +131,11 @@ public void fetchThrowClientException1MissCode() throws IOException, ClientExcep
131131
thrown.expect(ClientException.class);
132132
HttpResponse response = mock(HttpResponse.class);
133133
when(response.getStatus()).thenReturn(HttpURLConnection.HTTP_OK);
134-
String content = "{\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\",\"SecurityToken\":\"token\",\"Expiration\":\"2020-11-11 11:11:11\"}";
134+
String content = "{\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\",\"SecurityToken\":\"token\","
135+
+ "\"Expiration\":\"2020-11-11 11:11:11\"}";
135136
when(response.getHttpContent()).thenReturn(content.getBytes());
136137
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
137-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
138-
.willReturn(response);
138+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willReturn(response);
139139
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
140140
fetcher.setRoleName("role");
141141
fetcher.fetch();
@@ -146,11 +146,11 @@ public void fetchThrowClientException1MissAK() throws IOException, ClientExcepti
146146
thrown.expect(ClientException.class);
147147
HttpResponse response = mock(HttpResponse.class);
148148
when(response.getStatus()).thenReturn(HttpURLConnection.HTTP_OK);
149-
String content = "{\"Code\":\"Success\",\"AccessKeySecret\":\"sk\",\"SecurityToken\":\"token\",\"Expiration\":\"2020-11-11 11:11:11\"}";
149+
String content = "{\"Code\":\"Success\",\"AccessKeySecret\":\"sk\",\"SecurityToken\":\"token\","
150+
+ "\"Expiration\":\"2020-11-11 11:11:11\"}";
150151
when(response.getHttpContent()).thenReturn(content.getBytes());
151152
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
152-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
153-
.willReturn(response);
153+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willReturn(response);
154154
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
155155
fetcher.setRoleName("role");
156156
fetcher.fetch();
@@ -161,11 +161,11 @@ public void fetchThrowClientException1MissSK() throws IOException, ClientExcepti
161161
thrown.expect(ClientException.class);
162162
HttpResponse response = mock(HttpResponse.class);
163163
when(response.getStatus()).thenReturn(HttpURLConnection.HTTP_OK);
164-
String content = "{\"Code\":\"Success\",\"AccessKeyId\":\"ak\",\"SecurityToken\":\"token\",\"Expiration\":\"2020-11-11 11:11:11\"}";
164+
String content = "{\"Code\":\"Success\",\"AccessKeyId\":\"ak\",\"SecurityToken\":\"token\","
165+
+ "\"Expiration\":\"2020-11-11 11:11:11\"}";
165166
when(response.getHttpContent()).thenReturn(content.getBytes());
166167
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
167-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
168-
.willReturn(response);
168+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willReturn(response);
169169
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
170170
fetcher.setRoleName("role");
171171
fetcher.fetch();
@@ -176,11 +176,11 @@ public void fetchThrowClientException1MissToken() throws IOException, ClientExce
176176
thrown.expect(ClientException.class);
177177
HttpResponse response = mock(HttpResponse.class);
178178
when(response.getStatus()).thenReturn(HttpURLConnection.HTTP_OK);
179-
String content = "{\"Code\":\"Success\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\",\"Expiration\":\"2020-11-11 11:11:11\"}";
179+
String content = "{\"Code\":\"Success\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\","
180+
+ "\"Expiration\":\"2020-11-11 11:11:11\"}";
180181
when(response.getHttpContent()).thenReturn(content.getBytes());
181182
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
182-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
183-
.willReturn(response);
183+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willReturn(response);
184184
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
185185
fetcher.setRoleName("role");
186186
fetcher.fetch();
@@ -191,11 +191,11 @@ public void fetchThrowClientException1MissExpiration() throws IOException, Clien
191191
thrown.expect(ClientException.class);
192192
HttpResponse response = mock(HttpResponse.class);
193193
when(response.getStatus()).thenReturn(HttpURLConnection.HTTP_OK);
194-
String content = "{\"Code\":\"Success\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\",\"SecurityToken\":\"token\"}";
194+
String content = "{\"Code\":\"Success\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\","
195+
+ "\"SecurityToken\":\"token\"}";
195196
when(response.getHttpContent()).thenReturn(content.getBytes());
196197
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
197-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
198-
.willReturn(response);
198+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willReturn(response);
199199
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
200200
fetcher.setRoleName("role");
201201
fetcher.fetch();
@@ -206,11 +206,11 @@ public void fetchThrowClientException2() throws IOException, ClientException {
206206
thrown.expect(ClientException.class);
207207
HttpResponse response = mock(HttpResponse.class);
208208
when(response.getStatus()).thenReturn(HttpURLConnection.HTTP_OK);
209-
String content = "{\"Code\":\"Failed\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\",\"SecurityToken\":\"token\",\"Expiration\":\"2020-11-11 11:11:11\"}";
209+
String content = "{\"Code\":\"Failed\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\","
210+
+ "\"SecurityToken\":\"token\",\"Expiration\":\"2020-11-11 11:11:11\"}";
210211
when(response.getHttpContent()).thenReturn(content.getBytes());
211212
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
212-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
213-
.willReturn(response);
213+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willReturn(response);
214214
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
215215
fetcher.setRoleName("role");
216216
fetcher.fetch();
@@ -220,11 +220,11 @@ public void fetchThrowClientException2() throws IOException, ClientException {
220220
public void fetch3TimesNormal() throws IOException, ClientException {
221221
HttpResponse response = mock(HttpResponse.class);
222222
when(response.getStatus()).thenReturn(HttpURLConnection.HTTP_OK);
223-
String content = "{\"Code\":\"Success\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\",\"SecurityToken\":\"token\",\"Expiration\":\"2020-11-11 11:11:11\"}";
223+
String content = "{\"Code\":\"Success\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\","
224+
+ "\"SecurityToken\":\"token\",\"Expiration\":\"2020-11-11 11:11:11\"}";
224225
when(response.getHttpContent()).thenReturn(content.getBytes());
225226
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
226-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
227-
.willReturn(response);
227+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willReturn(response);
228228
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
229229
fetcher.setRoleName("role");
230230
InstanceProfileCredentials credentials = fetcher.fetch(3);
@@ -236,11 +236,11 @@ public void fetch3TimesThrowClientException() throws IOException, ClientExceptio
236236
thrown.expect(ClientException.class);
237237
HttpResponse response = mock(HttpResponse.class);
238238
when(response.getStatus()).thenReturn(HttpURLConnection.HTTP_OK);
239-
String content = "{\"Code\":\"Failed\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\",\"SecurityToken\":\"token\",\"Expiration\":\"2020-11-11 11:11:11\"}";
239+
String content = "{\"Code\":\"Failed\",\"AccessKeyId\":\"ak\",\"AccessKeySecret\":\"sk\","
240+
+ "\"SecurityToken\":\"token\",\"Expiration\":\"2020-11-11 11:11:11\"}";
240241
when(response.getHttpContent()).thenReturn(content.getBytes());
241242
PowerMockito.mockStatic(CompatibleUrlConnClient.class);
242-
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class)))
243-
.willReturn(response);
243+
BDDMockito.given(CompatibleUrlConnClient.compatibleGetResponse(any(HttpRequest.class))).willReturn(response);
244244
ECSMetadataServiceCredentialsFetcher fetcher = new ECSMetadataServiceCredentialsFetcher();
245245
fetcher.setRoleName("role");
246246
fetcher.fetch(3);

aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/RoaSignatureComposerTest.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package com.aliyuncs.auth;
22

3-
import com.aliyuncs.http.FormatType;
4-
import com.aliyuncs.http.MethodType;
5-
import org.apache.commons.logging.Log;
6-
import org.apache.commons.logging.LogFactory;
3+
import static org.mockito.Mockito.mock;
4+
import static org.mockito.Mockito.when;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
79
import org.junit.Assert;
810
import org.junit.Test;
911
import org.junit.runner.RunWith;
@@ -12,16 +14,12 @@
1214
import org.powermock.core.classloader.annotations.PrepareForTest;
1315
import org.powermock.modules.junit4.PowerMockRunner;
1416

15-
import java.util.HashMap;
16-
import java.util.Map;
17-
18-
import static org.mockito.Mockito.mock;
19-
import static org.mockito.Mockito.when;
17+
import com.aliyuncs.http.FormatType;
18+
import com.aliyuncs.http.MethodType;
2019

2120
@RunWith(PowerMockRunner.class)
2221
@PrepareForTest(FormatType.class)
2322
public class RoaSignatureComposerTest {
24-
private static final Log log = LogFactory.getLog(RpcSignatureComposerTest.class);
2523

2624
@Test
2725
public void constructorTest() {

aliyun-java-sdk-core/src/test/java/com/aliyuncs/auth/RpcSignatureComposerTest.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
package com.aliyuncs.auth;
22

3-
import com.aliyuncs.http.FormatType;
4-
import com.aliyuncs.http.MethodType;
5-
import org.apache.commons.logging.Log;
6-
import org.apache.commons.logging.LogFactory;
7-
import org.junit.Assert;
8-
import org.junit.Test;
3+
import static org.mockito.Mockito.mock;
4+
import static org.mockito.Mockito.when;
95

106
import java.util.HashMap;
117
import java.util.Map;
128

13-
import static org.mockito.Mockito.mock;
14-
import static org.mockito.Mockito.when;
9+
import org.junit.Assert;
10+
import org.junit.Test;
11+
12+
import com.aliyuncs.http.FormatType;
13+
import com.aliyuncs.http.MethodType;
1514

1615
public class RpcSignatureComposerTest {
1716

0 commit comments

Comments
 (0)