ImageService { public static int calculateInSampleSize(final int nativeWidth, int requestedWidth) { int inSampleSize = 1; if (nativeWidth > requestedWidth) { final int halfWidth = nativeWidth / 2; while ((halfWidth / inSampleSize) >= requestedWidth) { inSampleSize *= 2; } } return inSampleSize; }  @Nullable static Bitmap asBitmap(@NonNull final DownloadResponse downloadResponse, final int requestedWidth); @Nullable static Bitmap byteArrayToBitmap(@NonNull final byte[] bytes, final int requestedWidth); static long getMemBytes(@NonNull Options options); static int calculateInSampleSize(final int nativeWidth, int requestedWidth);  }
@Test public void calculateInSampleSize_withImageSmallerThanRequested_shouldBe1() { int nativeWidth = 1024; assertThat(ImageService.calculateInSampleSize(nativeWidth, 2046)).isEqualTo(1); }
@Test public void calculateInSampleSize_withImageSlightlyBiggerThanRequest_shouldBe1() { int nativeWidth = 1024; assertThat(ImageService.calculateInSampleSize(nativeWidth, 800)).isEqualTo(1); }
@Test public void calculateInSampleSize_withImageMuchBiggerThanRequest_shouldBe4() { int nativeWidth = 2048; int nativeHeight = 1024; assertThat(ImageService.calculateInSampleSize(nativeWidth, 512)).isEqualTo(4); }