diff --git a/java-vision/google-cloud-vision/src/test/java/com/google/cloud/vision/it/ITSystemTest.java b/java-vision/google-cloud-vision/src/test/java/com/google/cloud/vision/it/ITSystemTest.java index ce6ca73c26d7..890579508ac5 100644 --- a/java-vision/google-cloud-vision/src/test/java/com/google/cloud/vision/it/ITSystemTest.java +++ b/java-vision/google-cloud-vision/src/test/java/com/google/cloud/vision/it/ITSystemTest.java @@ -75,9 +75,9 @@ import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collection; import java.util.List; import java.util.UUID; -import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; import org.junit.AfterClass; import org.junit.Assert; @@ -90,12 +90,9 @@ public class ITSystemTest { private static ProductSearchClient productSearchClient; private static Product product; private static String formatProductName; - private static String productName; private static ProductSet productSet; - private static String productSetName; private static String formatProductSetName; private static ReferenceImage referenceImage; - private static String referenceImageName; private static String formatReferenceImageName; private static final String PROJECT_ID = ServiceOptions.getDefaultProjectId(); private static final String ID = UUID.randomUUID().toString().substring(0, 8); @@ -121,6 +118,7 @@ public class ITSystemTest { SAMPLE_URI = String.format("https://storage-download.googleapis.com/%s/vision/", GCS_BUCKET); } + private static final int RETRIES = 3; private static final String COMPUTE_REGION = "us-west1"; private static final String LOCATION_NAME = LocationName.of(PROJECT_ID, COMPUTE_REGION).toString(); @@ -153,7 +151,7 @@ public static void setUp() throws IOException { .setProduct(createProduct) .build(); product = productSearchClient.createProduct(productRequest); - productName = getName(product.getName()); + String productName = getName(product.getName()); formatProductName = ProductName.of(PROJECT_ID, COMPUTE_REGION, productName).toString(); /* create product set */ @@ -166,7 +164,7 @@ public static void setUp() throws IOException { .setProductSetId(PRODUCT_SET_ID) .build(); productSet = productSearchClient.createProductSet(productSetRequest); - productSetName = getName(productSet.getName()); + String productSetName = getName(productSet.getName()); formatProductSetName = ProductSetName.of(PROJECT_ID, COMPUTE_REGION, productSetName).toString(); /* add product to product set */ @@ -186,7 +184,7 @@ public static void setUp() throws IOException { .setReferenceImage(createReferenceImage) .build(); referenceImage = productSearchClient.createReferenceImage(imageRequest); - referenceImageName = getName(referenceImage.getName()); + String referenceImageName = getName(referenceImage.getName()); formatReferenceImageName = ReferenceImageName.of(PROJECT_ID, COMPUTE_REGION, productName, referenceImageName) .toString(); @@ -222,8 +220,8 @@ public static void tearDown() { imageAnnotatorClient.close(); } - private static List getResponsesList( - String image, Type type, boolean isGcs) throws IOException { + private static AnnotateImageResponse requestAnnotatedImage(String image, Type type, boolean isGcs) + throws IOException { ImageSource imgSource; Image img; if (isGcs) { @@ -234,74 +232,111 @@ private static List getResponsesList( img = Image.newBuilder().setContent(imgBytes).build(); } Feature feat = Feature.newBuilder().setType(type).build(); - AnnotateImageRequest request = - AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); - BatchAnnotateImagesResponse response = + + return request(AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build()); + } + + private static AnnotateImageResponse request(AnnotateImageRequest request) { + return request(request, RETRIES); + } + + private static AnnotateImageResponse request(AnnotateImageRequest request, int retries) { + try { + return executeRequest(request); + + } catch (StatusRuntimeException ex) { + if (retries <= 0) { + throw ex; + } + System.out.println("Retrying in 30s: " + ex.getMessage()); + try { + TimeUnit.SECONDS.sleep(30); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + return request(request, retries - 1); + } + + private static AnnotateImageResponse executeRequest(AnnotateImageRequest request) { + BatchAnnotateImagesResponse batchResponse = imageAnnotatorClient.batchAnnotateImages(ImmutableList.of(request)); - return response.getResponsesList(); + + List responses = batchResponse.getResponsesList(); + if (responses.isEmpty()) { + System.out.println("Request: " + request); + System.out.println("Response: " + batchResponse); + Assert.fail("Empty response."); + } + + AnnotateImageResponse response = assertSingleEntry(responses); + int errorCode = response.getError().getCode(); + if (errorCode != 0) { + throw new StatusRuntimeException(Status.fromCodeValue(errorCode)); + } + return response; + } + + private static T assertSingleEntry(Collection collection) { + assertEquals(1, collection.size()); + return collection.iterator().next(); + } + + private static List assertNotEmpty(AnnotateImageResponse response, List list) { + Assert.assertFalse("Empty response list: " + response, list.isEmpty()); + return list; } @Test public void detectFacesTest() throws IOException { - List responses = - getResponsesList("face_no_surprise.jpg", Type.FACE_DETECTION, false); - for (AnnotateImageResponse res : responses) { - for (FaceAnnotation annotation : res.getFaceAnnotationsList()) { - assertEquals(Likelihood.LIKELY, annotation.getAngerLikelihood()); - assertEquals(Likelihood.VERY_UNLIKELY, annotation.getJoyLikelihood()); - assertEquals(Likelihood.LIKELY, annotation.getSurpriseLikelihood()); - } + AnnotateImageResponse res = + requestAnnotatedImage("face_no_surprise.jpg", Type.FACE_DETECTION, false); + for (FaceAnnotation annotation : assertNotEmpty(res, res.getFaceAnnotationsList())) { + assertEquals(Likelihood.LIKELY, annotation.getAngerLikelihood()); + assertEquals(Likelihood.VERY_UNLIKELY, annotation.getJoyLikelihood()); + assertEquals(Likelihood.LIKELY, annotation.getSurpriseLikelihood()); } } @Test public void detectFacesGcsTest() throws IOException { - List responses = - getResponsesList("face/face_no_surprise.jpg", Type.FACE_DETECTION, true); - for (AnnotateImageResponse res : responses) { - for (FaceAnnotation annotation : res.getFaceAnnotationsList()) { - assertEquals(Likelihood.LIKELY, annotation.getAngerLikelihood()); - assertEquals(Likelihood.VERY_UNLIKELY, annotation.getJoyLikelihood()); - assertEquals(Likelihood.LIKELY, annotation.getSurpriseLikelihood()); - } + AnnotateImageResponse res = + requestAnnotatedImage("face/face_no_surprise.jpg", Type.FACE_DETECTION, true); + for (FaceAnnotation annotation : assertNotEmpty(res, res.getFaceAnnotationsList())) { + assertEquals(Likelihood.LIKELY, annotation.getAngerLikelihood()); + assertEquals(Likelihood.VERY_UNLIKELY, annotation.getJoyLikelihood()); + assertEquals(Likelihood.LIKELY, annotation.getSurpriseLikelihood()); } } @Test public void detectLabelsTest() throws IOException { - List responses = - getResponsesList("wakeupcat.jpg", Type.LABEL_DETECTION, false); + AnnotateImageResponse res = requestAnnotatedImage("wakeupcat.jpg", Type.LABEL_DETECTION, false); List actual = new ArrayList<>(); - for (AnnotateImageResponse res : responses) { - for (EntityAnnotation annotation : res.getLabelAnnotationsList()) { - actual.add(annotation.getDescription()); - } + for (EntityAnnotation annotation : assertNotEmpty(res, res.getLabelAnnotationsList())) { + actual.add(annotation.getDescription()); } assertThat(actual).contains("Whiskers"); } @Test public void detectLabelsGcsTest() throws IOException { - List responses = - getResponsesList("label/wakeupcat.jpg", Type.LABEL_DETECTION, true); + AnnotateImageResponse res = + requestAnnotatedImage("label/wakeupcat.jpg", Type.LABEL_DETECTION, true); List actual = new ArrayList<>(); - for (AnnotateImageResponse res : responses) { - for (EntityAnnotation annotation : res.getLabelAnnotationsList()) { - actual.add(annotation.getDescription()); - } + for (EntityAnnotation annotation : assertNotEmpty(res, res.getLabelAnnotationsList())) { + actual.add(annotation.getDescription()); } assertThat(actual).contains("Whiskers"); } @Test public void detectLandmarksTest() throws IOException { - List responses = - getResponsesList("landmark.jpg", Type.LANDMARK_DETECTION, false); + AnnotateImageResponse res = + requestAnnotatedImage("landmark.jpg", Type.LANDMARK_DETECTION, false); List actual = new ArrayList<>(); - for (AnnotateImageResponse res : responses) { - for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) { - actual.add(annotation.getDescription()); - } + for (EntityAnnotation annotation : assertNotEmpty(res, res.getLandmarkAnnotationsList())) { + actual.add(annotation.getDescription()); } assertThat(actual).contains("Palace of Fine Arts"); } @@ -315,109 +350,58 @@ public void detectLandmarksUrlTest() throws Exception { AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); - int maxTries = 3; - List actual = - retryIfEmptyOrStatusRuntimeException(() -> addResponsesToList(request), maxTries); - assertThat(actual).contains("Palace of Fine Arts"); - } - - private static List retryIfEmptyOrStatusRuntimeException( - Callable> callable, int retries) throws Exception { - Assert.assertTrue("No more retries available.", retries >= 0); - - try { - List result = callable.call(); - if (result.isEmpty()) { - System.out.println("Retrying due to empty response list... "); - TimeUnit.SECONDS.sleep(30); - return retryIfEmptyOrStatusRuntimeException(callable, retries - 1); - } - return result; - - } catch (StatusRuntimeException ex) { - if (retries == 0) { - throw ex; - } - System.out.println("Retrying due to request throttling or DOS prevention... "); - TimeUnit.SECONDS.sleep(30); - return retryIfEmptyOrStatusRuntimeException(callable, retries - 1); - } - } - - private List addResponsesToList(AnnotateImageRequest request) { List actual = new ArrayList<>(); - - BatchAnnotateImagesResponse response = - imageAnnotatorClient.batchAnnotateImages(ImmutableList.of(request)); - List responses = response.getResponsesList(); - for (AnnotateImageResponse res : responses) { - if (res.getError().getCode() == 14) { - throw new StatusRuntimeException(Status.UNAVAILABLE); - } - for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) { - actual.add(annotation.getDescription()); - } + AnnotateImageResponse res = request(request); + for (EntityAnnotation annotation : assertNotEmpty(res, res.getLandmarkAnnotationsList())) { + actual.add(annotation.getDescription()); } - return actual; + assertThat(actual).contains("Palace of Fine Arts"); } @Test public void detectLandmarksGcsTest() throws IOException { - List responses = - getResponsesList("landmark/pofa.jpg", Type.LANDMARK_DETECTION, true); + AnnotateImageResponse res = + requestAnnotatedImage("landmark/pofa.jpg", Type.LANDMARK_DETECTION, true); List actual = new ArrayList<>(); - for (AnnotateImageResponse res : responses) { - for (EntityAnnotation annotation : res.getLandmarkAnnotationsList()) { - actual.add(annotation.getDescription()); - } + for (EntityAnnotation annotation : assertNotEmpty(res, res.getLandmarkAnnotationsList())) { + actual.add(annotation.getDescription()); } assertThat(actual).contains("Palace of Fine Arts"); } @Test public void detectLogosTest() throws IOException { - List responses = - getResponsesList("logos.png", Type.LOGO_DETECTION, false); - for (AnnotateImageResponse res : responses) { - for (EntityAnnotation annotation : res.getLogoAnnotationsList()) { - assertEquals("Google", annotation.getDescription()); - } + AnnotateImageResponse res = requestAnnotatedImage("logos.png", Type.LOGO_DETECTION, false); + for (EntityAnnotation annotation : assertNotEmpty(res, res.getLogoAnnotationsList())) { + assertEquals("Google", annotation.getDescription()); } } @Test public void detectLogosGcsTest() throws IOException { - List responses = - getResponsesList("logo/logo_google.png", Type.LOGO_DETECTION, true); - for (AnnotateImageResponse res : responses) { - for (EntityAnnotation annotation : res.getLogoAnnotationsList()) { - assertEquals("Google", annotation.getDescription()); - } + AnnotateImageResponse res = + requestAnnotatedImage("logo/logo_google.png", Type.LOGO_DETECTION, true); + for (EntityAnnotation annotation : assertNotEmpty(res, res.getLogoAnnotationsList())) { + assertEquals("Google", annotation.getDescription()); } } @Test public void detectTextTest() throws IOException { - List responses = - getResponsesList("text.jpg", Type.TEXT_DETECTION, false); + AnnotateImageResponse res = requestAnnotatedImage("text.jpg", Type.TEXT_DETECTION, false); List actual = new ArrayList<>(); - for (AnnotateImageResponse res : responses) { - for (EntityAnnotation annotation : res.getTextAnnotationsList()) { - actual.add(annotation.getDescription()); - } + for (EntityAnnotation annotation : assertNotEmpty(res, res.getTextAnnotationsList())) { + actual.add(annotation.getDescription()); } assertThat(actual).contains("PS4"); } @Test public void detectTextGcsTest() throws IOException { - List responses = - getResponsesList("text/screen.jpg", Type.TEXT_DETECTION, true); + AnnotateImageResponse res = requestAnnotatedImage("text/screen.jpg", Type.TEXT_DETECTION, true); List actual = new ArrayList<>(); - for (AnnotateImageResponse res : responses) { - for (EntityAnnotation annotation : res.getTextAnnotationsList()) { - actual.add(annotation.getDescription()); - } + for (EntityAnnotation annotation : assertNotEmpty(res, res.getTextAnnotationsList())) { + actual.add(annotation.getDescription()); } String joinedActual = String.join(" ", actual); assertThat(joinedActual).contains("37%"); @@ -425,64 +409,54 @@ public void detectTextGcsTest() throws IOException { @Test public void detectPropertiesTest() throws IOException { - List responses = - getResponsesList("landmark.jpg", Type.IMAGE_PROPERTIES, false); + AnnotateImageResponse res = requestAnnotatedImage("landmark.jpg", Type.IMAGE_PROPERTIES, false); List actual = new ArrayList<>(); - for (AnnotateImageResponse res : responses) { - DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors(); - for (ColorInfo color : colors.getColorsList()) { - actual.add(color.getPixelFraction()); - } + DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors(); + for (ColorInfo color : assertNotEmpty(res, colors.getColorsList())) { + actual.add(color.getPixelFraction()); } assertThat(actual).contains((float) 0.14140345); } @Test public void detectPropertiesGcsTest() throws IOException { - List responses = - getResponsesList("landmark/pofa.jpg", Type.IMAGE_PROPERTIES, true); + AnnotateImageResponse res = + requestAnnotatedImage("landmark/pofa.jpg", Type.IMAGE_PROPERTIES, true); List actual = new ArrayList<>(); - for (AnnotateImageResponse res : responses) { - DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors(); - for (ColorInfo color : colors.getColorsList()) { - actual.add(color.getPixelFraction()); - } + DominantColorsAnnotation colors = res.getImagePropertiesAnnotation().getDominantColors(); + for (ColorInfo color : assertNotEmpty(res, colors.getColorsList())) { + actual.add(color.getPixelFraction()); } assertThat(actual).contains((float) 0.14140345); } @Test public void detectSafeSearchTest() throws IOException { - List responses = - getResponsesList("wakeupcat.jpg", Type.SAFE_SEARCH_DETECTION, false); - for (AnnotateImageResponse res : responses) { - SafeSearchAnnotation annotation = res.getSafeSearchAnnotation(); - assertEquals(Likelihood.VERY_UNLIKELY, annotation.getAdult()); - assertEquals(Likelihood.VERY_UNLIKELY, annotation.getRacy()); - } + AnnotateImageResponse res = + requestAnnotatedImage("wakeupcat.jpg", Type.SAFE_SEARCH_DETECTION, false); + SafeSearchAnnotation annotation = res.getSafeSearchAnnotation(); + assertEquals(Likelihood.VERY_UNLIKELY, annotation.getAdult()); + assertEquals(Likelihood.VERY_UNLIKELY, annotation.getRacy()); } @Test public void detectWebEntitiesTest() throws IOException { - List responses = getResponsesList("city.jpg", Type.WEB_DETECTION, false); + AnnotateImageResponse res = requestAnnotatedImage("city.jpg", Type.WEB_DETECTION, false); List actual = new ArrayList<>(); - for (AnnotateImageResponse imgResponse : responses) { - for (WebDetection.WebEntity entity : imgResponse.getWebDetection().getWebEntitiesList()) { - actual.add(entity.getDescription()); - } + for (WebDetection.WebEntity entity : + assertNotEmpty(res, res.getWebDetection().getWebEntitiesList())) { + actual.add(entity.getDescription()); } assertThat(actual).contains("Skyscraper"); } @Test public void detectSafeSearchGcsTest() throws IOException { - List responses = - getResponsesList("label/wakeupcat.jpg", Type.SAFE_SEARCH_DETECTION, true); - for (AnnotateImageResponse res : responses) { - SafeSearchAnnotation annotation = res.getSafeSearchAnnotation(); - assertEquals(Likelihood.VERY_UNLIKELY, annotation.getAdult()); - assertEquals(Likelihood.VERY_UNLIKELY, annotation.getRacy()); - } + AnnotateImageResponse res = + requestAnnotatedImage("label/wakeupcat.jpg", Type.SAFE_SEARCH_DETECTION, true); + SafeSearchAnnotation annotation = res.getSafeSearchAnnotation(); + assertEquals(Likelihood.VERY_UNLIKELY, annotation.getAdult()); + assertEquals(Likelihood.VERY_UNLIKELY, annotation.getRacy()); } @Test @@ -496,14 +470,11 @@ public void detectWebEntitiesGcsTest() { AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build(); - BatchAnnotateImagesResponse response = - imageAnnotatorClient.batchAnnotateImages(ImmutableList.of(request)); - List responses = response.getResponsesList(); + AnnotateImageResponse res = request(request); List actual = new ArrayList<>(); - for (AnnotateImageResponse imgResponse : responses) { - for (WebDetection.WebEntity entity : imgResponse.getWebDetection().getWebEntitiesList()) { - actual.add(entity.getDescription()); - } + for (WebDetection.WebEntity entity : + assertNotEmpty(res, res.getWebDetection().getWebEntitiesList())) { + actual.add(entity.getDescription()); } assertThat(actual).contains("Palace of Fine Arts"); } @@ -524,14 +495,12 @@ public void detectWebEntitiesIncludeGeoResultsTest() throws IOException { .setImageContext(imageContext) .setImage(img) .build(); - BatchAnnotateImagesResponse response = - imageAnnotatorClient.batchAnnotateImages(ImmutableList.of(request)); - List responses = response.getResponsesList(); + + AnnotateImageResponse res = request(request); List actual = new ArrayList<>(); - for (AnnotateImageResponse imgResponse : responses) { - for (WebDetection.WebEntity entity : imgResponse.getWebDetection().getWebEntitiesList()) { - actual.add(entity.getDescription()); - } + for (WebDetection.WebEntity entity : + assertNotEmpty(res, res.getWebDetection().getWebEntitiesList())) { + actual.add(entity.getDescription()); } List expectedResults = new ArrayList<>(); expectedResults.add("Electra Tower"); @@ -556,29 +525,23 @@ public void detectWebEntitiesIncludeGeoResultsGcsTest() { .setImageContext(imageContext) .setImage(img) .build(); - BatchAnnotateImagesResponse response = - imageAnnotatorClient.batchAnnotateImages(ImmutableList.of(request)); - List responses = response.getResponsesList(); + AnnotateImageResponse res = request(request); List actual = new ArrayList<>(); - for (AnnotateImageResponse imgResponse : responses) { - for (WebDetection.WebEntity entity : imgResponse.getWebDetection().getWebEntitiesList()) { - actual.add(entity.getDescription()); - } + for (WebDetection.WebEntity entity : + assertNotEmpty(res, res.getWebDetection().getWebEntitiesList())) { + actual.add(entity.getDescription()); } assertThat(actual).contains("Palace of Fine Arts"); } @Test public void detectCropHintsTest() throws IOException { - List responses = - getResponsesList("wakeupcat.jpg", Type.CROP_HINTS, false); + AnnotateImageResponse res = requestAnnotatedImage("wakeupcat.jpg", Type.CROP_HINTS, false); List actual = new ArrayList<>(); - for (AnnotateImageResponse imgResponse : responses) { - CropHintsAnnotation annotation = imgResponse.getCropHintsAnnotation(); - for (CropHint hint : annotation.getCropHintsList()) { - for (Vertex vertex : hint.getBoundingPoly().getVerticesList()) { - actual.add(vertex.getX()); - } + CropHintsAnnotation annotation = res.getCropHintsAnnotation(); + for (CropHint hint : assertNotEmpty(res, annotation.getCropHintsList())) { + for (Vertex vertex : assertNotEmpty(res, hint.getBoundingPoly().getVerticesList())) { + actual.add(vertex.getX()); } } assertEquals(Arrays.asList(210, 476, 476, 210), actual); @@ -586,15 +549,12 @@ public void detectCropHintsTest() throws IOException { @Test public void detectCropHintsGcsTest() throws IOException { - List responses = - getResponsesList("label/wakeupcat.jpg", Type.CROP_HINTS, true); + AnnotateImageResponse res = requestAnnotatedImage("label/wakeupcat.jpg", Type.CROP_HINTS, true); List actual = new ArrayList<>(); - for (AnnotateImageResponse imgResponse : responses) { - CropHintsAnnotation annotation = imgResponse.getCropHintsAnnotation(); - for (CropHint hint : annotation.getCropHintsList()) { - for (Vertex vertex : hint.getBoundingPoly().getVerticesList()) { - actual.add(vertex.getX()); - } + CropHintsAnnotation annotation = res.getCropHintsAnnotation(); + for (CropHint hint : assertNotEmpty(res, annotation.getCropHintsList())) { + for (Vertex vertex : assertNotEmpty(res, hint.getBoundingPoly().getVerticesList())) { + actual.add(vertex.getX()); } } assertEquals(Arrays.asList(210, 476, 476, 210), actual); @@ -602,37 +562,30 @@ public void detectCropHintsGcsTest() throws IOException { @Test public void detectDocumentTextTest() throws IOException { - List responses = - getResponsesList("text.jpg", Type.DOCUMENT_TEXT_DETECTION, false); - String actual = ""; - for (AnnotateImageResponse imgResponse : responses) { - TextAnnotation annotation = imgResponse.getFullTextAnnotation(); - actual = annotation.getText(); - } + AnnotateImageResponse res = + requestAnnotatedImage("text.jpg", Type.DOCUMENT_TEXT_DETECTION, false); + TextAnnotation annotation = res.getFullTextAnnotation(); + String actual = annotation.getText(); assertThat(actual).contains("After preparation is complete"); } @Test public void detectDocumentTextGcs() throws IOException { - List responses = - getResponsesList("text/screen.jpg", Type.DOCUMENT_TEXT_DETECTION, true); - String actual = ""; - for (AnnotateImageResponse imgResponse : responses) { - TextAnnotation annotation = imgResponse.getFullTextAnnotation(); - actual = annotation.getText(); - } + AnnotateImageResponse res = + requestAnnotatedImage("text/screen.jpg", Type.DOCUMENT_TEXT_DETECTION, true); + TextAnnotation annotation = res.getFullTextAnnotation(); + String actual = annotation.getText(); assertThat(actual).contains("After preparation is complete"); } @Test public void detectLocalizedObjectsTest() throws IOException { - List responses = - getResponsesList("puppies.jpg", Type.OBJECT_LOCALIZATION, false); + AnnotateImageResponse res = + requestAnnotatedImage("puppies.jpg", Type.OBJECT_LOCALIZATION, false); List actual = new ArrayList<>(); - for (AnnotateImageResponse res : responses) { - for (LocalizedObjectAnnotation entity : res.getLocalizedObjectAnnotationsList()) { - actual.add(entity.getName()); - } + for (LocalizedObjectAnnotation entity : + assertNotEmpty(res, res.getLocalizedObjectAnnotationsList())) { + actual.add(entity.getName()); } assertThat(actual).contains("Dog"); } @@ -659,13 +612,12 @@ public void getProductTest() { @Test public void detectLocalizedObjectsGcsTest() throws IOException { - List responses = - getResponsesList("object_localization/puppies.jpg", Type.OBJECT_LOCALIZATION, true); + AnnotateImageResponse res = + requestAnnotatedImage("object_localization/puppies.jpg", Type.OBJECT_LOCALIZATION, true); List actual = new ArrayList<>(); - for (AnnotateImageResponse res : responses) { - for (LocalizedObjectAnnotation entity : res.getLocalizedObjectAnnotationsList()) { - actual.add(entity.getName()); - } + for (LocalizedObjectAnnotation entity : + assertNotEmpty(res, res.getLocalizedObjectAnnotationsList())) { + actual.add(entity.getName()); } assertThat(actual).contains("Dog"); }