Skip to content

Commit

Permalink
Fix RU locale
Browse files Browse the repository at this point in the history
  • Loading branch information
sdsantos committed Nov 6, 2023
1 parent 033016d commit 74c4c1e
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 36 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
}

group = "io.bloco"
version = "2.0.2"
version = "2.0.3"

java {
withSourcesJar()
Expand Down
4 changes: 3 additions & 1 deletion src/main/kotlin/io/bloco/faker/FakerComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ abstract class FakerComponent(private val data: FakerData) {
private fun callMethod(methodKey: String): String {
val methodKeyCamel: String = methodKey.snakeToCamel()
return try {
javaClass.getDeclaredMethod(methodKeyCamel).invoke(this) as String
javaClass.getDeclaredMethod(methodKeyCamel)
.also { it.isAccessible = true }
.invoke(this) as String
} catch (e: NoSuchMethodException) {
throw IllegalArgumentException("Unsupported method '$methodKey' for component '$key'", e)
} catch (e: IllegalAccessException) {
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/io/bloco/faker/components/Address.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class Address(data: FakerData) : FakerComponent(data) {
return parse(fetch("address.city"))
}

private fun cityName(): String {
return parse("address.city_name")
}

fun streetName(): String {
return parse(fetch("address.street_name"))
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/kotlin/io/bloco/faker/components/Company.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class Company(data: FakerData) : FakerComponent(data) {
return parse(fetch("company.name"))
}

private fun prefix(): String {
return fetch("company.prefix")
}

fun suffix(): String {
return fetch("company.suffix")
}
Expand Down
59 changes: 25 additions & 34 deletions src/main/kotlin/io/bloco/faker/components/Name.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,31 @@ import io.bloco.faker.FakerComponent
import io.bloco.faker.FakerData

class Name(data: FakerData) : FakerComponent(data) {
fun firstName(): String {
return fetch("name.first_name")
}

fun lastName(): String {
return fetch("name.last_name")
}

fun prefix(): String {
return fetch("name.prefix")
}

fun suffix(): String {
return fetch("name.suffix")
}

fun title(): String {
return (
fetch("name.title.descriptor") +
" " + fetch("name.title.level") +
" " + fetch("name.title.job")
)
}

fun name(): String {
return parse(fetch("name.name"))
}

fun nameWithMiddle(): String {
return parse(fetch("name.name_with_middle"))
}

fun firstName(): String = fetch("name.first_name")

fun lastName(): String = fetch("name.last_name")

private fun maleFirstName(): String = fetch("name.male_first_name")
private fun femaleFirstName(): String = fetch("name.female_first_name")
private fun maleMiddleName(): String = fetch("name.male_middle_name")
private fun femaleMiddleName(): String = fetch("name.female_middle_name")
private fun maleLastName(): String = fetch("name.male_last_name")
private fun femaleLastName(): String = fetch("name.female_last_name")

fun prefix(): String = fetch("name.prefix")

fun suffix(): String = fetch("name.suffix")

fun title(): String =
fetch("name.title.descriptor") +
" " + fetch("name.title.level") +
" " + fetch("name.title.job")

fun name(): String = parse(fetch("name.name"))

fun nameWithMiddle(): String = parse(fetch("name.name_with_middle"))

@Suppress("UNCHECKED_CAST")
fun jobTitles(): List<String> {
return getMap("name", "title")["job"] as List<String>
}
fun jobTitles(): List<String> = getMap("name", "title")["job"] as List<String>
}
10 changes: 10 additions & 0 deletions src/test/kotlin/io/bloco/faker/components/AddressTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@ class AddressTest {
assertNotNull(faker.address.city())
}

@Test
fun city_pt() {
assertNotNull(Faker("pt").address.city())
}

@Test
fun city_ru() {
assertNotNull(Faker("ru").address.city())
}

@Test
fun streetName() {
assertNotNull(faker.address.streetName())
Expand Down
8 changes: 8 additions & 0 deletions src/test/kotlin/io/bloco/faker/components/CompanyTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package io.bloco.faker.components

import io.bloco.faker.Faker
import junit.framework.TestCase
import junit.framework.TestCase.assertFalse
import junit.framework.TestCase.assertNotNull
import org.junit.Test

Expand All @@ -13,6 +14,13 @@ class CompanyTest {
assertNotNull(faker.company.name())
}

@Test
fun name_ru() {
val name = Faker("ru").company.name()
assertNotNull(name)
assertFalse(name.contains("#"))
}

@Test
fun suffix() {
assertNotNull(faker.company.suffix())
Expand Down
8 changes: 8 additions & 0 deletions src/test/kotlin/io/bloco/faker/components/NameTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.bloco.faker.components

import io.bloco.faker.Faker
import junit.framework.TestCase.assertFalse
import junit.framework.TestCase.assertNotNull
import junit.framework.TestCase.assertTrue
import org.junit.Test
Expand Down Expand Up @@ -38,6 +39,13 @@ class NameTest {
assertNotNull(faker.name.name())
}

@Test
fun name_ru() {
val name = Faker("ru").name.name()
assertNotNull(name)
assertFalse(name.contains("#"))
}

@Test
fun nameWithMiddle() {
assertNotNull(faker.name.nameWithMiddle())
Expand Down

0 comments on commit 74c4c1e

Please sign in to comment.