Skip to content

Commit ac0eafe

Browse files
committed
fixed test
1 parent 5fb16fc commit ac0eafe

File tree

5 files changed

+79
-173
lines changed

5 files changed

+79
-173
lines changed

library/src/androidTest/java/com/qiniu/android/CancelTest.java

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class CancelTest extends InstrumentationTestCase {
3333
private volatile boolean failed;
3434
private volatile UploadManager uploadManager;
3535
private volatile String key;
36-
private volatile ResponseInfo info;
36+
private volatile ResponseInfo info = null;
3737
private volatile JSONObject resp;
3838
private volatile UploadOptions options;
3939

@@ -133,22 +133,13 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
133133

134134
try {
135135
signal.await(570, TimeUnit.SECONDS); // wait for callback
136+
Assert.assertNotNull("timeout", info);
136137
} catch (InterruptedException e) {
137138
e.printStackTrace();
138139
}
139-
// 尝试获取info信息。
140-
// key == null : 没进入 complete ? 什么导致的?
141-
if (!expectKey.equals(key)) {
142-
//此处通不过, travis 会打印信息
143-
Assert.assertEquals("", info);
144-
}
145-
if (info == null || !info.isCancelled()) {
146-
//此处通不过, travis 会打印信息
147-
Assert.assertEquals("", info);
148-
}
149-
Assert.assertEquals(expectKey, key);
150-
Assert.assertFalse(info.isOK());
151-
Assert.assertTrue(info.isCancelled());
140+
141+
Assert.assertEquals(info.toString(), expectKey, key);
142+
Assert.assertTrue(info.toString(), info.isCancelled());
152143
Assert.assertNull(resp);
153144

154145
TempFile.remove(tempFile);
@@ -206,22 +197,13 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
206197

207198
try {
208199
signal.await(570, TimeUnit.SECONDS); // wait for callback
200+
Assert.assertNotNull("timeout", info);
209201
} catch (InterruptedException e) {
210202
e.printStackTrace();
211203
}
212-
// 尝试获取info信息。
213-
// key == null : 没进入 complete ? 什么导致的?
214-
if (!expectKey.equals(key)) {
215-
//此处通不过, travis 会打印信息
216-
Assert.assertEquals("", info);
217-
}
218-
if (info == null || !info.isCancelled()) {
219-
//此处通不过, travis 会打印信息
220-
Assert.assertEquals("", info);
221-
}
222-
Assert.assertEquals(expectKey, key);
223-
Assert.assertFalse(info.isOK());
224-
Assert.assertTrue(info.isCancelled());
204+
205+
Assert.assertEquals(info.toString(), expectKey, key);
206+
Assert.assertTrue(info.toString(), info.isCancelled());
225207
Assert.assertNull(resp);
226208
}
227209

library/src/androidTest/java/com/qiniu/android/FormUploadTest.java

Lines changed: 37 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,12 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
5353

5454
try {
5555
signal.await(120, TimeUnit.SECONDS); // wait for callback
56+
Assert.assertNotNull("timeout", info);
5657
} catch (InterruptedException e) {
5758
e.printStackTrace();
5859
}
59-
// 尝试获取info信息。
60-
// key == null : 没进入 complete ? 什么导致的?
61-
if (!expectKey.equals(key)) {
62-
//此处通不过, travis 会打印信息
63-
Assert.assertEquals("", info);
64-
}
65-
if (info == null || !info.isOK()) {
66-
//此处通不过, travis 会打印信息
67-
Assert.assertEquals("", info);
68-
}
69-
Assert.assertEquals(expectKey, key);
70-
Assert.assertTrue(info.isOK());
60+
Assert.assertEquals(info.toString(), expectKey, key);
61+
Assert.assertTrue(info.toString(), info.isOK());
7162
Assert.assertNotNull(info.reqId);
7263
Assert.assertNotNull(resp);
7364
Assert.assertEquals("/", info.path);
@@ -95,17 +86,14 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
9586

9687
try {
9788
signal.await(120, TimeUnit.SECONDS); // wait for callback
89+
Assert.assertNotNull("timeout", info);
9890
} catch (InterruptedException e) {
9991
e.printStackTrace();
10092
}
10193

