Skip to content

Commit 61d7d22

Browse files
authored
smaller tests, better code format (#4355)
1 parent f352fa6 commit 61d7d22

File tree

2 files changed

+40
-18
lines changed
  • CI/samples.ci/client/petstore/java/test-manual/okhttp-gson/api
  • samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api

2 files changed

+40
-18
lines changed

CI/samples.ci/client/petstore/java/test-manual/okhttp-gson/api/PetApiTest.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ public void onDownloadProgress(long bytesRead, long contentLength, boolean done)
146146
}
147147
} while (result.isEmpty());
148148
assertPetMatches(pet, fetched);
149+
}
150+
151+
@Test
152+
public void testCreateAndGetPetAsyncInvalidID() throws Exception {
153+
Pet pet = createPet();
154+
api.addPet(pet);
155+
// to store returned Pet or error message/exception
156+
final Map<String, Object> result = new HashMap<String, Object>();
149157

150158
// test getting a nonexistent pet
151159
result.clear();
@@ -172,8 +180,11 @@ public void onDownloadProgress(long bytesRead, long contentLength, boolean done)
172180
});
173181

174182
// wait for the asynchronous call to finish (at most 10 seconds)
175-
tryCount = 1;
183+
final int maxTry = 10;
184+
int tryCount = 1;
185+
Pet fetched = null;
176186
ApiException exception = null;
187+
177188
do {
178189
if (tryCount > maxTry) fail("have not got result of getPetByIdAsync after 10 seconds");
179190
Thread.sleep(1000);
@@ -414,16 +425,16 @@ private void assertPetMatches(Pet expected, Pet actual) {
414425
assertEquals(expected.getId(), actual.getId());
415426
assertNotNull(actual.getCategory());
416427
assertEquals(expected.getCategory().getName(),
417-
actual.getCategory().getName());
428+
actual.getCategory().getName());
418429
}
419430

420431
/**
421432
* Assert that the given upload/download progress list satisfies the
422433
* following constraints:
423-
*
424-
* - List is not empty
425-
* - Byte count should be nondecreasing
426-
* - The last element, and only the last element, should have done=true
434+
* <p>
435+
* - List is not empty
436+
* - Byte count should be nondecreasing
437+
* - The last element, and only the last element, should have done=true
427438
*/
428439
private void assertValidProgress(List<Progress> progressList) {
429440
assertFalse(progressList.isEmpty());
@@ -434,7 +445,7 @@ private void assertValidProgress(List<Progress> progressList) {
434445
if (prev != null) {
435446
if (prev.done || prev.bytes > progress.bytes) {
436447
fail("Progress list out of order at index " + index
437-
+ ": " + progressList);
448+
+ ": " + progressList);
438449
}
439450
}
440451
prev = progress;
@@ -450,9 +461,9 @@ private static class TestApiCallback<T> implements ApiCallback<T> {
450461

451462
private final CountDownLatch latch;
452463
private final ConcurrentLinkedQueue<Progress> uploadProgress =
453-
new ConcurrentLinkedQueue<Progress>();
464+
new ConcurrentLinkedQueue<Progress>();
454465
private final ConcurrentLinkedQueue<Progress> downloadProgress =
455-
new ConcurrentLinkedQueue<Progress>();
466+
new ConcurrentLinkedQueue<Progress>();
456467

457468
private boolean done;
458469
private boolean success;

samples/client/petstore/java/okhttp-gson/src/test/java/org/openapitools/client/api/PetApiTest.java

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,14 @@ public void onDownloadProgress(long bytesRead, long contentLength, boolean done)
146146
}
147147
} while (result.isEmpty());
148148
assertPetMatches(pet, fetched);
149+
}
150+
151+
@Test
152+
public void testCreateAndGetPetAsyncInvalidID() throws Exception {
153+
Pet pet = createPet();
154+
api.addPet(pet);
155+
// to store returned Pet or error message/exception
156+
final Map<String, Object> result = new HashMap<String, Object>();
149157

150158
// test getting a nonexistent pet
151159
result.clear();
@@ -172,8 +180,11 @@ public void onDownloadProgress(long bytesRead, long contentLength, boolean done)
172180
});
173181

174182
// wait for the asynchronous call to finish (at most 10 seconds)
175-
tryCount = 1;
183+
final int maxTry = 10;
184+
int tryCount = 1;
185+
Pet fetched = null;
176186
ApiException exception = null;
187+
177188
do {
178189
if (tryCount > maxTry) fail("have not got result of getPetByIdAsync after 10 seconds");
179190
Thread.sleep(1000);
@@ -414,16 +425,16 @@ private void assertPetMatches(Pet expected, Pet actual) {
414425
assertEquals(expected.getId(), actual.getId());
415426
assertNotNull(actual.getCategory());
416427
assertEquals(expected.getCategory().getName(),
417-
actual.getCategory().getName());
428+
actual.getCategory().getName());
418429
}
419430

420431
/**
421432
* Assert that the given upload/download progress list satisfies the
422433
* following constraints:
423-
*
424-
* - List is not empty
425-
* - Byte count should be nondecreasing
426-
* - The last element, and only the last element, should have done=true
434+
* <p>
435+
* - List is not empty
436+
* - Byte count should be nondecreasing
437+
* - The last element, and only the last element, should have done=true
427438
*/
428439
private void assertValidProgress(List<Progress> progressList) {
429440
assertFalse(progressList.isEmpty());
@@ -434,7 +445,7 @@ private void assertValidProgress(List<Progress> progressList) {
434445
if (prev != null) {
435446
if (prev.done || prev.bytes > progress.bytes) {
436447
fail("Progress list out of order at index " + index
437-
+ ": " + progressList);
448+
+ ": " + progressList);
438449
}
439450
}
440451
prev = progress;
@@ -450,9 +461,9 @@ private static class TestApiCallback<T> implements ApiCallback<T> {
450461

451462
private final CountDownLatch latch;
452463
private final ConcurrentLinkedQueue<Progress> uploadProgress =
453-
new ConcurrentLinkedQueue<Progress>();
464+
new ConcurrentLinkedQueue<Progress>();
454465
private final ConcurrentLinkedQueue<Progress> downloadProgress =
455-
new ConcurrentLinkedQueue<Progress>();
466+
new ConcurrentLinkedQueue<Progress>();
456467

457468
private boolean done;
458469
private boolean success;

0 commit comments

Comments
 (0)