-
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.
Merge pull request #310 from LookUpGroup27/fix/improve-code-coverage
test: improve general code coverage
- Loading branch information
Showing
7 changed files
with
289 additions
and
18 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
app/src/androidTest/java/com/github/lookupgroup27/lookup/ui/overview/SampleScreenTest.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,55 @@ | ||
package com.github.lookupgroup27.lookup.ui.overview | ||
|
||
import androidx.compose.ui.test.* | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import com.github.lookupgroup27.lookup.ui.navigation.NavigationActions | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.mockito.kotlin.mock | ||
|
||
class SampleScreenTest { | ||
|
||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
private val mockNavigationActions: NavigationActions = mock() | ||
|
||
@Test | ||
fun sampleScreen_displaysCorrectText() { | ||
// Set up test input | ||
val testText = "Sample Screen Text" | ||
val screenTag = "sampleScreenTag" | ||
val backButtonTag = "backButtonTag" | ||
|
||
// Render the composable | ||
composeTestRule.setContent { | ||
SampleScreen( | ||
screenText = testText, | ||
navigationActions = mockNavigationActions, | ||
screenTag = screenTag, | ||
backButtonTag = backButtonTag) | ||
} | ||
|
||
// Verify the screen text is displayed | ||
composeTestRule.onNodeWithText(testText).assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun sampleScreen_hasCorrectTestTags() { | ||
// Set up test input | ||
val screenTag = "sampleScreenTag" | ||
val backButtonTag = "backButtonTag" | ||
|
||
// Render the composable | ||
composeTestRule.setContent { | ||
SampleScreen( | ||
screenText = "Sample Screen Text", | ||
navigationActions = mockNavigationActions, | ||
screenTag = screenTag, | ||
backButtonTag = backButtonTag) | ||
} | ||
|
||
// Verify the test tags are present | ||
composeTestRule.onNodeWithTag(screenTag).assertIsDisplayed() | ||
composeTestRule.onNodeWithTag(backButtonTag).assertIsDisplayed() | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...src/androidTest/java/com/github/lookupgroup27/lookup/ui/profile/ChangeAvatarButtonTest.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,60 @@ | ||
package com.github.lookupgroup27.lookup.ui.profile | ||
|
||
import androidx.compose.ui.test.assertIsDisplayed | ||
import androidx.compose.ui.test.junit4.createComposeRule | ||
import androidx.compose.ui.test.onNodeWithText | ||
import androidx.compose.ui.test.performClick | ||
import com.github.lookupgroup27.lookup.R | ||
import com.github.lookupgroup27.lookup.ui.profile.components.ChangeAvatarButton | ||
import org.junit.Rule | ||
import org.junit.Test | ||
|
||
class ChangeAvatarButtonTest { | ||
|
||
@get:Rule val composeTestRule = createComposeRule() | ||
|
||
@Test | ||
fun changeAvatarButton_isDisplayed_whenAvatarIsNotDefaultOrNull() { | ||
// Set up the test | ||
composeTestRule.setContent { | ||
ChangeAvatarButton( | ||
selectedAvatar = R.drawable.avatar1, isAvatarDefaultOrNull = false, onButtonClick = {}) | ||
} | ||
|
||
// Verify the button is displayed | ||
composeTestRule.onNodeWithText("Change Avatar").assertIsDisplayed() | ||
} | ||
|
||
@Test | ||
fun changeAvatarButton_isNotDisplayed_whenAvatarIsDefaultOrNull() { | ||
// Set up the test | ||
composeTestRule.setContent { | ||
ChangeAvatarButton( | ||
selectedAvatar = R.drawable.default_profile_icon, | ||
isAvatarDefaultOrNull = true, | ||
onButtonClick = {}) | ||
} | ||
|
||
// Verify the button does not exist | ||
composeTestRule.onNodeWithText("Change Avatar").assertDoesNotExist() | ||
} | ||
|
||
@Test | ||
fun changeAvatarButton_triggersOnClick_whenClicked() { | ||
var isClicked = false | ||
|
||
// Set up the test | ||
composeTestRule.setContent { | ||
ChangeAvatarButton( | ||
selectedAvatar = R.drawable.avatar1, | ||
isAvatarDefaultOrNull = false, | ||
onButtonClick = { isClicked = true }) | ||
} | ||
|
||
// Perform a click on the button | ||
composeTestRule.onNodeWithText("Change Avatar").performClick() | ||
|
||
// Verify the callback was invoked | ||
assert(isClicked) | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
app/src/test/java/com/github/lookupgroup27/lookup/model/map/CameraTest.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,22 @@ | ||
package com.github.lookupgroup27.lookup.model.map | ||
|
||
import android.hardware.Sensor | ||
import android.hardware.SensorManager | ||
import org.junit.Test | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.times | ||
import org.mockito.Mockito.verify | ||
|
||
class CameraTest { | ||
|
||
@Test | ||
fun testOnAccuracyChanged() { | ||
val sensor = mock(Sensor::class.java) | ||
val camera = Camera(90f) | ||
|
||
camera.onAccuracyChanged(sensor, SensorManager.SENSOR_STATUS_ACCURACY_HIGH) | ||
|
||
// Since the method does nothing, we just verify that it can be called without exceptions | ||
verify(sensor, times(0)).type // This is just to use the sensor mock | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
.../test/java/com/github/lookupgroup27/lookup/model/map/renderables/utils/BufferUtilsTest.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,28 @@ | ||
package com.github.lookupgroup27.lookup.model.map.renderables.utils | ||
|
||
import com.github.lookupgroup27.lookup.util.opengl.BufferUtils.toBuffer | ||
import java.nio.ShortBuffer | ||
import org.junit.Assert.assertArrayEquals | ||
import org.junit.Test | ||
|
||
class BufferUtilsTest { | ||
|
||
@Test | ||
fun testShortArrayToBuffer() { | ||
// Input short array | ||
val inputArray = shortArrayOf(1, 2, 3, 4, 5) | ||
|
||
// Convert the array to a ShortBuffer | ||
val buffer: ShortBuffer = inputArray.toBuffer() | ||
|
||
// Verify the buffer's capacity | ||
assert(buffer.capacity() == inputArray.size) | ||
|
||
// Create an output array and read the buffer's contents into it | ||
val outputArray = ShortArray(inputArray.size) | ||
buffer.get(outputArray) | ||
|
||
// Verify the output array matches the input array | ||
assertArrayEquals(inputArray, outputArray) | ||
} | ||
} |
78 changes: 78 additions & 0 deletions
78
...est/java/com/github/lookupgroup27/lookup/model/map/renderables/utils/GeometryUtilsTest.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,78 @@ | ||
package com.github.lookupgroup27.lookup.model.map.renderables.utils | ||
|
||
import org.junit.Assert.assertArrayEquals | ||
import org.junit.Assert.assertEquals | ||
import org.junit.Test | ||
|
||
class GeometryUtilsTest { | ||
|
||
@Test | ||
fun testGenerateCircularGeometry_vertices() { | ||
val numSegments = 4 | ||
val geometryData = GeometryUtils.generateCircularGeometry(numSegments) | ||
|
||
// Expected vertices for a 4-segment circle | ||
val expectedVertices = | ||
floatArrayOf( | ||
0f, | ||
0f, | ||
0f, // Center vertex | ||
1f, | ||
0f, | ||
0f, // First segment | ||
0f, | ||
1f, | ||
0f, // Second segment | ||
-1f, | ||
0f, | ||
0f, // Third segment | ||
0f, | ||
-1f, | ||
0f, // Fourth segment | ||
1f, | ||
0f, | ||
0f // Wrap around to the first segment | ||
) | ||
|
||
// Assert that the vertices match | ||
assertArrayEquals(expectedVertices, geometryData.vertices, 0.001f) | ||
} | ||
|
||
@Test | ||
fun testGenerateCircularGeometry_indices() { | ||
val numSegments = 4 | ||
val geometryData = GeometryUtils.generateCircularGeometry(numSegments) | ||
|
||
// Expected indices for a 4-segment circle | ||
val expectedIndices = | ||
shortArrayOf( | ||
0, | ||
1, | ||
2, // Triangle 1 | ||
0, | ||
2, | ||
3, // Triangle 2 | ||
0, | ||
3, | ||
4, // Triangle 3 | ||
0, | ||
4, | ||
1 // Triangle 4 (wrap around) | ||
) | ||
|
||
// Assert that the indices match | ||
assertArrayEquals(expectedIndices, geometryData.indices) | ||
} | ||
|
||
@Test | ||
fun testGenerateCircularGeometry_numberOfVerticesAndIndices() { | ||
val numSegments = 32 | ||
val geometryData = GeometryUtils.generateCircularGeometry(numSegments) | ||
|
||
// The number of vertices should be numSegments + 2 (center + one for wraparound) | ||
assertEquals(numSegments + 2, geometryData.vertices.size / 3) | ||
|
||
// The number of indices should be numSegments * 3 (3 indices per triangle) | ||
assertEquals(numSegments * 3, geometryData.indices.size) | ||
} | ||
} |
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) | ||
} | ||
} |