Skip to content

Commit f128baa

Browse files
committed
Spotless fix
1 parent a19bc9e commit f128baa

File tree

9 files changed

+306
-23
lines changed

9 files changed

+306
-23
lines changed

CLAUDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This is a Kotlin Multiplatform (KMP) library that provides unified barcode scann
1717
- For the naming of test class use suffix `Test` of the original class
1818
- If the same class name exists in common module and in platform specific like android for example, you can add platform name as suffix as well but before the word `Test`
1919
- Test coverage is ony important for the `scan-engine/` module and run tests only for this module
20-
- Classes with functions annotated as @Composable they need to be tested via android (instrumented) tests and not unit tests
20+
- Classes with functions annotated as @Composable they need to be tested via android instrumented tests and not unit tests
2121
- Activities or Fragment classes cover with android (instrumented) tests, not unit tests
2222
- Make sure at the end after you run all tests you cleanup test class for any unused variables, imports or components
2323
- `./gradlew :scan-engine:allTests` - Run tests for all platforms (Android, iOS) and create aggregated report

scan-engine/src/androidInstrumentedTest/kotlin/de/tillhub/scanengine/camera/contract/CameraScanContractTest.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ class CameraScanContractTest {
9191
fun testCameraScanContractWithStateChanges() {
9292
var latestEvent: ScannerEvent? = null
9393
var eventCount = 0
94-
94+
9595
val onResult: (ScannerEvent) -> Unit = { event ->
9696
latestEvent = event
9797
eventCount++
@@ -112,7 +112,7 @@ class CameraScanContractTest {
112112

113113
// Manually trigger launch to test functionality
114114
contract.launchCameraScanner("manual_test")
115-
115+
116116
// Wait for composition updates
117117
composeTestRule.waitForIdle()
118118

@@ -125,14 +125,14 @@ class CameraScanContractTest {
125125
@Test
126126
fun testCameraScanContractRecomposition() {
127127
var recompositionCount = 0
128-
128+
129129
val onResult: (ScannerEvent) -> Unit = { }
130130

131131
composeTestRule.setContent {
132132
recompositionCount++
133-
133+
134134
val contract = rememberCameraScanLauncher(onResult = onResult)
135-
135+
136136
// Contract should be remembered across recompositions
137137
assertNotNull(contract)
138138
}
@@ -176,10 +176,10 @@ class CameraScanContractTest {
176176
// Verify all launches triggered InProgress events
177177
val inProgressEvents = events.filterIsInstance<ScannerEvent.Camera.InProgress>()
178178
assertEquals(3, inProgressEvents.size)
179-
179+
180180
// Verify the scan keys are correct
181181
assertEquals("first_launch", inProgressEvents[0].scanKey)
182182
assertEquals("second_launch", inProgressEvents[1].scanKey)
183183
assertEquals(null, inProgressEvents[2].scanKey)
184184
}
185-
}
185+
}

scan-engine/src/androidInstrumentedTest/kotlin/de/tillhub/scanengine/camera/ui/CameraPreviewTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class CameraPreviewTest {
4545
.fillMaxSize()
4646
.testTag("camera_preview"),
4747
barcodeScanned = barcodeCallback,
48-
onCameraError = errorCallback
48+
onCameraError = errorCallback,
4949
)
5050
}
5151

@@ -73,7 +73,7 @@ class CameraPreviewTest {
7373
cameraPreview(
7474
modifier = Modifier.testTag("camera_preview_callbacks"),
7575
barcodeScanned = barcodeCallback,
76-
onCameraError = errorCallback
76+
onCameraError = errorCallback,
7777
)
7878
}
7979

@@ -92,7 +92,7 @@ class CameraPreviewTest {
9292
.fillMaxSize()
9393
.testTag("camera_preview_modified"),
9494
barcodeScanned = { },
95-
onCameraError = { }
95+
onCameraError = { },
9696
)
9797
}
9898

@@ -119,7 +119,7 @@ class CameraPreviewTest {
119119
},
120120
onCameraError = { error ->
121121
errorState.value = error
122-
}
122+
},
123123
)
124124
}
125125

@@ -141,7 +141,7 @@ class CameraPreviewTest {
141141
cameraPreview(
142142
modifier = Modifier.testTag("camera_preview_recomposition"),
143143
barcodeScanned = { },
144-
onCameraError = { }
144+
onCameraError = { },
145145
)
146146
}
147147

@@ -155,4 +155,4 @@ class CameraPreviewTest {
155155
// Verify composable still exists after potential recomposition
156156
composeTestRule.onNodeWithTag("camera_preview_recomposition").assertExists()
157157
}
158-
}
158+
}

