Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(android): uppercase conversion in getEnumName() method #3311

Merged
merged 4 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,15 @@ dependencies {
implementation "com.squareup.okhttp3:okhttp:4.9.0"
implementation "com.squareup.okhttp3:okhttp-urlconnection:4.9.0"
}

testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.8.2'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
testImplementation 'org.jetbrains.kotlin:kotlin-test'
testImplementation "org.mockito.kotlin:mockito-kotlin:5.2.1"
}


tasks.withType(Test).configureEach {
useJUnitPlatform()
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class RNMBXStyleValue(config: ReadableMap) {
}

fun getEnumName(): String {
return mPayload!!.getString("value")!!.toUpperCase().replace("-", "_")
return mPayload!!.getString("value")!!.uppercase().replace("-", "_")
}

fun getDouble(key: String?): Double {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import com.facebook.react.bridge.Dynamic
import com.facebook.react.bridge.ReadableMap
import com.rnmapbox.rnmbx.components.styles.RNMBXStyleValue
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.*
import org.mockito.Mockito
import java.util.Locale

class RNMBXStyleValueTest {

private lateinit var mockConfig: ReadableMap
private lateinit var mockPayload: ReadableMap
private lateinit var mockDynamic: Dynamic

@BeforeEach
fun setup() {
mockConfig = Mockito.mock(ReadableMap::class.java)
mockPayload = Mockito.mock(ReadableMap::class.java)
mockDynamic = Mockito.mock(Dynamic::class.java)

Mockito.`when`(mockConfig.getMap("stylevalue")).thenReturn(mockPayload)
Mockito.`when`(mockPayload.getDynamic("value")).thenReturn(mockDynamic)
}

@Test
fun `getEnumName returns correct enum name`() {
Mockito.`when`(mockPayload.getString("value")).thenReturn("test-value")

val styleValue = RNMBXStyleValue(mockConfig)

assertEquals("TEST_VALUE", styleValue.getEnumName())
}

@Test
fun `getEnumName handles Turkish locale correctly`() {
Mockito.`when`(mockPayload.getString("value")).thenReturn("miter")

val styleValue = RNMBXStyleValue(mockConfig)

Locale.setDefault(Locale("tr", "TR"))

assertEquals("MITER", styleValue.getEnumName())

Locale.setDefault(Locale.getDefault())
}
}
Loading