@Override public ImageInRegion getImage(String id) { String region = ImageInRegion.extractRegion(id); String imageId = ImageInRegion.extractImageId(id); // The id of the image can be an id or a slug. Use the corresponding method of the API depending on what is // provided. If it can be parsed as a number, use the method to get by ID. Otherwise, get by slug. Integer numericId = Ints.tryParse(imageId); Image image = numericId == null ? api.imageApi().get(imageId) : api.imageApi().get(numericId); return image == null ? null : ImageInRegion.create(image, region); }
@Override public ImageInRegion getImage(String id) { String region = ImageInRegion.extractRegion(id); String imageId = ImageInRegion.extractImageId(id); // The id of the image can be an id or a slug. Use the corresponding method of the API depending on what is // provided. If it can be parsed as a number, use the method to get by ID. Otherwise, get by slug. Integer numericId = Ints.tryParse(imageId); Image image = numericId == null ? api.imageApi().get(imageId) : api.imageApi().get(numericId); return image == null ? null : ImageInRegion.create(image, region); }
@Override public ImageInRegion getImage(String id) { String region = ImageInRegion.extractRegion(id); String imageId = ImageInRegion.extractImageId(id); // The id of the image can be an id or a slug. Use the corresponding method of the API depending on what is // provided. If it can be parsed as a number, use the method to get by ID. Otherwise, get by slug. Integer numericId = Ints.tryParse(imageId); Image image = numericId == null ? api.imageApi().get(imageId) : api.imageApi().get(numericId); return image == null ? null : ImageInRegion.create(image, region); }
public void testGetImage() { Optional<Image> first = api().list().concat().first(); assertTrue(first.isPresent(), "At least one image was expected to exist"); assertNotNull(api().get(first.get().id())); }
public void testGetImageBySlug() { Optional<Image> first = api().list().concat().firstMatch(new Predicate<Image>() { @Override public boolean apply(Image input) { return !isNullOrEmpty(input.slug()); } }); assertTrue(first.isPresent(), "At least one image with the 'slug' field set was expected to exist"); assertNotNull(api().get(first.get().slug())); }
public void testGetImageUsingSlugReturns404() throws InterruptedException { server.enqueue(response404()); Image image = api.imageApi().get("foo"); assertNull(image); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/images/foo"); }
public void testGetImageReturns404() throws InterruptedException { server.enqueue(response404()); Image image = api.imageApi().get(1); assertNull(image); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/images/1"); }
public void testGetImage() throws InterruptedException { server.enqueue(jsonResponse("/image.json")); Image image = api.imageApi().get(1); assertEquals(image, imageFromResource("/image.json")); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/images/1"); }
public void testGetImageUsingSlug() throws InterruptedException { server.enqueue(jsonResponse("/image.json")); Image image = api.imageApi().get("foo"); assertEquals(image, imageFromResource("/image.json")); assertEquals(server.getRequestCount(), 1); assertSent(server, "GET", "/images/foo"); }