scan-engine/src/androidInstrumentedTest/kotlin/de/tillhub/scanengine/camera/ui/CameraScanActivityTest.kt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,17 @@ class CameraScanActivityTest {
2323
fun testActivityLaunch() {
2424
val context = InstrumentationRegistry.getInstrumentation().targetContext
2525
val intent = Intent(context, CameraScanActivity::class.java)
26-
26+
2727
ActivityScenario.launch<CameraScanActivity>(intent).use { scenario ->
2828
scenario.onActivity { activity ->
2929
assertNotNull(activity)
30-
30+
3131
// Test basic activity functionality
3232
val testBarcode = "test_barcode_123"
3333
val resultIntent = Intent().apply {
3434
putExtra(CameraScanActivity.DATA_KEY, testBarcode)
3535
}
36-
36+
3737
// Verify we can set result and finish activity
3838
activity.setResult(Activity.RESULT_OK, resultIntent)
3939
activity.finish()
@@ -45,15 +45,15 @@ class CameraScanActivityTest {
4545
fun testActivityCancellation() {
4646
val context = InstrumentationRegistry.getInstrumentation().targetContext
4747
val intent = Intent(context, CameraScanActivity::class.java)
48-
48+
4949
ActivityScenario.launch<CameraScanActivity>(intent).use { scenario ->
5050
scenario.onActivity { activity ->
5151
assertNotNull(activity)
52-
52+
5353
// Test cancellation scenario
5454
activity.setResult(Activity.RESULT_CANCELED)
5555
activity.finish()
5656
}
5757
}
5858
}
59-
}
59+
}

scan-engine/src/androidUnitTest/kotlin/de/tillhub/scanengine/camera/AndroidPermissionHandlerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,4 @@ internal class AndroidPermissionHandlerTest {
4747

4848
assertFalse(result)
4949
}
50-
}
50+
}

scan-engine/src/androidUnitTest/kotlin/de/tillhub/scanengine/camera/CameraHandlerTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ internal class CameraHandlerTest {
2727
// without calling getCameraProvider which requires CameraX setup
2828
assertNotNull(target)
2929
}
30-
}
30+
}

scan-engine/src/androidUnitTest/kotlin/de/tillhub/scanengine/camera/InputImageGeneratorTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ internal class InputImageGeneratorTest {
2020
// Simple test to ensure the InputImageGenerator can be created
2121
assertNotNull(target)
2222
}
23-
}
23+
}
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
package de.tillhub.scanengine.camera
2+
3+
import androidx.compose.ui.test.ExperimentalTestApi
4+
import androidx.compose.ui.test.runComposeUiTest
5+
import kotlinx.cinterop.ExperimentalForeignApi
6+
import kotlin.test.Test
7+
import kotlin.test.assertNotNull
8+
9+
@OptIn(ExperimentalTestApi::class, ExperimentalForeignApi::class)
10+
internal class IosPermissionHandlerTest {
11+
12+
@Test
13+
fun testIosPermissionHandlerInstantiation() {
14+
val handler = IosPermissionHandler()
15+
assertNotNull(handler)
16+
}
17+
18+
@Test
19+
fun testHasCameraPermissionMethod() {
20+
val handler = IosPermissionHandler()
21+
22+
// This will check the actual iOS permission status
23+
// The result depends on the system state, but it should not crash
24+
val result = handler.hasCameraPermission()
25+
26+
// Just verify the method executes without error
27+
// The actual permission state is environment dependent
28+
}
29+
30+
@Test
31+
fun testRequestCameraPermissionComposable() = runComposeUiTest {
32+
var grantedCalled = false
33+
var deniedCalled = false
34+
35+
val onGranted = { grantedCalled = true }
36+
val onDenied = { deniedCalled = true }
37+
38+
val handler = IosPermissionHandler()
39+
40+
setContent {
41+
handler.requestCameraPermission(
42+
onGranted = onGranted,
43+
onDenied = onDenied,
44+
)
45+
}
46+
47+
// Wait for composition
48+
waitForIdle()
49+
50+
// The actual permission request behavior depends on the system state
51+
// This test verifies that the composable can be called without crashing
52+
}
53+
54+
@Test
55+
fun testGetPermissionHandlerComposable() = runComposeUiTest {
56+
var handler: PermissionHandler? = null
57+
58+
setContent {
59+
handler = getPermissionHandler()
60+
}
61+
62+
waitForIdle()
63+
64+
assertNotNull(handler)
65+
// Verify it returns an IosPermissionHandler instance
66+
// We can't use instanceof in Kotlin/Native, so we verify it's not null
67+
// and that it has the expected interface
68+
val result = handler.hasCameraPermission()
69+
// Just verifying the interface works
70+
}
71+
72+
@Test
73+
fun testPermissionHandlerRecomposition() = runComposeUiTest {
74+
var recompositionCount = 0
75+
var handler1: PermissionHandler? = null
76+
var handler2: PermissionHandler? = null
77+
78+
setContent {
79+
recompositionCount++
80+
if (recompositionCount == 1) {
81+
handler1 = getPermissionHandler()
82+
} else {
83+
handler2 = getPermissionHandler()
84+
}
85+
}
86+
87+
waitForIdle()
88+
89+
// Force recomposition by updating content
90+
setContent {
91+
recompositionCount++
92+
handler2 = getPermissionHandler()
93+
}
94+
95+
waitForIdle()
96+
97+
// Both handlers should be non-null and functional
98+
assertNotNull(handler1)
99+
assertNotNull(handler2)
100+
}
101+
}

0 commit comments

Comments
 (0)