Repository: serpro69/kotlin-faker (kotlin)

Issue:
Rename functions that generate random strings
Should not have different names for functions that essentially do the same thing, so `RandomService#nextString` and `RandomService#randomAlphanumeric` should both be renamed to `randomString`

- [x] `nextString` will need to be handled gradually, first by adding a deprecation warning and then removing in some future release
  - [x] deprecation warning can also include a note about coming default length change #98 
- [x] `randomAlphanumeric`, which was added in #92, can be simply renamed since it hasn't gotten out of a `1.9.0-SNAPSHOT` yet

Pull request description:
Closes #100

Patch:
diff --git a/core/src/integration/kotlin/io/github/serpro69/kfaker/docs/Extras.kt b/core/src/integration/kotlin/io/github/serpro69/kfaker/docs/Extras.kt
index 690b0a84e5..719403f03a 100644
--- a/core/src/integration/kotlin/io/github/serpro69/kfaker/docs/Extras.kt
+++ b/core/src/integration/kotlin/io/github/serpro69/kfaker/docs/Extras.kt
@@ -116,8 +116,8 @@ class Extras : DescribeSpec({
 
         it("should generate random string of English chars") {
             // START extras_random_everything_four
-            faker.random.randomAlphanumeric(
-                length = 10,
+            faker.random.randomString(
+                length = 42,
                 numericalChars = false
             )
             // END extras_random_everything_four
@@ -125,8 +125,8 @@ class Extras : DescribeSpec({
 
         it("should generate random string in a given locale") {
             // START extras_random_everything_five
-            faker.random.nextString(
-                length = 21,
+            faker.random.randomString(
+                length = 24,
                 locale = Locale.forLanguageTag("nb-NO"),
                 auxiliaryChars = true,
                 numericalChars = true
diff --git a/core/src/integration/kotlin/io/github/serpro69/kfaker/docs/Homepage.kt b/core/src/integration/kotlin/io/github/serpro69/kfaker/docs/Homepage.kt
index 9288974d36..ec2e07b846 100644
--- a/core/src/integration/kotlin/io/github/serpro69/kfaker/docs/Homepage.kt
+++ b/core/src/integration/kotlin/io/github/serpro69/kfaker/docs/Homepage.kt
@@ -147,7 +147,7 @@ class Homepage : DescribeSpec({
                 // START random_service_one
                 faker.random.nextInt(intRange = 0..1000)
                 faker.random.nextLong(bound = 999L)
-                faker.random.nextString(length = 99)
+                faker.random.randomString(length = 99)
                 faker.random.nextEnum<TestEnum>()
                 faker.random.nextEnum(TestEnum::class.java) {
                     it != TestEnum.SOME // Exclude 'SOME' enum
diff --git a/core/src/main/kotlin/io/github/serpro69/kfaker/RandomService.kt b/core/src/main/kotlin/io/github/serpro69/kfaker/RandomService.kt
index 91ff397db2..3ef01cf728 100644
--- a/core/src/main/kotlin/io/github/serpro69/kfaker/RandomService.kt
+++ b/core/src/main/kotlin/io/github/serpro69/kfaker/RandomService.kt
@@ -55,12 +55,12 @@ class RandomService internal constructor(private val config: FakerConfig) {
     fun nextInt(min: Int, max: Int) = random.nextInt(max - min + 1) + min
 
     /**
-     * Returns the a pseudo-randomly selected value from the [list] of values.
+     * Returns a pseudo-randomly selected value from the [list] of values.
      */
     fun <T> randomValue(list: List<T>) = list[nextInt(list.size)]
 
     /**
-     * Returns the a pseudo-randomly selected value from the [array] of values.
+     * Returns a pseudo-randomly selected value from the [array] of values.
      */
     fun <T> randomValue(array: Array<T>) = array[nextInt(array.size)]
 
@@ -80,10 +80,12 @@ class RandomService internal constructor(private val config: FakerConfig) {
      * English alphabet letters and optional [numericalChars],
      * or an empty string for a `length < 1`.
      *
-     * @param length the length of the resulting string
-     * @param numericalChars add additional numerical chars from 0 to 9 to the resulting string
+     * @param length         the length of the resulting string.
+     *                       Default: `24`
+     * @param numericalChars add additional numerical chars from 0 to 9 to the resulting string.
+     *                       Default: `true`
      */
-    fun randomAlphanumeric(length: Int = 10, numericalChars: Boolean = true): String {
+    fun randomString(length: Int = 24, numericalChars: Boolean = true): String {
         if (length < 1) return ""
         val charset = if (numericalChars) {
             alphabeticLowerCharset + alphabeticUpperCharset + numericCharset
@@ -148,23 +150,51 @@ class RandomService internal constructor(private val config: FakerConfig) {
      * consisting of pseudo-randomly generated characters
      * in a given [locale] with optional [auxiliaryChars] and [numericalChars]
      *
-     * This function is intended to be used when [randomAlphanumeric] is not sufficient,
-     * i.e. when a non-English [locale] or additional chars are needed in the resulting string.
-     *
      * @param length the length of the resulting string
      * @param locale locale to use to generate the charset. Defaults to `locale` config value set for the `faker` instance
      * @param auxiliaryChars add additional auxiliary chars to the resulting string as defined in [Character_Elements](https://www.unicode.org/reports/tr35/tr35-general.html#Character_Elements)
      * @param numericalChars add additional numerical chars from 0 to 9 to the resulting string
      */
-    @JvmOverloads
+    @Deprecated(
+        message = "This function is deprecated and will be removed in future releases.\n" +
+            "Note that default value for 'length' param has changed from '100' to '24' in the new 'randomString' function.",
+        replaceWith = ReplaceWith("randomString"),
+        level = DeprecationLevel.WARNING
+    )
     fun nextString(
         length: Int = 100,
         locale: Locale = Locale.forLanguageTag(config.locale),
         auxiliaryChars: Boolean = false,
         numericalChars: Boolean = false
+    ): String = randomString(length, locale, auxiliaryChars, numericalChars)
+
+    /**
+     * Returns [String] with the specified [length] (or an empty string for a `length < 1`)
+     * consisting of pseudo-randomly generated characters
+     * in a given [locale] with optional [auxiliaryChars] and [numericalChars]
+     *
+     * @param length         the length of the resulting string.
+     *                       Default: `24`
+     * @param locale         locale to use to generate the charset.
+     *                       Defaults to `locale` config value set for the `faker` instance.
+     * @param auxiliaryChars add additional auxiliary chars to the resulting string as defined in
+     *                       [Character_Elements](https://www.unicode.org/reports/tr35/tr35-general.html#Character_Elements).
+     *                       Default: `false`
+     * @param numericalChars add additional numerical chars from 0 to 9 to the resulting string
+     *                       Default: `false`
+     */
+    @JvmOverloads
+    fun randomString(
+        length: Int = 24,
+        locale: Locale = Locale.forLanguageTag(config.locale),
+        auxiliaryChars: Boolean = false,
+        numericalChars: Boolean = false
     ): String {
         if (length < 1) return "" // base case
-        if (locale in listOf(Locale.ENGLISH, Locale.US, Locale.UK, Locale.CANADA)) return randomAlphanumeric(length, numericalChars)
+        if (locale in listOf(Locale.ENGLISH, Locale.US, Locale.UK, Locale.CANADA)) return randomString(
+            length,
+            numericalChars
+        )
 
         val localeData = LocaleData.getInstance(ULocale.forLocale(locale))
         val mainChars = localeData.getExemplarSet(UnicodeSet.MIN_VALUE, LocaleData.ES_STANDARD)
diff --git a/core/src/main/kotlin/io/github/serpro69/kfaker/provider/RandomProvider.kt b/core/src/main/kotlin/io/github/serpro69/kfaker/provider/RandomProvider.kt
index 1e238989ca..32fbdefa1a 100644
--- a/core/src/main/kotlin/io/github/serpro69/kfaker/provider/RandomProvider.kt
+++ b/core/src/main/kotlin/io/github/serpro69/kfaker/provider/RandomProvider.kt
@@ -2,7 +2,6 @@ package io.github.serpro69.kfaker.provider
 
 import io.github.serpro69.kfaker.FakerConfig
 import io.github.serpro69.kfaker.RandomService
-import java.util.*
 import kotlin.Boolean
 import kotlin.Char
 import kotlin.Double
@@ -110,7 +109,7 @@ class RandomProvider internal constructor(fakerConfig: FakerConfig) {
         Int::class -> randomService.nextInt()
         Short::class -> randomService.nextInt().toShort()
         Byte::class -> randomService.nextInt().toByte()
-        String::class -> randomService.nextString()
+        String::class -> randomService.randomString()
         Char::class -> randomService.nextChar()
         Boolean::class -> randomService.nextBoolean()
         // TODO: 16.06.19 Arrays


Test patch:
diff --git a/core/src/test/kotlin/io/github/serpro69/kfaker/RandomServiceTest.kt b/core/src/test/kotlin/io/github/serpro69/kfaker/RandomServiceTest.kt
index 635f0f2b12..284634f608 100644
--- a/core/src/test/kotlin/io/github/serpro69/kfaker/RandomServiceTest.kt
+++ b/core/src/test/kotlin/io/github/serpro69/kfaker/RandomServiceTest.kt
@@ -136,9 +136,9 @@ internal class RandomServiceTest : DescribeSpec({
             }
         }
 
-        context("nextString() fun") {
-            it("default generated string is 100 char length") {
-                randomService.nextString().length shouldBe 100
+        context("randomString() fun") {
+            it("default generated string is 24 char length") {
+                randomService.randomString().length shouldBe 24
             }
         }
 
@@ -191,15 +191,15 @@ internal class RandomServiceTest : DescribeSpec({
         context("randomAlphanumeric() fun") {
             it("generates a string from the alphaNumeric source") {
                 val sourceGenerated = ('A'..'Z') + ('a'..'z') + ('0'..'9')
-                val listAlphanumeric = List(100) { randomService.randomAlphanumeric(100) }
+                val listAlphanumeric = List(100) { randomService.randomString(100) }
                 listAlphanumeric.forEach {
                     sourceGenerated shouldContainAll it.map { c -> c }
                 }
             }
 
             it("consecutive runs return different values") {
-                val one = randomService.randomAlphanumeric()
-                val two = randomService.randomAlphanumeric()
+                val one = randomService.randomString()
+                val two = randomService.randomString()
                 one shouldNotBe two
             }
 
@@ -208,21 +208,21 @@ internal class RandomServiceTest : DescribeSpec({
                 val c2 = fakerConfig { random = Random(42) }
                 val r1 = RandomService(c1)
                 val r2 = RandomService(c2)
-                r1.randomAlphanumeric() shouldBe r2.randomAlphanumeric()
+                r1.randomString() shouldBe r2.randomString()
             }
 
-            it("default generated string is 10 char length") {
-                val defaultLength = 10
-                randomService.randomAlphanumeric().length shouldBe defaultLength
+            it("default generated string is 24 char length") {
+                val defaultLength = 24
+                randomService.randomString().length shouldBe defaultLength
             }
 
             it("should return a specific length of the string") {
                 val expectedLength = 100
-                randomService.randomAlphanumeric(expectedLength).length shouldBe expectedLength
+                randomService.randomString(expectedLength).length shouldBe expectedLength
             }
 
             it("returns an empty string when length is 0") {
-                randomService.randomAlphanumeric(0) shouldBe ""
+                randomService.randomString(0) shouldBe ""
             }
         }