From 24e8aa1ac27c894d730ddc6711d087d78b584210 Mon Sep 17 00:00:00 2001 From: Nain57 Date: Sat, 25 Dec 2021 14:21:51 +0100 Subject: [PATCH] Update unit tests --- .../smartautoclicker/detection/CacheTests.kt | 24 +++++++------------ .../detection/ConditionDetectorTests.kt | 2 -- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/detection/src/test/java/com/buzbuz/smartautoclicker/detection/CacheTests.kt b/detection/src/test/java/com/buzbuz/smartautoclicker/detection/CacheTests.kt index 0e75189be..8aa369fdc 100644 --- a/detection/src/test/java/com/buzbuz/smartautoclicker/detection/CacheTests.kt +++ b/detection/src/test/java/com/buzbuz/smartautoclicker/detection/CacheTests.kt @@ -112,7 +112,6 @@ class CacheTests { /** Assert if the [cache] values aren't the correct default ones. */ private fun assertInitialCacheValues() { - assertNull("Initial current image should be null", cache.currentImage) assertNull("Initial screen bitmap should be null", cache.screenBitmap) assertNull("Initial screen pixels should be null", cache.screenPixels) assertEquals("Initial display size is invalid", Rect(), cache.displaySize) @@ -172,8 +171,7 @@ class CacheTests { @Test fun refresh_bitmapCacheCreation() { - cache.currentImage = mockImage - cache.refreshProcessedImage(TEST_DATA_DISPLAY_SIZE) + cache.refreshProcessedImage(mockImage, TEST_DATA_DISPLAY_SIZE) verify(mockBitmapCreator) .createBitmap(TEST_DATA_DISPLAY_SIZE_WIDTH, TEST_DATA_DISPLAY_SIZE_HEIGHT, Bitmap.Config.ARGB_8888) @@ -187,11 +185,9 @@ class CacheTests { @Test fun refresh_bitmapCacheCreation_twice_sameDisplay() { - cache.currentImage = mockImage - cache.refreshProcessedImage(TEST_DATA_DISPLAY_SIZE) + cache.refreshProcessedImage(mockImage, TEST_DATA_DISPLAY_SIZE) - cache.currentImage = mockImage2 - cache.refreshProcessedImage(TEST_DATA_DISPLAY_SIZE_2) + cache.refreshProcessedImage(mockImage2, TEST_DATA_DISPLAY_SIZE_2) verify(mockBitmapCreator) .createBitmap(TEST_DATA_DISPLAY_SIZE_WIDTH, TEST_DATA_DISPLAY_SIZE_HEIGHT, Bitmap.Config.ARGB_8888) @@ -207,9 +203,8 @@ class CacheTests { @Test fun refresh_bitmapCacheCreation_twice_newDisplay() { - cache.currentImage = mockImage - cache.refreshProcessedImage(TEST_DATA_DISPLAY_SIZE) - cache.refreshProcessedImage(TEST_DATA_DISPLAY_SIZE) + cache.refreshProcessedImage(mockImage, TEST_DATA_DISPLAY_SIZE) + cache.refreshProcessedImage(mockImage, TEST_DATA_DISPLAY_SIZE) verify(mockBitmapCreator) .createBitmap(TEST_DATA_DISPLAY_SIZE_WIDTH, TEST_DATA_DISPLAY_SIZE_HEIGHT, Bitmap.Config.ARGB_8888) @@ -223,8 +218,7 @@ class CacheTests { @Test fun refresh_bitmapCaching() { - cache.currentImage = mockImage - cache.refreshProcessedImage(TEST_DATA_DISPLAY_SIZE) + cache.refreshProcessedImage(mockImage, TEST_DATA_DISPLAY_SIZE) inOrder(mockCreatedBitmap).apply { verify(mockCreatedBitmap).copyPixelsFromBuffer(mockImagePlaneBuffer) @@ -267,8 +261,7 @@ class CacheTests { @Test fun release_bitmapCache() { - cache.currentImage = mockImage - cache.refreshProcessedImage(TEST_DATA_DISPLAY_SIZE) + cache.refreshProcessedImage(mockImage, TEST_DATA_DISPLAY_SIZE) cache.release() assertInitialCacheValues() @@ -284,8 +277,7 @@ class CacheTests { @Test fun release_bitmapCache_and_pixelsCache() { - cache.currentImage = mockImage - cache.refreshProcessedImage(TEST_DATA_DISPLAY_SIZE) + cache.refreshProcessedImage(mockImage, TEST_DATA_DISPLAY_SIZE) cache.pixelsCache.get(TEST_DATA_CONDITION) cache.release() diff --git a/detection/src/test/java/com/buzbuz/smartautoclicker/detection/ConditionDetectorTests.kt b/detection/src/test/java/com/buzbuz/smartautoclicker/detection/ConditionDetectorTests.kt index cea08fba0..7287ef2c0 100644 --- a/detection/src/test/java/com/buzbuz/smartautoclicker/detection/ConditionDetectorTests.kt +++ b/detection/src/test/java/com/buzbuz/smartautoclicker/detection/ConditionDetectorTests.kt @@ -78,7 +78,6 @@ class ConditionDetectorTests { private lateinit var spiedCache: Cache @Mock private lateinit var mockPixelCache: LruCache?> - @Mock private lateinit var mockCurrentImage: Image @Mock private lateinit var mockScreenBitmap: Bitmap /** The object under test. */ @@ -114,7 +113,6 @@ class ConditionDetectorTests { // Setup cache mocks spiedCache = spy(Cache() { _, _, _ -> null }) doReturn(mockPixelCache).`when`(spiedCache).pixelsCache - doReturn(mockCurrentImage).`when`(spiedCache).currentImage doReturn(mockScreenBitmap).`when`(spiedCache).screenBitmap doReturn(ProcessingData.SCREEN_AREA).`when`(spiedCache).displaySize