102-
// 尝试获取info信息。
103-
if (info == null || !info.isOK()) {
104-
//此处通不过, travis 会打印信息
105-
Assert.assertEquals("", info);
106-
}
107-
Assert.assertEquals(expectKey, key);
108-
Assert.assertTrue(info.isOK());
94+
Assert.assertEquals(info.toString(), expectKey, key);
95+
Assert.assertTrue(info.toString(), info.isOK());
96+
10997
Assert.assertNotNull(info.reqId);
11098
Assert.assertEquals("/", info.path);
11199
Assert.assertNotNull(resp);
@@ -131,11 +119,12 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
131119

132120
try {
133121
signal.await(120, TimeUnit.SECONDS); // wait for callback
122+
Assert.assertNotNull("timeout", info);
134123
} catch (InterruptedException e) {
135124
e.printStackTrace();
136125
}
137-
Assert.assertEquals(expectKey, key);
138-
Assert.assertEquals(ResponseInfo.InvalidToken, info.statusCode);
126+
Assert.assertEquals(info.toString(), expectKey, key);
127+
Assert.assertEquals(info.toString(), ResponseInfo.InvalidToken, info.statusCode);
139128
Assert.assertNotNull(info.reqId);
140129
Assert.assertNull(resp);
141130
}
@@ -157,11 +146,13 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
157146

158147
try {
159148
signal.await(120, TimeUnit.SECONDS); // wait for callback
149+
assertNotNull("timeout", info);
160150
} catch (InterruptedException e) {
161151
e.printStackTrace();
162152
}
163-
Assert.assertEquals(expectKey, key);
164-
Assert.assertEquals(ResponseInfo.InvalidArgument, info.statusCode);
153+
Assert.assertEquals(info.toString(), expectKey, key);
154+
Assert.assertEquals(info.toString(), ResponseInfo.InvalidArgument,
155+
info.statusCode);
165156
Assert.assertNull(resp);
166157
}
167158

@@ -184,11 +175,12 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
184175

185176
try {
186177
signal.await(120, TimeUnit.SECONDS); // wait for callback
178+
Assert.assertNotNull("timeout", info);
187179
} catch (InterruptedException e) {
188180
e.printStackTrace();
189181
}
190-
Assert.assertEquals(expectKey, key);
191-
Assert.assertEquals(ResponseInfo.InvalidArgument, info.statusCode);
182+
Assert.assertEquals(info.toString(), expectKey, key);
183+
Assert.assertEquals(info.toString(), ResponseInfo.InvalidArgument, info.statusCode);
192184
Assert.assertNull(resp);
193185
}
194186

@@ -211,11 +203,13 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
211203

212204
try {
213205
signal.await(120, TimeUnit.SECONDS); // wait for callback
206+
Assert.assertNotNull("timeout", info);
214207
} catch (InterruptedException e) {
215208
e.printStackTrace();
216209
}
217-
Assert.assertEquals(expectKey, key);
218-
Assert.assertEquals(ResponseInfo.InvalidArgument, info.statusCode);
210+
Assert.assertEquals(info.toString(), expectKey, key);
211+
Assert.assertEquals(info.toString(), ResponseInfo.InvalidArgument,
212+
info.statusCode);
219213
Assert.assertNull(resp);
220214
}
221215

@@ -238,21 +232,13 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
238232

239233
try {
240234
signal.await(130, TimeUnit.SECONDS); // wait for callback
235+
Assert.assertNotNull("timeout", info);
241236
} catch (InterruptedException e) {
242237
e.printStackTrace();
243238
}
244-
// 尝试获取info信息。
245-
// key == null : 没进入 complete ? 什么导致的?
246-
if (!expectKey.equals(key)) {
247-
//此处通不过, travis 会打印信息
248-
Assert.assertEquals("", info);
249-
}
250-
if (info == null || !info.isOK()) {
251-
//此处通不过, travis 会打印信息
252-
Assert.assertEquals("", info);
253-
}
254-
Assert.assertEquals(expectKey, key);
255-
Assert.assertTrue(info.isOK());
239+
240+
Assert.assertEquals(info.toString(), expectKey, key);
241+
Assert.assertTrue(info.toString(), info.isOK());
256242
Assert.assertNotNull(info.reqId);
257243
Assert.assertNotNull(resp);
258244
TempFile.remove(f);
@@ -306,21 +292,13 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
306292

