diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/BitmapUtils.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/BitmapUtils.java index 0370f64d96b..1419b863004 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/BitmapUtils.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/BitmapUtils.java @@ -85,7 +85,7 @@ private static Boolean compareBasicBitmapsInfo(Bitmap bmp1, Bitmap bmp2) { public static boolean compareBitmaps(Bitmap bmp1, Bitmap bmp2) { final Boolean basicComparison = compareBasicBitmapsInfo(bmp1, bmp2); if (basicComparison != null) { - return basicComparison.booleanValue(); + return basicComparison; } for (int i = 0; i < bmp1.getWidth(); i++) { @@ -107,7 +107,7 @@ public static boolean compareBitmaps(Bitmap bmp1, Bitmap bmp2) { public static boolean compareBitmaps(Bitmap bmp1, Bitmap bmp2, double minimumPrecision) { final Boolean basicComparison = compareBasicBitmapsInfo(bmp1, bmp2); if (basicComparison != null) { - return basicComparison.booleanValue(); + return basicComparison; } final int width = bmp1.getWidth(); @@ -210,7 +210,7 @@ public static boolean compareBitmapsMse( boolean isPremultiplied) { final Boolean basicComparison = compareBasicBitmapsInfo(expected, actual); if (basicComparison != null) { - return basicComparison.booleanValue(); + return basicComparison; } double mse = 0; @@ -238,14 +238,13 @@ public static boolean compareBitmapsMse( Log.d(TAG, "MSE too large for normal case: " + mse); return false; } - return true; } else { if (mse <= mseMargin) { Log.d(TAG, "MSE too small for abnormal case: " + mse); return false; } - return true; } + return true; } // Same as above, but asserts compareBitmapsMse's return value. diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ColorUtils.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ColorUtils.java index 0e1690e75b2..b0c88d07b43 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ColorUtils.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ColorUtils.java @@ -49,10 +49,10 @@ public static void verifyColor(@Nonnull String s, int expected, int observed, in + Integer.toHexString(observed) + ", tolerated channel error 0x" + tolerance; - String red = verifyChannel("red", expected, observed, tolerance, (i) -> Color.red(i)); - String green = verifyChannel("green", expected, observed, tolerance, (i) -> Color.green(i)); - String blue = verifyChannel("blue", expected, observed, tolerance, (i) -> Color.blue(i)); - String alpha = verifyChannel("alpha", expected, observed, tolerance, (i) -> Color.alpha(i)); + String red = verifyChannel("red", expected, observed, tolerance, Color::red); + String green = verifyChannel("green", expected, observed, tolerance, Color::green); + String blue = verifyChannel("blue", expected, observed, tolerance, Color::blue); + String alpha = verifyChannel("alpha", expected, observed, tolerance, Color::alpha); buildErrorString(s, red, green, blue, alpha); } @@ -81,10 +81,10 @@ public static void verifyColor( + observed + ", tolerated channel error " + tolerance; - String red = verifyChannel("red", expected, observed, tolerance, (c) -> c.red()); - String green = verifyChannel("green", expected, observed, tolerance, (c) -> c.green()); - String blue = verifyChannel("blue", expected, observed, tolerance, (c) -> c.blue()); - String alpha = verifyChannel("alpha", expected, observed, tolerance, (c) -> c.alpha()); + String red = verifyChannel("red", expected, observed, tolerance, Color::red); + String green = verifyChannel("green", expected, observed, tolerance, Color::green); + String blue = verifyChannel("blue", expected, observed, tolerance, Color::blue); + String alpha = verifyChannel("alpha", expected, observed, tolerance, Color::alpha); buildErrorString(msg, red, green, blue, alpha); } @@ -95,18 +95,18 @@ private static void buildErrorString( @Nullable String green, @Nullable String blue, @Nullable String alpha) { - String err = null; + StringBuilder error = null; for (String channel : new String[] {red, green, blue, alpha}) { if (channel == null) { continue; } - if (err == null) { - err = s; + if (error == null) { + error = new StringBuilder(s); } - err += "\n\t\t" + channel; + error.append("\n\t\t").append(channel); } - if (err != null) { - fail(err); + if (error != null) { + fail(error.toString()); } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/HardwareAcceleratedActivityRenderTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/HardwareAcceleratedActivityRenderTest.java index e09713686f2..1fad0b6b073 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/HardwareAcceleratedActivityRenderTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/HardwareAcceleratedActivityRenderTest.java @@ -26,7 +26,7 @@ @Config(minSdk = Q) public class HardwareAcceleratedActivityRenderTest { @Test - public void hardwareAcceleratedActivity_setup() throws Exception { + public void hardwareAcceleratedActivity_setup() { // Setting up an Activity is a smoke test that exercises much of the HardwareRenderer / // RenderNode / RecordingCanvas native code. Robolectric.setupActivity(HardwareAcceleratedActivity.class); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAllocationRegistryTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAllocationRegistryTest.java index 7fdc554ae6d..474a313aa91 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAllocationRegistryTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAllocationRegistryTest.java @@ -25,7 +25,7 @@ public final class ShadowNativeAllocationRegistryTest { // TODO(hoisie): choose a different free function to test in V and above. @Config(maxSdk = U.SDK_INT) @Test - public void applyFreeFunction_matrix() throws Exception { + public void applyFreeFunction_matrix() { WeakReference weakMatrix = new WeakReference<>(newMatrix()); // Invokes 'applyFreeFunction' when the matrix is GC'd. GcFinalization.awaitClear(weakMatrix); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAnimatedImageDrawableTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAnimatedImageDrawableTest.java index d1f47a6cf37..cc992a41b54 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAnimatedImageDrawableTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAnimatedImageDrawableTest.java @@ -28,7 +28,7 @@ public void setup() { } @Test - public void testInflate() throws Exception { + public void testInflate() { AnimatedImageDrawable aid = (AnimatedImageDrawable) resources.getDrawable(R.drawable.animated); assertThat(aid).isNotNull(); } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAnimatedVectorDrawableTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAnimatedVectorDrawableTest.java index 03a9492590c..87d439ba520 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAnimatedVectorDrawableTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeAnimatedVectorDrawableTest.java @@ -2,6 +2,8 @@ import static android.os.Build.VERSION_CODES.O; import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertFalse; +import static junit.framework.Assert.assertTrue; import android.content.res.Resources; import android.graphics.Bitmap; @@ -92,7 +94,7 @@ public void start_isRunning_returnsTrue() throws Exception { drawable.start(); - assertEquals(true, Shadows.shadowOf(drawable).isStartInitiated()); + assertTrue(Shadows.shadowOf(drawable).isStartInitiated()); } @Test @@ -116,6 +118,6 @@ public void stop_returnsFalse() throws Exception { drawable.start(); drawable.stop(); - assertEquals(false, Shadows.shadowOf(drawable).isStartInitiated()); + assertFalse(Shadows.shadowOf(drawable).isStartInitiated()); } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBitmapFactoryTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBitmapFactoryTest.java index a028529b605..b7e547e4ac5 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBitmapFactoryTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBitmapFactoryTest.java @@ -48,6 +48,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.RandomAccessFile; +import javax.annotation.Nullable; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -278,9 +279,7 @@ public void testDecodeReuseRecycled() { assertThrows( IllegalArgumentException.class, - () -> { - BitmapFactory.decodeResource(res, R.drawable.pass, options); - }); + () -> BitmapFactory.decodeResource(res, R.drawable.pass, options)); } /** Create bitmap sized to load unscaled resources: start, pass, and alpha */ @@ -345,9 +344,7 @@ public void testDecodeReuseFailure() { options.inMutable = true; options.inScaled = false; options.inSampleSize = 4; - Bitmap reduced = BitmapFactory.decodeResource(res, R.drawable.robot, options); - - options.inBitmap = reduced; + options.inBitmap = BitmapFactory.decodeResource(res, R.drawable.robot, options); options.inSampleSize = 1; assertThrows( "should throw exception due to lack of space", @@ -410,8 +407,8 @@ public void testDecodeReuseEquivalentScaling() { options.inSampleSize = 2; Bitmap scaleReduced = BitmapFactory.decodeResource(res, R.drawable.robot, options); // verify that density isn't incorrectly carried over during bitmap reuse - assertFalse(densityReduced.getDensity() == 2); - assertFalse(densityReduced.getDensity() == 0); + assertNotEquals(2, densityReduced.getDensity()); + assertNotEquals(0, densityReduced.getDensity()); assertSame(densityReduced, scaleReduced); } @@ -430,17 +427,19 @@ public void testDecodeInPurgeableAllocationCount() { options.inInputShareable = false; byte[] array = obtainArray(); Bitmap purgeableBitmap = BitmapFactory.decodeByteArray(array, 0, array.length, options); - assertFalse(purgeableBitmap.getAllocationByteCount() == 0); + assertNotEquals(0, purgeableBitmap.getAllocationByteCount()); } private int defaultCreationDensity; - private void verifyScaled(Bitmap b) { + private void verifyScaled(@Nullable Bitmap b) { + assertNotNull(b); assertEquals(START_WIDTH * 2, b.getWidth()); assertEquals(2, b.getDensity()); } - private void verifyUnscaled(Bitmap b) { + private void verifyUnscaled(@Nullable Bitmap b) { + assertNotNull(b); assertEquals(START_WIDTH, b.getWidth()); assertEquals(b.getDensity(), defaultCreationDensity); } @@ -478,28 +477,30 @@ public void testDecodeScaling() { @Test public void testDecodeFileDescriptor1() throws IOException { - ParcelFileDescriptor pfd = obtainParcelDescriptor(obtainPath()); - FileDescriptor input = pfd.getFileDescriptor(); - Rect r = new Rect(1, 1, 1, 1); - Bitmap b = BitmapFactory.decodeFileDescriptor(input, r, opt1); - assertNotNull(b); - // Test the bitmap size - assertEquals(START_HEIGHT, b.getHeight()); - assertEquals(START_WIDTH, b.getWidth()); - // Test if no bitmap - assertNull(BitmapFactory.decodeFileDescriptor(input, r, opt2)); + try (ParcelFileDescriptor pfd = obtainParcelDescriptor(obtainPath())) { + FileDescriptor input = pfd.getFileDescriptor(); + Rect r = new Rect(1, 1, 1, 1); + Bitmap b = BitmapFactory.decodeFileDescriptor(input, r, opt1); + assertNotNull(b); + // Test the bitmap size + assertEquals(START_HEIGHT, b.getHeight()); + assertEquals(START_WIDTH, b.getWidth()); + // Test if no bitmap + assertNull(BitmapFactory.decodeFileDescriptor(input, r, opt2)); + } } @Test public void testDecodeFileDescriptor2() throws IOException { - ParcelFileDescriptor pfd = obtainParcelDescriptor(obtainPath()); - FileDescriptor input = pfd.getFileDescriptor(); - Bitmap b = BitmapFactory.decodeFileDescriptor(input); + try (ParcelFileDescriptor pfd = obtainParcelDescriptor(obtainPath())) { + FileDescriptor input = pfd.getFileDescriptor(); + Bitmap b = BitmapFactory.decodeFileDescriptor(input); - assertNotNull(b); - // Test the bitmap size - assertEquals(START_HEIGHT, b.getHeight()); - assertEquals(START_WIDTH, b.getWidth()); + assertNotNull(b); + // Test the bitmap size + assertEquals(START_HEIGHT, b.getHeight()); + assertEquals(START_WIDTH, b.getWidth()); + } } @Test @@ -511,30 +512,32 @@ public void testDecodeFileDescriptor3() throws IOException { for (int j = 0; j < actualOffsets.length; ++j) { long actualOffset = actualOffsets[j]; String path = obtainPath(testImage.id, actualOffset); - RandomAccessFile file = new RandomAccessFile(path, "r"); - FileDescriptor fd = file.getFD(); - assertTrue(fd.valid()); - - // Set the offset to ACTUAL_OFFSET - file.seek(actualOffset); - assertEquals(file.getFilePointer(), actualOffset); - - // Now decode. This should be successful and leave the offset - // unchanged. - Bitmap b = BitmapFactory.decodeFileDescriptor(fd); - assertNotNull(b); - assertEquals(file.getFilePointer(), actualOffset); - - // Now use the other offset. It should fail to decode, and - // the offset should remain unchanged. - long otherOffset = actualOffsets[(j + 1) % actualOffsets.length]; - assertFalse(otherOffset == actualOffset); - file.seek(otherOffset); - assertEquals(file.getFilePointer(), otherOffset); - - b = BitmapFactory.decodeFileDescriptor(fd); - assertNull(b); - assertEquals(file.getFilePointer(), otherOffset); + + try (RandomAccessFile file = new RandomAccessFile(path, "r")) { + FileDescriptor fd = file.getFD(); + assertTrue(fd.valid()); + + // Set the offset to ACTUAL_OFFSET + file.seek(actualOffset); + assertEquals(file.getFilePointer(), actualOffset); + + // Now decode. This should be successful and leave the offset + // unchanged. + Bitmap b = BitmapFactory.decodeFileDescriptor(fd); + assertNotNull(b); + assertEquals(file.getFilePointer(), actualOffset); + + // Now use the other offset. It should fail to decode, and + // the offset should remain unchanged. + long otherOffset = actualOffsets[(j + 1) % actualOffsets.length]; + assertNotEquals(otherOffset, actualOffset); + file.seek(otherOffset); + assertEquals(file.getFilePointer(), otherOffset); + + b = BitmapFactory.decodeFileDescriptor(fd); + assertNull(b); + assertEquals(file.getFilePointer(), otherOffset); + } } } } @@ -604,10 +607,9 @@ static File obtainFile(int resId, long offset) throws IOException { File dir = RuntimeEnvironment.getApplication().getFilesDir(); dir.mkdirs(); - String name = - RuntimeEnvironment.getApplication().getResources().getResourceEntryName(resId).toString(); + String name = RuntimeEnvironment.getApplication().getResources().getResourceEntryName(resId); if (offset > 0) { - name = name + "_" + String.valueOf(offset); + name = name + "_" + offset; } File file = new File(dir, name); @@ -624,7 +626,7 @@ static File obtainFile(int resId, long offset) throws IOException { // Write a bunch of zeroes before the image. assertThat(offset).isAtMost(1024); fOutput.write(dataBuffer, 0, (int) offset); - int readLength = 0; + int readLength; while ((readLength = is.read(dataBuffer)) != -1) { fOutput.write(dataBuffer, 0, readLength); } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBitmapTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBitmapTest.java index bf0170a9121..280a3ad0e0d 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBitmapTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBitmapTest.java @@ -77,7 +77,7 @@ public class ShadowNativeBitmapTest { private BitmapFactory.Options options; public static List getRgbColorSpaces() { - List rgbColorSpaces = new ArrayList(); + List rgbColorSpaces = new ArrayList<>(); for (ColorSpace.Named e : ColorSpace.Named.values()) { ColorSpace cs = ColorSpace.get(e); if (cs.getModel() != ColorSpace.Model.RGB) { @@ -437,7 +437,7 @@ public void testWrapHardwareBufferWithInvalidUsageFails() { try (HardwareBuffer hwBuffer = HardwareBuffer.create( 512, 512, HardwareBuffer.RGBA_8888, 1, HardwareBuffer.USAGE_CPU_WRITE_RARELY)) { - Bitmap bitmap = Bitmap.wrapHardwareBuffer(hwBuffer, ColorSpace.get(Named.SRGB)); + Bitmap.wrapHardwareBuffer(hwBuffer, ColorSpace.get(Named.SRGB)); } }); } @@ -452,7 +452,7 @@ public void testWrapHardwareBufferWithRgbBufferButNonRgbColorSpaceFails() { try (HardwareBuffer hwBuffer = HardwareBuffer.create( 512, 512, HardwareBuffer.RGBA_8888, 1, HardwareBuffer.USAGE_GPU_SAMPLED_IMAGE)) { - Bitmap bitmap = Bitmap.wrapHardwareBuffer(hwBuffer, ColorSpace.get(Named.CIE_LAB)); + Bitmap.wrapHardwareBuffer(hwBuffer, ColorSpace.get(Named.CIE_LAB)); } }); } @@ -587,7 +587,7 @@ public void testGetColor() { bitmap.eraseColor(wideGamutLong); Color result = bitmap.getColor(0, 0); - if (bitmap.getColorSpace().equals(sRGB)) { + if (sRGB.equals(bitmap.getColorSpace())) { assertEquals(bitmap.getPixel(0, 0), result.toArgb()); } if (eraseColorSpace.equals(bitmapColorSpace)) { @@ -979,7 +979,7 @@ private void verifyAlphaAndPremul( case ARGB_4444: // This shouldn't happen, since we don't allow creating or converting // to 4444. - assertFalse(true); + fail(); break; case RGB_565: assertFalse(bitmap.hasAlpha()); @@ -1366,7 +1366,7 @@ private void verifyPremultipliedBitmapConfig(Config config, boolean expectedPrem Bitmap bitmap = Bitmap.createBitmap(1, 1, config); bitmap.setPremultiplied(true); bitmap.setPixel(0, 0, Color.TRANSPARENT); - assertTrue(bitmap.isPremultiplied() == expectedPremul); + assertEquals(bitmap.isPremultiplied(), expectedPremul); bitmap.setHasAlpha(false); assertFalse(bitmap.isPremultiplied()); @@ -1385,21 +1385,21 @@ public void testSetPremultipliedData() { // with premul, will store 2,2,2,2, so it doesn't get value correct Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888); bitmap.setPixel(0, 0, PREMUL_COLOR); - assertEquals(bitmap.getPixel(0, 0), PREMUL_ROUNDED_COLOR); + assertEquals(PREMUL_ROUNDED_COLOR, bitmap.getPixel(0, 0)); // read premultiplied value directly bitmap.setPremultiplied(false); - assertEquals(bitmap.getPixel(0, 0), PREMUL_STORED_COLOR); + assertEquals(PREMUL_STORED_COLOR, bitmap.getPixel(0, 0)); // value can now be stored/read correctly bitmap.setPixel(0, 0, PREMUL_COLOR); - assertEquals(bitmap.getPixel(0, 0), PREMUL_COLOR); + assertEquals(PREMUL_COLOR, bitmap.getPixel(0, 0)); // verify with array methods int[] testArray = new int[] {PREMUL_COLOR}; bitmap.setPixels(testArray, 0, 1, 0, 0, 1, 1); bitmap.getPixels(testArray, 0, 1, 0, 0, 1, 1); - assertEquals(bitmap.getPixel(0, 0), PREMUL_COLOR); + assertEquals(PREMUL_COLOR, bitmap.getPixel(0, 0)); } @Test @@ -1832,8 +1832,6 @@ private void strictModeTest(Runnable runnable) { } } - static final int ANDROID_BITMAP_FORMAT_RGBA_8888 = 1; - private static int scaleFromDensity(int size, int sdensity, int tdensity) { if (sdensity == Bitmap.DENSITY_NONE || sdensity == tdensity) { return size; diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBlendModeColorFilterTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBlendModeColorFilterTest.java index 574b5214585..35d714b0f03 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBlendModeColorFilterTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeBlendModeColorFilterTest.java @@ -19,8 +19,6 @@ @RunWith(AndroidJUnit4.class) @Config(minSdk = Q) // Added in API 29 public class ShadowNativeBlendModeColorFilterTest { - private static final int TOLERANCE = 5; - private static final int TEST_WIDTH = 90; private static final int TEST_HEIGHT = 90; private static final int LEFT_X = TEST_WIDTH / 4; diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeColorSpaceTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeColorSpaceTest.java index 9aac3a05f32..fb01a61cae6 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeColorSpaceTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeColorSpaceTest.java @@ -881,7 +881,7 @@ public void testCctToXyz() { } } - private static float[] identityMatrix = + private static final float[] identityMatrix = new float[] { 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeHardwareRendererObserverTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeHardwareRendererObserverTest.java index e67a2f70a1e..581bc3181d1 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeHardwareRendererObserverTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeHardwareRendererObserverTest.java @@ -22,15 +22,13 @@ public class ShadowNativeHardwareRendererObserverTest { public void test_hardwareRenderer() { OnFrameMetricsAvailableListener listener = i -> {}; if (RuntimeEnvironment.getApiLevel() >= S) { - HardwareRendererObserver unused = - new HardwareRendererObserver(listener, new long[0], new Handler(), false); + new HardwareRendererObserver(listener, new long[0], new Handler(), false); } else { - HardwareRendererObserver unused = - ReflectionHelpers.callConstructor( - HardwareRendererObserver.class, - ClassParameter.from(OnFrameMetricsAvailableListener.class, listener), - ClassParameter.from(long[].class, new long[0]), - ClassParameter.from(Handler.class, new Handler())); + ReflectionHelpers.callConstructor( + HardwareRendererObserver.class, + ClassParameter.from(OnFrameMetricsAvailableListener.class, listener), + ClassParameter.from(long[].class, new long[0]), + ClassParameter.from(Handler.class, new Handler())); } } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeHardwareRendererTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeHardwareRendererTest.java index 94da9cc2684..0aa822b83c0 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeHardwareRendererTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeHardwareRendererTest.java @@ -35,7 +35,7 @@ public class ShadowNativeHardwareRendererTest { @Test public void test_hardwareRenderer() { - HardwareRenderer unused = new HardwareRenderer(); + new HardwareRenderer(); } @Config(maxSdk = R) @@ -50,7 +50,7 @@ public void setWideGamut_doesNotCrash() { public void choreographer_firstCalled() { // In some SDK levels, the Choreographer constructor ends up calling // HardwareRenderer.nHackySetRTAnimationsEnabled. Ensure that RNG is loaded if this happens. - var unused = Choreographer.getInstance(); + Choreographer.getInstance(); } @Test diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeImageReaderTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeImageReaderTest.java index ed9cded3bbc..6c04d87ad6b 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeImageReaderTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeImageReaderTest.java @@ -96,33 +96,35 @@ public void imageReader_setOnImageAvailableListener() { @Test public void imageReader_lockHardwareCanvas_drawColor() { - ImageReader reader = ImageReader.newInstance(100, 100, PixelFormat.RGBA_8888, 1); - Surface surface = reader.getSurface(); - Canvas canvas = surface.lockHardwareCanvas(); - canvas.drawColor(Color.RED); - surface.unlockCanvasAndPost(canvas); - Image image = reader.acquireNextImage(); - assertThat(image).isNotNull(); - Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); - Plane[] planes = image.getPlanes(); - bitmap.copyPixelsFromBuffer(planes[0].getBuffer()); - surface.release(); - assertThat(Integer.toHexString(bitmap.getPixel(50, 50))) - .isEqualTo(Integer.toHexString(Color.RED)); + try (ImageReader reader = ImageReader.newInstance(100, 100, PixelFormat.RGBA_8888, 1)) { + Surface surface = reader.getSurface(); + Canvas canvas = surface.lockHardwareCanvas(); + canvas.drawColor(Color.RED); + surface.unlockCanvasAndPost(canvas); + Image image = reader.acquireNextImage(); + assertThat(image).isNotNull(); + Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888); + Plane[] planes = image.getPlanes(); + bitmap.copyPixelsFromBuffer(planes[0].getBuffer()); + surface.release(); + assertThat(Integer.toHexString(bitmap.getPixel(50, 50))) + .isEqualTo(Integer.toHexString(Color.RED)); + } } @Test - public void testGetHardwareBuffer() throws Exception { - ImageReader reader = ImageReader.newInstance(1, 1, PixelFormat.RGBA_8888, 1); - Surface surface = reader.getSurface(); - Canvas canvas = surface.lockHardwareCanvas(); - canvas.drawColor(Color.RED); - surface.unlockCanvasAndPost(canvas); - Image image = reader.acquireNextImage(); - assertThat(image).isNotNull(); - HardwareBuffer buffer = image.getHardwareBuffer(); - // TODO(hoisie): buffer should not be null, but fixing it will require an implementation of - // HardwareBuffer on host libandroid_runtime. - assertThat(buffer).isNull(); + public void testGetHardwareBuffer() { + try (ImageReader reader = ImageReader.newInstance(1, 1, PixelFormat.RGBA_8888, 1)) { + Surface surface = reader.getSurface(); + Canvas canvas = surface.lockHardwareCanvas(); + canvas.drawColor(Color.RED); + surface.unlockCanvasAndPost(canvas); + Image image = reader.acquireNextImage(); + assertThat(image).isNotNull(); + HardwareBuffer buffer = image.getHardwareBuffer(); + // TODO(hoisie): buffer should not be null, but fixing it will require an implementation of + // HardwareBuffer on host libandroid_runtime. + assertThat(buffer).isNull(); + } } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeLineBreakerTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeLineBreakerTest.java index a318ce90aae..5a42ec74e8b 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeLineBreakerTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeLineBreakerTest.java @@ -30,13 +30,9 @@ @RunWith(RobolectricTestRunner.class) public class ShadowNativeLineBreakerTest { - private static final String TAG = "LineBreakerTest"; - - private static Paint paint; - @Before public void setup() { - paint = new Paint(); + Paint paint = new Paint(); Context context = RuntimeEnvironment.getApplication(); AssetManager am = context.getAssets(); Typeface tf = new Typeface.Builder(am, "fonts/layout/linebreak.ttf").build(); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeLinearGradientTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeLinearGradientTest.java index 76ea26e76af..4e4c475cff4 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeLinearGradientTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeLinearGradientTest.java @@ -67,15 +67,11 @@ public void testLinearGradientLong() { long green = Color.pack(0, 1, 0, 1, p3); long blue = Color.pack(0, 0, 1, 1, p3); long[] colors = new long[] {blue, green, red}; - float[] positions = null; - LinearGradient lg = new LinearGradient(0, 0, 0, 40, colors, positions, TileMode.CLAMP); + LinearGradient lg = new LinearGradient(0, 0, 0, 40, colors, null, TileMode.CLAMP); Bitmap b = drawLinearGradient(lg, Bitmap.Config.RGBA_F16); final ColorSpace bitmapColorSpace = b.getColorSpace(); - Function convert = - (l) -> { - return Color.valueOf(Color.convert(l, bitmapColorSpace)); - }; + Function convert = (l) -> Color.valueOf(Color.convert(l, bitmapColorSpace)); ColorUtils.verifyColor( "Top-most color should be mostly blue!", convert.apply(blue), b.getColor(0, 0), 0.09f); @@ -152,10 +148,7 @@ public void testNullColorInts() { int[] colors = null; assertThrows( NullPointerException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, colors, null, TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, colors, null, TileMode.CLAMP)); } @Test @@ -164,10 +157,7 @@ public void testNullColorLongs() { long[] colors = null; assertThrows( NullPointerException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, colors, null, TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, colors, null, TileMode.CLAMP)); } @Test @@ -175,10 +165,7 @@ public void testNullColorLongs() { public void testNoColorInts() { assertThrows( IllegalArgumentException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, new int[0], null, TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, new int[0], null, TileMode.CLAMP)); } @Test @@ -186,10 +173,7 @@ public void testNoColorInts() { public void testNoColorLongs() { assertThrows( IllegalArgumentException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, new long[0], null, TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, new long[0], null, TileMode.CLAMP)); } @Test @@ -197,10 +181,7 @@ public void testNoColorLongs() { public void testOneColorInts() { assertThrows( IllegalArgumentException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, new int[1], null, TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, new int[1], null, TileMode.CLAMP)); } @Test @@ -208,10 +189,7 @@ public void testOneColorInts() { public void testOneColorLongs() { assertThrows( IllegalArgumentException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, new long[1], null, TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, new long[1], null, TileMode.CLAMP)); } @Test @@ -222,10 +200,7 @@ public void testMismatchColorLongs() { colors[1] = Color.pack(.5f, .5f, .5f, 1.0f, ColorSpace.get(ColorSpace.Named.DISPLAY_P3)); assertThrows( IllegalArgumentException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, colors, null, TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, colors, null, TileMode.CLAMP)); } @Test @@ -235,10 +210,7 @@ public void testMismatchColorLongs2() { long color1 = Color.pack(.5f, .5f, .5f, 1.0f, ColorSpace.get(ColorSpace.Named.DISPLAY_P3)); assertThrows( IllegalArgumentException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, color0, color1, TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, color0, color1, TileMode.CLAMP)); } @Test @@ -246,10 +218,7 @@ public void testMismatchColorLongs2() { public void testMismatchPositionsInts() { assertThrows( IllegalArgumentException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, new int[2], new float[3], TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, new int[2], new float[3], TileMode.CLAMP)); } @Test @@ -257,24 +226,16 @@ public void testMismatchPositionsInts() { public void testMismatchPositionsLongs() { assertThrows( IllegalArgumentException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, new long[2], new float[3], TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, new long[2], new float[3], TileMode.CLAMP)); } @Test @Config(minSdk = Q) public void testInvalidColorLongs() { - long[] colors = new long[2]; - colors[0] = -1L; - colors[0] = -2L; + long[] colors = new long[] {-1L, -2L}; assertThrows( IllegalArgumentException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, colors, null, TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, colors, null, TileMode.CLAMP)); } @Test @@ -282,10 +243,7 @@ public void testInvalidColorLongs() { public void testInvalidColorLong() { assertThrows( IllegalArgumentException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, -1L, Color.pack(Color.RED), TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, -1L, Color.pack(Color.RED), TileMode.CLAMP)); } @Test @@ -293,9 +251,6 @@ public void testInvalidColorLong() { public void testInvalidColorLong2() { assertThrows( IllegalArgumentException.class, - () -> { - LinearGradient unused = - new LinearGradient(0.5f, 0, 1.5f, 0, Color.pack(Color.RED), -1L, TileMode.CLAMP); - }); + () -> new LinearGradient(0.5f, 0, 1.5f, 0, Color.pack(Color.RED), -1L, TileMode.CLAMP)); } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeMaskFilterTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeMaskFilterTest.java index 34e48b99145..5f776a6ffa2 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeMaskFilterTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeMaskFilterTest.java @@ -13,6 +13,6 @@ public class ShadowNativeMaskFilterTest { @Test public void testConstructor() { - var unused = new MaskFilter(); + new MaskFilter(); } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeMeasuredParagraphTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeMeasuredParagraphTest.java index cba45b3741f..c02eafc1620 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeMeasuredParagraphTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeMeasuredParagraphTest.java @@ -140,9 +140,8 @@ public void buildForMeasurement() { public void buildForStaticLayout() { MeasuredParagraph mt = - (MeasuredParagraph) - reflector(MeasuredParagraphReflector.class) - .buildForStaticLayout(paint, "XXX", 0, 3, LTR, false, false, null); + reflector(MeasuredParagraphReflector.class) + .buildForStaticLayout(paint, "XXX", 0, 3, LTR, false, false, null); assertNotNull(mt); assertNotNull(mt.getChars()); assertEquals("XXX", charsToString(mt.getChars())); @@ -157,9 +156,8 @@ public void buildForStaticLayout() { // Recycle it MeasuredParagraph mt2 = - (MeasuredParagraph) - reflector(MeasuredParagraphReflector.class) - .buildForStaticLayout(paint, "_VVV_", 1, 4, RTL, false, false, mt); + reflector(MeasuredParagraphReflector.class) + .buildForStaticLayout(paint, "_VVV_", 1, 4, RTL, false, false, mt); assertEquals(mt2, mt); assertNotNull(mt2.getChars()); assertEquals("VVV", charsToString(mt.getChars())); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePaintTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePaintTest.java index aa62c359fc3..37297c0f9c7 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePaintTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePaintTest.java @@ -13,6 +13,7 @@ import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThrows; import static org.junit.Assert.assertTrue; @@ -890,7 +891,7 @@ public void testAccessTextSize() { } @Test - public void testGetTextWidths() throws Exception { + public void testGetTextWidths() { String text = "HIJKLMN"; char[] textChars = text.toCharArray(); SpannedString textSpan = new SpannedString(text); @@ -1383,8 +1384,8 @@ public void testMeasureText() { } float totalWidth = 0; - for (int i = 0; i < widths.length; i++) { - totalWidth += widths[i]; + for (float width : widths) { + totalWidth += width; } // Test measuring the widths of the entire text @@ -1579,10 +1580,9 @@ public void testHasGlyph() { // We don't require gender-neutral emoji, but if present, results must be consistent // whether VS is present or not. - assertTrue( - p.hasGlyph("\uD83D\uDC69\u200D\u2695") - == // WOMAN, ZWJ, STAFF OF AESCULAPIUS - p.hasGlyph("\uD83D\uDC69\u200D\u2695\uFE0F")); // above + VS16 + assertEquals( + p.hasGlyph("\uD83D\uDC69\u200D\u2695"), // WOMAN, ZWJ, STAFF OF AESCULAPIUS + p.hasGlyph("\uD83D\uDC69\u200D\u2695\uFE0F")); // above + VS16 } @Test @@ -1940,7 +1940,7 @@ public void testGetOffsetForAdvance_graphemeCluster() { final int offset = p.getOffsetForAdvance( string, 0, string.length(), 0, string.length(), false, widthToOffset); - assertFalse(1 == offset); + assertNotEquals(1, offset); assertTrue(0 == offset || string.length() == offset); } } @@ -1952,7 +1952,7 @@ public void testGetOffsetForAdvance_graphemeCluster() { final int offset = p.getOffsetForAdvance( string, 0, string.length(), 0, string.length(), false, widthToOffset); - assertFalse(2 == offset); + assertNotEquals(2, offset); assertTrue(0 == offset || string.length() == offset); } { @@ -2104,7 +2104,7 @@ public void testGetRunCursor_cursor_after() { } @Test - public void testGetRunCursor_currsor_at() { + public void testGetRunCursor_cursor_at() { assertEquals(0, getTextRunCursor("abc", 0, CURSOR_AT)); assertEquals(1, getTextRunCursor("abc", 1, CURSOR_AT)); assertEquals(2, getTextRunCursor("abc", 2, CURSOR_AT)); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathEffectTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathEffectTest.java index 551150988a9..0381c7a8666 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathEffectTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathEffectTest.java @@ -14,6 +14,6 @@ public class ShadowNativePathEffectTest { @Test public void testConstructor() { - var unused = new PathEffect(); + new PathEffect(); } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathIteratorTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathIteratorTest.java index 12ec2b0efb1..9d83519e8fd 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathIteratorTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathIteratorTest.java @@ -383,7 +383,7 @@ public void testPointsArrayOffset() { PathIterator iterator = mPath.getPathIterator(); assertEquals(PathIterator.VERB_MOVE, iterator.next(pointsArray, offset)); assertEquals(PathIterator.VERB_LINE, iterator.next(pointsArray, offset)); - assertEquals(0f, pointsArray[offset + 0], 0f); + assertEquals(0f, pointsArray[offset], 0f); assertEquals(0f, pointsArray[offset + 1], 0f); assertEquals(100f, pointsArray[offset + 2], 0f); assertEquals(200f, pointsArray[offset + 3], 0f); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathMeasureTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathMeasureTest.java index 0780bb30a66..2096ae340d7 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathMeasureTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathMeasureTest.java @@ -67,10 +67,7 @@ public void testGetPosTanArraysTooSmall() { float[] tan = {1f}; assertThrows( - ArrayIndexOutOfBoundsException.class, - () -> { - pathMeasure.getPosTan(distance, pos, tan); - }); + ArrayIndexOutOfBoundsException.class, () -> pathMeasure.getPosTan(distance, pos, tan)); } @Test diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathTest.java index cc47cb54a0a..c3edc1797cd 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePathTest.java @@ -439,10 +439,7 @@ public void testApproximate_circle() { public void legacyShadowPathAPIs_notSupported() { Path path = new Path(); assertThrows( - UnsupportedOperationException.class, - () -> { - ((ShadowPath) Shadow.extract(path)).getPoints(); - }); + UnsupportedOperationException.class, () -> ((ShadowPath) Shadow.extract(path)).getPoints()); } private void addRectToPath(Path path) { diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePictureTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePictureTest.java index 695ff374a54..cf02dc6b1ac 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePictureTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePictureTest.java @@ -78,7 +78,7 @@ private void verifyBalance(Picture picture) { assertEquals(beforeSaveCount, canvas.getSaveCount()); - assertTrue(beforeMatrix.equals(canvas.getMatrix())); + assertEquals(beforeMatrix, canvas.getMatrix()); Rect afterClip = new Rect(); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePropertyValuesHolderTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePropertyValuesHolderTest.java index 2bb95a68ba2..999977e8f69 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePropertyValuesHolderTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativePropertyValuesHolderTest.java @@ -4,7 +4,6 @@ import static org.junit.Assert.assertEquals; import android.animation.PropertyValuesHolder; -import android.app.Instrumentation; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.platform.app.InstrumentationRegistry; import org.junit.Before; @@ -16,15 +15,13 @@ @Config(minSdk = O) public class ShadowNativePropertyValuesHolderTest { - private Instrumentation instrumentation; private float startY; private float endY; private String property; @Before public void setup() { - instrumentation = InstrumentationRegistry.getInstrumentation(); - instrumentation.setInTouchMode(false); + InstrumentationRegistry.getInstrumentation().setInTouchMode(false); property = "y"; startY = 0; endY = 10; diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRadialGradientTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRadialGradientTest.java index ab47b9ad77a..997d747e1f8 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRadialGradientTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRadialGradientTest.java @@ -62,10 +62,7 @@ public void testColorLong() { canvas.drawPaint(paint); final ColorSpace bitmapColorSpace = bitmap.getColorSpace(); - Function convert = - (l) -> { - return Color.valueOf(Color.convert(l, bitmapColorSpace)); - }; + Function convert = (l) -> Color.valueOf(Color.convert(l, bitmapColorSpace)); final Color centerColor = bitmap.getColor(50, 50); ColorUtils.verifyColor("Center color should be red!", convert.apply(red), centerColor, 0.034f); @@ -147,9 +144,7 @@ public void testNullColorInts() { int[] colors = null; assertThrows( NullPointerException.class, - () -> { - RadialGradient unused = new RadialGradient(0.5f, 0.5f, 1, colors, null, TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, colors, null, TileMode.CLAMP)); } @Test @@ -158,19 +153,14 @@ public void testNullColorLongs() { long[] colors = null; assertThrows( NullPointerException.class, - () -> { - RadialGradient unused = new RadialGradient(0.5f, 0.5f, 1, colors, null, TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, colors, null, TileMode.CLAMP)); } @Test public void testNoColorInts() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient(0.5f, 0.5f, 1, new int[0], null, TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, new int[0], null, TileMode.CLAMP)); } @Test @@ -178,20 +168,14 @@ public void testNoColorInts() { public void testNoColorLongs() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient(0.5f, 0.5f, 1, new long[0], null, TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, new long[0], null, TileMode.CLAMP)); } @Test public void testOneColorInts() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient(0.5f, 0.5f, 1, new int[1], null, TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, new int[1], null, TileMode.CLAMP)); } @Test @@ -199,10 +183,7 @@ public void testOneColorInts() { public void testOneColorLongs() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient(0.5f, 0.5f, 1, new long[1], null, TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, new long[1], null, TileMode.CLAMP)); } @Test @@ -213,9 +194,7 @@ public void testMismatchColorLongs() { colors[1] = Color.pack(.5f, .5f, .5f, 1.0f, ColorSpace.get(ColorSpace.Named.DISPLAY_P3)); assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = new RadialGradient(0.5f, 0.5f, 1, colors, null, TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, colors, null, TileMode.CLAMP)); } @Test @@ -225,9 +204,7 @@ public void testMismatchColorLongs2() { long color1 = Color.pack(.5f, .5f, .5f, 1.0f, ColorSpace.get(ColorSpace.Named.DISPLAY_P3)); assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = new RadialGradient(0.5f, 0.5f, 1, color0, color1, TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, color0, color1, TileMode.CLAMP)); } @Test @@ -235,10 +212,7 @@ public void testMismatchColorLongs2() { public void testMismatchPositionsInts() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient(0.5f, 0.5f, 1, new int[2], new float[3], TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, new int[2], new float[3], TileMode.CLAMP)); } @Test @@ -246,23 +220,16 @@ public void testMismatchPositionsInts() { public void testMismatchPositionsLongs() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient(0.5f, 0.5f, 1, new long[2], new float[3], TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, new long[2], new float[3], TileMode.CLAMP)); } @Test @Config(minSdk = Q) public void testInvalidColorLongs() { - long[] colors = new long[2]; - colors[0] = -1L; - colors[0] = -2L; + long[] colors = new long[] {-1L, -2L}; assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = new RadialGradient(0.5f, 0.5f, 1, colors, null, TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, colors, null, TileMode.CLAMP)); } @Test @@ -270,10 +237,7 @@ public void testInvalidColorLongs() { public void testInvalidColorLong() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient(0.5f, 0.5f, 1, -1L, Color.pack(Color.RED), TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, -1L, Color.pack(Color.RED), TileMode.CLAMP)); } @Test @@ -281,10 +245,7 @@ public void testInvalidColorLong() { public void testInvalidColorLong2() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient(0.5f, 0.5f, 1, Color.pack(Color.RED), -1L, TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 1, Color.pack(Color.RED), -1L, TileMode.CLAMP)); } @Test @@ -292,10 +253,7 @@ public void testInvalidColorLong2() { public void testZeroRadius() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient(0.5f, 0.5f, 0, Color.RED, Color.BLUE, TileMode.CLAMP); - }); + () -> new RadialGradient(0.5f, 0.5f, 0, Color.RED, Color.BLUE, TileMode.CLAMP)); } @Test @@ -303,11 +261,9 @@ public void testZeroRadius() { public void testZeroRadiusArray() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient( - 0.5f, 0.5f, 0, new int[] {Color.RED, Color.BLUE}, null, TileMode.CLAMP); - }); + () -> + new RadialGradient( + 0.5f, 0.5f, 0, new int[] {Color.RED, Color.BLUE}, null, TileMode.CLAMP)); } @Test @@ -315,11 +271,9 @@ public void testZeroRadiusArray() { public void testZeroRadiusLong() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient( - 0.5f, 0.5f, 0, Color.pack(Color.RED), Color.pack(Color.BLUE), TileMode.CLAMP); - }); + () -> + new RadialGradient( + 0.5f, 0.5f, 0, Color.pack(Color.RED), Color.pack(Color.BLUE), TileMode.CLAMP)); } @Test @@ -327,15 +281,13 @@ public void testZeroRadiusLong() { public void testZeroRadiusLongArray() { assertThrows( IllegalArgumentException.class, - () -> { - RadialGradient unused = - new RadialGradient( - 0.5f, - 0.5f, - 0, - new long[] {Color.pack(Color.RED), Color.pack(Color.BLUE)}, - null, - TileMode.CLAMP); - }); + () -> + new RadialGradient( + 0.5f, + 0.5f, + 0, + new long[] {Color.pack(Color.RED), Color.pack(Color.BLUE)}, + null, + TileMode.CLAMP)); } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRegionTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRegionTest.java index 11c7d83e445..3b7e5344364 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRegionTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRegionTest.java @@ -123,14 +123,14 @@ public class ShadowNativeRegionTest { private Region region; private void verifyPointsInsideRegion(int[][] area) { - for (int i = 0; i < area.length; i++) { - assertTrue(region.contains(area[i][0], area[i][1])); + for (int[] ints : area) { + assertTrue(region.contains(ints[0], ints[1])); } } private void verifyPointsOutsideRegion(int[][] area) { - for (int i = 0; i < area.length; i++) { - assertFalse(region.contains(area[i][0], area[i][1])); + for (int[] ints : area) { + assertFalse(region.contains(ints[0], ints[1])); } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRenderNodeTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRenderNodeTest.java index 5b485380470..f6d9cc1385a 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRenderNodeTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRenderNodeTest.java @@ -254,7 +254,7 @@ public void testCameraDistanceSetGet() { @Test @Config(minSdk = O, maxSdk = P) - public void testIsValid() throws Exception { + public void testIsValid() { Object renderNode = reflector(RenderNodeOpReflector.class).create("name", null); RenderNodeOpReflector renderNodeOpReflector = reflector(RenderNodeOpReflector.class, renderNode); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRuntimeShaderTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRuntimeShaderTest.java index 807ef97d70c..a5518ccd1d6 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRuntimeShaderTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeRuntimeShaderTest.java @@ -61,18 +61,17 @@ public void setup() { @Config(minSdk = S, maxSdk = S_V2) @Test public void testConstructor() { - var unused = - ReflectionHelpers.callConstructor( - RuntimeShader.class, - ClassParameter.from(String.class, SKSL), - ClassParameter.from(boolean.class, false)); + ReflectionHelpers.callConstructor( + RuntimeShader.class, + ClassParameter.from(String.class, SKSL), + ClassParameter.from(boolean.class, false)); } /** {@link #SKSL} does not compile on V and above. */ @Config(minSdk = TIRAMISU, maxSdk = U.SDK_INT) @Test public void testConstructorT() { - var unused = new RuntimeShader(SKSL); + new RuntimeShader(SKSL); } @Test diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeShaderTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeShaderTest.java index fd6e428d598..04d8b2c7618 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeShaderTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeShaderTest.java @@ -22,7 +22,7 @@ public class ShadowNativeShaderTest { @Test public void testConstructor() { - var unused = new Shader(); + new Shader(); } @Test diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeStaticLayoutTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeStaticLayoutTest.java index bac4f09e80f..11299899530 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeStaticLayoutTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeStaticLayoutTest.java @@ -62,6 +62,7 @@ import java.util.ArrayList; import java.util.List; import java.util.Locale; +import javax.annotation.Nonnull; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -99,7 +100,7 @@ public class ShadowNativeStaticLayoutTest { /* the first line must have one tab. the others not. totally 6 lines */ private static final CharSequence LAYOUT_TEXT = - "CharSe\tq\nChar" + "Sequence\nCharSequence\nHelllo\n, world\nLongLongLong"; + "CharSe\tq\nChar" + "Sequence\nCharSequence\nHello\n, world\nLongLongLong"; private static final CharSequence LAYOUT_TEXT_SINGLE_LINE = "CharSequence"; @@ -269,7 +270,7 @@ public void testBuilder() { StaticLayout layout = builder.build(); assertEquals(ELLIPSIZE_WIDTH, layout.getEllipsizedWidth()); assertEquals(DEFAULT_OUTER_WIDTH, layout.getWidth()); - assertTrue(layout.getEllipsisCount(0) == 0); + assertEquals(0, layout.getEllipsisCount(0)); assertTrue(layout.getEllipsisCount(5) > 0); } { @@ -480,7 +481,7 @@ public void testGetContainsTabAfterLast() { /** * Returns an array of directionalities for the specified line. The array alternates counts of * characters in left-to-right and right-to-left segments of the line. We can not check the return - * value, for Directions's field is package private So only check it not null + * value, for Directions' field is package private So only check it not null */ @Test public void testGetLineDirections() { @@ -523,12 +524,12 @@ public void testGetEllipsisCount() { // Multilines (6 lines) and TruncateAt.START so no ellipsis at all defaultLayout = createEllipsizeStaticLayout(LAYOUT_TEXT, TextUtils.TruncateAt.MIDDLE); - assertTrue(defaultLayout.getEllipsisCount(0) == 0); - assertTrue(defaultLayout.getEllipsisCount(1) == 0); - assertTrue(defaultLayout.getEllipsisCount(2) == 0); - assertTrue(defaultLayout.getEllipsisCount(3) == 0); - assertTrue(defaultLayout.getEllipsisCount(4) == 0); - assertTrue(defaultLayout.getEllipsisCount(5) == 0); + assertEquals(0, defaultLayout.getEllipsisCount(0)); + assertEquals(0, defaultLayout.getEllipsisCount(1)); + assertEquals(0, defaultLayout.getEllipsisCount(2)); + assertEquals(0, defaultLayout.getEllipsisCount(3)); + assertEquals(0, defaultLayout.getEllipsisCount(4)); + assertEquals(0, defaultLayout.getEllipsisCount(5)); assertThrows(ArrayIndexOutOfBoundsException.class, () -> defaultLayout.getEllipsisCount(-1)); @@ -539,31 +540,31 @@ public void testGetEllipsisCount() { // Multilines (6 lines) and TruncateAt.MIDDLE so no ellipsis at all defaultLayout = createEllipsizeStaticLayout(LAYOUT_TEXT, TextUtils.TruncateAt.MIDDLE); - assertTrue(defaultLayout.getEllipsisCount(0) == 0); - assertTrue(defaultLayout.getEllipsisCount(1) == 0); - assertTrue(defaultLayout.getEllipsisCount(2) == 0); - assertTrue(defaultLayout.getEllipsisCount(3) == 0); - assertTrue(defaultLayout.getEllipsisCount(4) == 0); - assertTrue(defaultLayout.getEllipsisCount(5) == 0); + assertEquals(0, defaultLayout.getEllipsisCount(0)); + assertEquals(0, defaultLayout.getEllipsisCount(1)); + assertEquals(0, defaultLayout.getEllipsisCount(2)); + assertEquals(0, defaultLayout.getEllipsisCount(3)); + assertEquals(0, defaultLayout.getEllipsisCount(4)); + assertEquals(0, defaultLayout.getEllipsisCount(5)); // Multilines (6 lines) and TruncateAt.END so ellipsis only on the last line defaultLayout = createEllipsizeStaticLayout(LAYOUT_TEXT, TextUtils.TruncateAt.END); - assertTrue(defaultLayout.getEllipsisCount(0) == 0); - assertTrue(defaultLayout.getEllipsisCount(1) == 0); - assertTrue(defaultLayout.getEllipsisCount(2) == 0); - assertTrue(defaultLayout.getEllipsisCount(3) == 0); - assertTrue(defaultLayout.getEllipsisCount(4) == 0); + assertEquals(0, defaultLayout.getEllipsisCount(0)); + assertEquals(0, defaultLayout.getEllipsisCount(1)); + assertEquals(0, defaultLayout.getEllipsisCount(2)); + assertEquals(0, defaultLayout.getEllipsisCount(3)); + assertEquals(0, defaultLayout.getEllipsisCount(4)); assertTrue(defaultLayout.getEllipsisCount(5) > 0); // Multilines (6 lines) and TruncateAt.MARQUEE so ellipsis only on the last line defaultLayout = createEllipsizeStaticLayout(LAYOUT_TEXT, TextUtils.TruncateAt.END); - assertTrue(defaultLayout.getEllipsisCount(0) == 0); - assertTrue(defaultLayout.getEllipsisCount(1) == 0); - assertTrue(defaultLayout.getEllipsisCount(2) == 0); - assertTrue(defaultLayout.getEllipsisCount(3) == 0); - assertTrue(defaultLayout.getEllipsisCount(4) == 0); + assertEquals(0, defaultLayout.getEllipsisCount(0)); + assertEquals(0, defaultLayout.getEllipsisCount(1)); + assertEquals(0, defaultLayout.getEllipsisCount(2)); + assertEquals(0, defaultLayout.getEllipsisCount(3)); + assertEquals(0, defaultLayout.getEllipsisCount(4)); assertTrue(defaultLayout.getEllipsisCount(5) > 0); } @@ -655,7 +656,7 @@ public void testImmutableStaticLayout() { // String wrapper for testing not well known implementation of CharSequence. private static class FakeCharSequence implements CharSequence { - private String str; + private final String str; public FakeCharSequence(String str) { this.str = str; @@ -672,11 +673,13 @@ public int length() { } @Override + @Nonnull public CharSequence subSequence(int start, int end) { return str.subSequence(start, end); } @Override + @Nonnull public String toString() { return str; } @@ -716,13 +719,13 @@ private String buildTestMessage(CharSequence seq) { StringBuilder builder = new StringBuilder(); for (int i = 0; i < seq.length(); ++i) { - builder.append(String.format("0x%04X ", Integer.valueOf(seq.charAt(i)))); + builder.append(String.format("0x%04X ", (int) seq.charAt(i))); } return "testString: \"" - + seq.toString() + + seq + "\"[" - + builder.toString() + + builder + "]" + ", class: " + seq.getClass().getName() @@ -1527,6 +1530,7 @@ static class LayoutParam { } @Override + @Nonnull public String toString() { return "{" + "mStrategy=" @@ -1820,19 +1824,19 @@ private static class FakeLineBackgroundSpan implements LineBackgroundSpan { private final List history; FakeLineBackgroundSpan() { - history = new ArrayList(); + history = new ArrayList<>(); } @Override public void drawBackground( - Canvas c, - Paint p, + @Nonnull Canvas c, + @Nonnull Paint p, int left, int right, int top, int baseline, int bottom, - CharSequence text, + @Nonnull CharSequence text, int start, int end, int lnum) { @@ -1934,7 +1938,7 @@ public void testBidiVisibleEnd() { Bitmap.createBitmap(layout.getWidth(), layout.getHeight(), Bitmap.Config.RGB_565); final Canvas c = new Canvas(bmp); // Make sure draw won't cause crashes. - // draw eventualy calls TextLine.draw which was the problematic method. + // draw eventually calls TextLine.draw which was the problematic method. layout.draw(c); } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeSweepGradientTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeSweepGradientTest.java index 8438eaa3430..a0e5be5631f 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeSweepGradientTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeSweepGradientTest.java @@ -163,60 +163,40 @@ public void testZeroScaleMatrix() { @Test public void testNullColorInts() { int[] colors = null; - assertThrows( - NullPointerException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, colors, null); - }); + assertThrows(NullPointerException.class, () -> new SweepGradient(1, 0.5f, colors, null)); } @Test @Config(minSdk = Q) public void testNullColorLongs() { long[] colors = null; - assertThrows( - NullPointerException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, colors, null); - }); + assertThrows(NullPointerException.class, () -> new SweepGradient(1, 0.5f, colors, null)); } @Test public void testNoColorInts() { assertThrows( - IllegalArgumentException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, new int[0], null); - }); + IllegalArgumentException.class, () -> new SweepGradient(1, 0.5f, new int[0], null)); } @Test @Config(minSdk = Q) public void testNoColorLongs() { assertThrows( - IllegalArgumentException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, new long[0], null); - }); + IllegalArgumentException.class, () -> new SweepGradient(1, 0.5f, new long[0], null)); } @Test public void testOneColorInts() { assertThrows( - IllegalArgumentException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, new int[1], null); - }); + IllegalArgumentException.class, () -> new SweepGradient(1, 0.5f, new int[1], null)); } @Test @Config(minSdk = Q) public void testOneColorLongs() { assertThrows( - IllegalArgumentException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, new long[1], null); - }); + IllegalArgumentException.class, () -> new SweepGradient(1, 0.5f, new long[1], null)); } @Test @@ -225,11 +205,7 @@ public void testMismatchColorLongs() { long[] colors = new long[2]; colors[0] = Color.pack(Color.BLUE); colors[1] = Color.pack(.5f, .5f, .5f, 1.0f, ColorSpace.get(ColorSpace.Named.DISPLAY_P3)); - assertThrows( - IllegalArgumentException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, colors, null); - }); + assertThrows(IllegalArgumentException.class, () -> new SweepGradient(1, 0.5f, colors, null)); } @Test @@ -237,20 +213,13 @@ public void testMismatchColorLongs() { public void testMismatchColorLongs2() { long color0 = Color.pack(Color.BLUE); long color1 = Color.pack(.5f, .5f, .5f, 1.0f, ColorSpace.get(ColorSpace.Named.DISPLAY_P3)); - assertThrows( - IllegalArgumentException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, color0, color1); - }); + assertThrows(IllegalArgumentException.class, () -> new SweepGradient(1, 0.5f, color0, color1)); } @Test public void testMismatchPositionsInts() { assertThrows( - IllegalArgumentException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, new int[2], new float[3]); - }); + IllegalArgumentException.class, () -> new SweepGradient(1, 0.5f, new int[2], new float[3])); } @Test @@ -258,22 +227,14 @@ public void testMismatchPositionsInts() { public void testMismatchPositionsLongs() { assertThrows( IllegalArgumentException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, new long[2], new float[3]); - }); + () -> new SweepGradient(1, 0.5f, new long[2], new float[3])); } @Test @Config(minSdk = Q) public void testInvalidColorLongs() { - long[] colors = new long[2]; - colors[0] = -1L; - colors[0] = -2L; - assertThrows( - IllegalArgumentException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, colors, null); - }); + long[] colors = new long[] {-1L, -2L}; + assertThrows(IllegalArgumentException.class, () -> new SweepGradient(1, 0.5f, colors, null)); } @Test @@ -281,9 +242,7 @@ public void testInvalidColorLongs() { public void testInvalidColorLong() { assertThrows( IllegalArgumentException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, -1L, Color.pack(Color.RED)); - }); + () -> new SweepGradient(1, 0.5f, -1L, Color.pack(Color.RED))); } @Test @@ -291,9 +250,7 @@ public void testInvalidColorLong() { public void testInvalidColorLong2() { assertThrows( IllegalArgumentException.class, - () -> { - SweepGradient unused = new SweepGradient(1, 0.5f, Color.pack(Color.RED), -1L); - }); + () -> new SweepGradient(1, 0.5f, Color.pack(Color.RED), -1L)); } private String toString(double angle) { @@ -317,10 +274,7 @@ public void testColorLong() { canvas.drawPaint(paint); final ColorSpace bitmapColorSpace = bitmap.getColorSpace(); - Function convert = - (l) -> { - return Color.valueOf(Color.convert(l, bitmapColorSpace)); - }; + Function convert = (l) -> Color.valueOf(Color.convert(l, bitmapColorSpace)); Color lastColor = null; double lastAngle = 0; diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeThreadedRendererTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeThreadedRendererTest.java index 9cc85f74181..61f2dcdca09 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeThreadedRendererTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeThreadedRendererTest.java @@ -15,7 +15,6 @@ public class ShadowNativeThreadedRendererTest { @Test public void testInitialization() { - ThreadedRenderer unused = - ThreadedRenderer.create(ApplicationProvider.getApplicationContext(), false, "Name"); + ThreadedRenderer.create(ApplicationProvider.getApplicationContext(), false, "Name"); } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeTypefaceTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeTypefaceTest.java index 0c9a6128c77..717b2876cad 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeTypefaceTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeTypefaceTest.java @@ -183,19 +183,19 @@ public void testCreateFromFileByFileReference() throws IOException { } @Test - public void testCreateFromFileWithInvalidPath() throws IOException { + public void testCreateFromFileWithInvalidPath() { File file = new File("/invalid/path"); assertThrows(RuntimeException.class, () -> Typeface.createFromFile(file)); } @Test - public void testCreateFromFileByFileNameNull() throws IOException { + public void testCreateFromFileByFileNameNull() { // input abnormal params. assertThrows(NullPointerException.class, () -> Typeface.createFromFile((String) null)); } @Test - public void testCreateFromFileByInvalidFileName() throws IOException { + public void testCreateFromFileByInvalidFileName() { // input abnormal params. assertThrows(RuntimeException.class, () -> Typeface.createFromFile("/invalid/path")); } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeVectorDrawableTest.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeVectorDrawableTest.java index beed3f14192..5a6cc51714a 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeVectorDrawableTest.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/ShadowNativeVectorDrawableTest.java @@ -317,13 +317,13 @@ private String getTitleForStateSet(int[] stateSet) { } final StringBuilder builder = new StringBuilder(); - for (int i = 0; i < stateSet.length; i++) { - final String state = resources.getResourceName(stateSet[i]); + for (int i : stateSet) { + final String state = resources.getResourceName(i); final int stateIndex = state.indexOf("state_"); if (stateIndex >= 0) { builder.append(state.substring(stateIndex + 6)); } else { - builder.append(stateSet[i]); + builder.append(i); } } @@ -414,7 +414,7 @@ public void testColorFilter() { } @Test - public void testGetOpacity() throws XmlPullParserException, IOException { + public void testGetOpacity() { VectorDrawable vectorDrawable = new VectorDrawable(); assertEquals("Default alpha should be 255", 255, vectorDrawable.getAlpha()); @@ -466,7 +466,7 @@ public void legacyShadowDrawableAPI() { } @Test - public void testTint() throws IOException { + public void testTint() { Drawable drawable = resources.getDrawable(R.drawable.vector_icon_delete); drawable = drawable.mutate(); drawable.setTint(Color.BLUE); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapcomparers/MSSIMComparer.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapcomparers/MSSIMComparer.java index e9fcdd3ad86..e9ef6d8d801 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapcomparers/MSSIMComparer.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapcomparers/MSSIMComparer.java @@ -34,7 +34,7 @@ public class MSSIMComparer extends BitmapComparer { public static final double CONSTANT_C2 = Math.pow(CONSTANT_L * CONSTANT_K2, 2); public static final int WINDOW_SIZE = 10; - private double threshold; + private final double threshold; public MSSIMComparer(double threshold) { this.threshold = threshold; diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/ColorCountVerifier.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/ColorCountVerifier.java index 14b2e0300ec..934ee87f501 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/ColorCountVerifier.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/ColorCountVerifier.java @@ -19,9 +19,9 @@ import org.robolectric.shadows.testing.util.CompareUtils; public class ColorCountVerifier extends BitmapVerifier { - private int color; - private int count; - private int threshold; + private final int color; + private final int count; + private final int threshold; public ColorCountVerifier(int color, int count, int threshold) { this.color = color; diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/ColorVerifier.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/ColorVerifier.java index c9aede31fc1..8990a750284 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/ColorVerifier.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/ColorVerifier.java @@ -19,7 +19,7 @@ /** Checks to see if a bitmap is entirely a single color */ public class ColorVerifier extends PerPixelBitmapVerifier { - @ColorInt private int color; + @ColorInt private final int color; public ColorVerifier(@ColorInt int color) { this(color, DEFAULT_THRESHOLD); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/PerPixelBitmapVerifier.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/PerPixelBitmapVerifier.java index 7179cb6da24..3bdebc45b09 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/PerPixelBitmapVerifier.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/PerPixelBitmapVerifier.java @@ -23,14 +23,14 @@ /** This class looks at every pixel in a given bitmap and verifies that it is correct. */ public abstract class PerPixelBitmapVerifier extends BitmapVerifier { - private static final String TAG = "PerPixelBitmapVerifer"; + private static final String TAG = "PerPixelBitmapVerifier"; public static final int DEFAULT_THRESHOLD = 48; // total color difference tolerated without the pixel failing - private int colorTolerance; + private final int colorTolerance; // portion of bitmap allowed to fail pixel check - private float spatialTolerance; + private final float spatialTolerance; public PerPixelBitmapVerifier() { this(DEFAULT_THRESHOLD, 0); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/RectVerifier.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/RectVerifier.java index 5fcf5e18fab..152bb5a63ed 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/RectVerifier.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/RectVerifier.java @@ -19,9 +19,9 @@ /** Tests to see if there is rectangle of a certain color, with a background given */ public class RectVerifier extends PerPixelBitmapVerifier { - private int outerColor; - private int innerColor; - private Rect innerRect; + private final int outerColor; + private final int innerColor; + private final Rect innerRect; public RectVerifier(int outerColor, int innerColor, Rect innerRect) { this(outerColor, innerColor, innerRect, DEFAULT_THRESHOLD); diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/RegionVerifier.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/RegionVerifier.java index 625d87516e2..0d88cd4d3f1 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/RegionVerifier.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/RegionVerifier.java @@ -36,7 +36,7 @@ private static class SubRegionVerifiers { } } - private List regionVerifiers = new ArrayList<>(); + private final List regionVerifiers = new ArrayList<>(); @Override public boolean verify(int[] bitmap, int offset, int stride, int width, int height) { @@ -47,9 +47,9 @@ public boolean verify(int[] bitmap, int offset, int stride, int width, int heigh Rect area = subRegionVerifier.region.getBounds(); isVerified &= verifySubRect(bitmap, offset, stride, subRegionVerifier.verifier, area); } else { - RegionIterator iter = new RegionIterator(subRegionVerifier.region); + RegionIterator iterator = new RegionIterator(subRegionVerifier.region); Rect area = new Rect(); - while (iter.next(area)) { + while (iterator.next(area)) { isVerified &= verifySubRect(bitmap, offset, stride, subRegionVerifier.verifier, area); } } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/SamplePointWideGamutVerifier.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/SamplePointWideGamutVerifier.java index 236ab1e5253..896887849b2 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/SamplePointWideGamutVerifier.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/bitmapverifiers/SamplePointWideGamutVerifier.java @@ -50,10 +50,7 @@ public boolean verify(Bitmap bitmap) { Color actual = bitmap.getColor(p.x, p.y).convert(expected.getColorSpace()); - boolean localSuccess = true; - if (!floatCompare(expected.red(), actual.red(), eps)) { - localSuccess = false; - } + boolean localSuccess = floatCompare(expected.red(), actual.red(), eps); if (!floatCompare(expected.green(), actual.green(), eps)) { localSuccess = false; } diff --git a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/text/EditorState.java b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/text/EditorState.java index 8805ab6de69..fecbf619f91 100644 --- a/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/text/EditorState.java +++ b/integration_tests/nativegraphics/src/test/java/org/robolectric/shadows/testing/text/EditorState.java @@ -23,7 +23,8 @@ import android.text.SpannableString; import android.text.style.ReplacementSpan; import com.google.common.base.Splitter; -import junit.framework.Assert; +import javax.annotation.Nonnull; +import org.junit.Assert; /** * Represents an editor state. @@ -57,13 +58,13 @@ public EditorState() {} private static class MockReplacementSpan extends ReplacementSpan { @Override public int getSize( - Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { + @Nonnull Paint paint, CharSequence text, int start, int end, Paint.FontMetricsInt fm) { return 0; } @Override public void draw( - Canvas canvas, + @Nonnull Canvas canvas, CharSequence text, int start, int end, @@ -71,7 +72,7 @@ public void draw( int top, int y, int bottom, - Paint paint) {} + @Nonnull Paint paint) {} } // Returns true if the code point is ASCII and graph.