Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nain57 committed Dec 25, 2021
1 parent 6ec8693 commit 24e8aa1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ class ConditionDetectorTests {

private lateinit var spiedCache: Cache
@Mock private lateinit var mockPixelCache: LruCache<Condition, Pair<IntArray, IntArray>?>
@Mock private lateinit var mockCurrentImage: Image
@Mock private lateinit var mockScreenBitmap: Bitmap

/** The object under test. */
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit 24e8aa1

Please sign in to comment.