307293
try {
308294
signal.await(120, TimeUnit.SECONDS); // wait for callback
295+
Assert.assertNotNull("timeout", info);
309296
} catch (InterruptedException e) {
310297
e.printStackTrace();
311298
}
312-
// 尝试获取info信息。
313-
// key == null : 没进入 complete ? 什么导致的?
314-
if (!expectKey.equals(key)) {
315-
//此处通不过, travis 会打印信息
316-
Assert.assertEquals("", info);
317-
}
318-
if (info == null || !info.isOK()) {
319-
//此处通不过, travis 会打印信息
320-
Assert.assertEquals("", info);
321-
}
322-
Assert.assertEquals(expectKey, key);
323-
Assert.assertTrue(info.isOK());
299+
300+
Assert.assertEquals(info.toString(), expectKey, key);
301+
Assert.assertTrue(info.toString(), info.isOK());
324302
Assert.assertNotNull(info.reqId);
325303
Assert.assertNotNull(resp);
326304
}
@@ -350,21 +328,13 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
350328

351329
try {
352330
signal.await(120, TimeUnit.SECONDS); // wait for callback
331+
Assert.assertNotNull("timeout", info);
353332
} catch (InterruptedException e) {
354333
e.printStackTrace();
355334
}
356-
// 尝试获取info信息。
357-
// key == null : 没进入 complete ? 什么导致的?
358-
if (!expectKey.equals(key)) {
359-
//此处通不过, travis 会打印信息
360-
Assert.assertEquals("", info);
361-
}
362-
if (info == null || !info.isOK()) {
363-
//此处通不过, travis 会打印信息
364-
Assert.assertEquals("", info);
365-
}
366-
Assert.assertEquals(expectKey, key);
367-
Assert.assertTrue(info.isOK());
335+
336+
Assert.assertEquals(info.toString(), expectKey, key);
337+
Assert.assertTrue(info.toString(), info.isOK());
368338
Assert.assertNotNull(info.reqId);
369339
Assert.assertNotNull(resp);
370340
}
@@ -393,21 +363,13 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
393363

394364
try {
395365
signal.await(120, TimeUnit.SECONDS); // wait for callback
366+
Assert.assertNotNull("timeout", info);
396367
} catch (InterruptedException e) {
397368
e.printStackTrace();
398369
}
399-
// 尝试获取info信息。
400-
// key == null : 没进入 complete ? 什么导致的?
401-
if (!expectKey.equals(key)) {
402-
//此处通不过, travis 会打印信息
403-
Assert.assertEquals("", info);
404-
}
405-
if (info == null || !info.isOK()) {
406-
//此处通不过, travis 会打印信息
407-
Assert.assertEquals("", info);
408-
}
409-
Assert.assertEquals(expectKey, key);
410-
Assert.assertTrue(info.isOK());
370+
371+
Assert.assertEquals(info.toString(), expectKey, key);
372+
Assert.assertTrue(info.toString(), info.isOK());
411373
Assert.assertNotNull(info.reqId);
412374
Assert.assertNotNull(resp);
413375
}

library/src/androidTest/java/com/qiniu/android/PortTest.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -95,21 +95,13 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
9595
private void check(final String expectKey) {
9696
try {
9797
signal.await(120, TimeUnit.SECONDS); // wait for callback
98+
Assert.assertNotNull("timeout", info);
9899
} catch (InterruptedException e) {
99100
e.printStackTrace();
100101
}
101-
// 尝试获取info信息。
102-
// key == null : 没进入 complete ? 什么导致的?
103-
if (!expectKey.equals(key)) {
104-
//此处通不过, travis 会打印信息
105-
Assert.assertEquals("", info);
106-
}
107-
if (info == null || !info.isOK()) {
108-
//此处通不过, travis 会打印信息
109-
Assert.assertEquals("", info);
110-
}
111-
Assert.assertEquals(expectKey, key);
112-
Assert.assertTrue(info.isOK());
102+
103+
Assert.assertEquals(info.toString(), expectKey, key);
104+
Assert.assertTrue(info.toString(), info.isOK());
113105
Assert.assertNotNull(info.reqId);
114106
Assert.assertNotNull(resp);
115107
}

