|
| 1 | +/* |
| 2 | + * Copyright (c) 2025 Alexander Farber |
| 3 | + * SPDX-License-Identifier: MIT |
| 4 | + * |
| 5 | + * This file is part of the OpenMapView project (https://github.com/afarber/OpenMapView) |
| 6 | + */ |
| 7 | + |
| 8 | +package de.afarber.openmapview |
| 9 | + |
| 10 | +import org.junit.Assert.assertFalse |
| 11 | +import org.junit.Assert.assertNotSame |
| 12 | +import org.junit.Assert.assertSame |
| 13 | +import org.junit.Test |
| 14 | +import org.junit.runner.RunWith |
| 15 | +import org.robolectric.RobolectricTestRunner |
| 16 | + |
| 17 | +@RunWith(RobolectricTestRunner::class) |
| 18 | +class MarkerIconFactoryTest { |
| 19 | + @Test |
| 20 | + fun getDefaultIcon_SameHue_ReturnsCachedBitmap() { |
| 21 | + MarkerIconFactory.clearCache() |
| 22 | + |
| 23 | + val icon1 = MarkerIconFactory.getDefaultIcon(0f) |
| 24 | + val icon2 = MarkerIconFactory.getDefaultIcon(0f) |
| 25 | + |
| 26 | + assertSame(icon1, icon2) |
| 27 | + assertFalse(icon1.isRecycled) |
| 28 | + } |
| 29 | + |
| 30 | + @Test |
| 31 | + fun clearCache_DoesNotRecycleBitmapInUse() { |
| 32 | + MarkerIconFactory.clearCache() |
| 33 | + |
| 34 | + val icon = MarkerIconFactory.getDefaultIcon(120f) |
| 35 | + MarkerIconFactory.clearCache() |
| 36 | + |
| 37 | + assertFalse(icon.isRecycled) |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + fun getDefaultIcon_AfterClearCache_ReturnsFreshBitmap() { |
| 42 | + MarkerIconFactory.clearCache() |
| 43 | + |
| 44 | + val first = MarkerIconFactory.getDefaultIcon(240f) |
| 45 | + MarkerIconFactory.clearCache() |
| 46 | + val second = MarkerIconFactory.getDefaultIcon(240f) |
| 47 | + |
| 48 | + assertNotSame(first, second) |
| 49 | + assertFalse(second.isRecycled) |
| 50 | + } |
| 51 | +} |
0 commit comments