-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(star): add StarsLoaderTest test class to test StarsLoader
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
app/src/test/java/com/github/lookupgroup27/lookup/model/map/stars/StarsLoaderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.github.lookupgroup27.lookup.model.map.stars | ||
|
||
import android.content.Context | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Before | ||
import org.junit.Test | ||
import org.mockito.Mockito.* | ||
|
||
class StarsLoaderTest { | ||
|
||
private lateinit var mockContext: Context | ||
private lateinit var mockRepository: StarDataRepository | ||
private lateinit var starsLoader: StarsLoader | ||
|
||
@Before | ||
fun setUp() { | ||
mockContext = mock(Context::class.java) | ||
mockRepository = mock(StarDataRepository::class.java) | ||
starsLoader = StarsLoader(mockContext, mockRepository) | ||
} | ||
|
||
@Test | ||
fun testLoadStars_callsUpdateStarPositions() { | ||
// Arrange: Set up the mock repository | ||
`when`(mockRepository.getUpdatedStars()).thenReturn(emptyList()) | ||
|
||
// Act: Call loadStars | ||
starsLoader.loadStars() | ||
|
||
// Assert: Verify that updateStarPositions was called | ||
verify(mockRepository).updateStarPositions() | ||
} | ||
|
||
@Test | ||
fun testLoadStars_handlesEmptyStarDataList() { | ||
// Arrange: Return an empty star data list | ||
`when`(mockRepository.getUpdatedStars()).thenReturn(emptyList()) | ||
|
||
// Act: Call loadStars | ||
val stars = starsLoader.loadStars() | ||
|
||
// Assert: Verify the result is an empty list | ||
assertEquals(0, stars.size) | ||
} | ||
} |