library/src/androidTest/java/com/qiniu/android/ResumeUploadTest.java

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ public class ResumeUploadTest extends InstrumentationTestCase {
2424
final CountDownLatch signal = new CountDownLatch(1);
2525
private UploadManager uploadManager;
2626
private volatile String key;
27-
private volatile ResponseInfo info;
27+
private volatile ResponseInfo info = null;
2828
private volatile JSONObject resp;
2929

3030
public void setUp() throws Exception {
31-
Configuration config = new Configuration.Builder().upPort(9999).build();
31+
Configuration config = new Configuration.Builder().upPort(8888).build();
3232
uploadManager = new UploadManager(config);
3333
}
3434

@@ -50,22 +50,16 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
5050
});
5151

5252
try {
53-
signal.await(500, TimeUnit.SECONDS); // wait for callback
53+
signal.await(600, TimeUnit.SECONDS); // wait for callback
54+
Assert.assertNotNull("timeout", info);
5455
} catch (InterruptedException e) {
5556
e.printStackTrace();
5657
}
57-
// 尝试获取info信息。
58-
// key == null : 没进入 complete ? 什么导致的?
59-
if (!expectKey.equals(key)) {
60-
//此处通不过, travis 会打印信息
61-
Assert.assertEquals("", info);
62-
}
63-
if (info == null || !info.isOK()) {
64-
//此处通不过, travis 会打印信息
65-
Assert.assertEquals("", info);
66-
}
67-
Assert.assertEquals(expectKey, key);
68-
Assert.assertTrue(info.isOK());
58+
59+
Assert.assertEquals(info.toString(), expectKey, key);
60+
61+
Assert.assertTrue(info.toString(), info.isOK());
62+
6963
Assert.assertNotNull(info.reqId);
7064
Assert.assertNotNull(resp);
7165
TempFile.remove(f);
@@ -87,19 +81,15 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
8781

8882
try {
8983
signal.await(500, TimeUnit.SECONDS); // wait for callback
84+
Assert.assertNotNull("timeout", info);
9085
} catch (InterruptedException e) {
9186
e.printStackTrace();
9287
}
93-
// 尝试获取info信息。
94-
// key == null : 没进入 complete ? 什么导致的?
95-
if (!expectKey.equals(key)) {
96-
//此处通不过, travis 会打印信息
97-
Assert.assertEquals("", info);
98-
}
99-
if (info == null || !info.isOK()) {
100-
//此处通不过, travis 会打印信息
101-
Assert.assertEquals("", info);
102-
}
88+
89+
Assert.assertEquals(info.toString(), expectKey, key);
90+
91+
Assert.assertTrue(info.toString(), info.isOK());
92+
10393
Assert.assertEquals(expectKey, key);
10494
Assert.assertTrue(info.isOK());
10595
Assert.assertNotNull(info.reqId);
@@ -129,19 +119,15 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
129119

130120
try {
131121
signal.await(500, TimeUnit.SECONDS); // wait for callback
122+
Assert.assertNotNull("timeout", info);
132123
} catch (InterruptedException e) {
133124
e.printStackTrace();
134125
}
135-
// 尝试获取info信息。
136-
// key == null : 没进入 complete ? 什么导致的?
137-
if (!expectKey.equals(key)) {
138-
//此处通不过, travis 会打印信息
139-
Assert.assertEquals("", info);
140-
}
141-
if (info == null || !info.isOK()) {
142-
//此处通不过, travis 会打印信息
143-
Assert.assertEquals("", info);
144-
}
126+
127+
Assert.assertEquals(info.toString(), expectKey, key);
128+
129+
Assert.assertTrue(info.toString(), info.isOK());
130+
145131
Assert.assertEquals(expectKey, key);
146132
Assert.assertTrue(info.isOK());
147133
Assert.assertNotNull(info.reqId);

0 commit comments

Comments
 (0)