Skip to content

Commit 6447de2

Browse files
authored
Add javadoc documentation (#52)
1 parent 962080d commit 6447de2

File tree

67 files changed

+1191
-228
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1191
-228
lines changed

README.adoc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ The sequence can hang indefinitely if the applied operators prevent the generati
9292

9393
Everything can be customised, see link:fixture/configuration-options.adoc[configuration options] for more details.
9494

95+
link:fixture/advanced-customisation.adoc[Advanced engine customisation] is also possible if the above options are not enough.
96+
9597
== Kotest integration: property based testing
9698

9799
The library provides {link-appmattus} powered property based testing for https://github.com/kotest/kotest/[Kotest].
@@ -106,7 +108,7 @@ See link:fixture-javafaker/README.adoc[Java Faker integration] for more details.
106108

107109
== Generex integration: regex to random string
108110

109-
To generate a random string from a Regex, look no further than the Generex integration.
111+
To generate a random string from a regular expression, look no further than the Generex integration.
110112

111113
See link:fixture-generex/README.adoc[Generex integration] for more details.
112114

fixture-generex/src/main/kotlin/com/appmattus/kotlinfixture/config/GeneratorString.kt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,52 @@ package com.appmattus.kotlinfixture.config
1818

1919
import com.mifmif.common.regex.Generex
2020

21+
/**
22+
* # Generate a random string from a regular expression
23+
*
24+
* ```
25+
* data class DataClass(val index: String, val value: String)
26+
*
27+
* val indexRegex = "[a-z][0-9]".toRegex()
28+
* val valueRegex = "[A-Z]{3}".toRegex()
29+
*
30+
* val fixture = kotlinFixture {
31+
* factory<String> { regexToRandom(indexRegex) }
32+
*
33+
* property(DataClass::value) { regexToRandom(valueRegex) }
34+
* }
35+
*
36+
* println(fixture<DataClass>()) // DataClass(index=m3, value=CGJ)
37+
* ```
38+
*
39+
* IMPORTANT: Be careful with object creation inside the generation function as it will be called for every instance of the object you create.
40+
*/
2141
fun Generator<String>.regexToRandom(regex: String, minLength: Int = 1, maxLength: Int = Int.MAX_VALUE): String {
2242
return Generex(regex).apply {
2343
setSeed(random.nextLong())
2444
}.random(minLength, maxLength)
2545
}
2646

47+
/**
48+
* # Generate a random string from a regular expression
49+
*
50+
* ```
51+
* data class DataClass(val index: String, val value: String)
52+
*
53+
* val indexRegex = "[a-z][0-9]".toRegex()
54+
* val valueRegex = "[A-Z]{3}".toRegex()
55+
*
56+
* val fixture = kotlinFixture {
57+
* factory<String> { regexToRandom(indexRegex) }
58+
*
59+
* property(DataClass::value) { regexToRandom(valueRegex) }
60+
* }
61+
*
62+
* println(fixture<DataClass>()) // DataClass(index=m3, value=CGJ)
63+
* ```
64+
*
65+
* IMPORTANT: Be careful with object creation inside the generation function as it will be called for every instance of the object you create.
66+
*/
2767
fun Generator<String>.regexToRandom(regex: Regex, minLength: Int = 1, maxLength: Int = Int.MAX_VALUE): String {
2868
return regexToRandom(regex.pattern, minLength, maxLength)
2969
}

fixture-javafaker/src/main/kotlin/com/appmattus/kotlinfixture/decorator/fake/javafaker/JavaFakerConfiguration.kt

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,19 @@ import java.time.ZoneId
2929
import java.time.temporal.ChronoUnit
3030
import java.util.Locale
3131

32-
data class JavaFakerConfiguration(
33-
val creditCard: CreditCard = CreditCard.Any,
34-
val ipAddress: IpAddress = IpAddress.V4,
35-
val isbn10Separator: Boolean = false,
36-
val isbn13Separator: Boolean = false,
37-
val locale: Locale = Locale.ENGLISH,
38-
val password: Password = Password(),
39-
val temperature: Temperature = Temperature.Celsius,
40-
val userAgent: UserAgent = UserAgent.Any,
41-
val properties: Map<String, Faker.(JavaFakerConfiguration) -> Any?> = defaultMap
32+
/**
33+
* Configuration for the [JavaFakerStrategy]
34+
*/
35+
data class JavaFakerConfiguration internal constructor(
36+
internal val creditCard: CreditCard = CreditCard.Any,
37+
internal val ipAddress: IpAddress = IpAddress.V4,
38+
internal val isbn10Separator: Boolean = false,
39+
internal val isbn13Separator: Boolean = false,
40+
internal val locale: Locale = Locale.ENGLISH,
41+
internal val password: Password = Password(),
42+
internal val temperature: Temperature = Temperature.Celsius,
43+
internal val userAgent: UserAgent = UserAgent.Any,
44+
internal val properties: Map<String, Faker.(JavaFakerConfiguration) -> Any?> = defaultMap
4245
) {
4346
private companion object {
4447

@@ -231,6 +234,12 @@ data class JavaFakerConfiguration(
231234
}
232235
}
233236

237+
/**
238+
* # Fake object generation with `javaFakerStrategy`
239+
*
240+
* The faker intercepts the generation of named properties so their values can be replaced with fake data generated by
241+
* the [Java Faker](https://github.com/DiUS/java-faker) library
242+
*/
234243
fun ConfigurationBuilder.javaFakerStrategy(configuration: JavaFakerConfigurationBuilder.() -> Unit = {}) {
235244
fakeStrategy(
236245
(fakeStrategy as? JavaFakerStrategy)?.new(configuration) ?: JavaFakerStrategy().new(configuration)

fixture-javafaker/src/main/kotlin/com/appmattus/kotlinfixture/decorator/fake/javafaker/JavaFakerConfigurationBuilder.kt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,17 @@
1717
package com.appmattus.kotlinfixture.decorator.fake.javafaker
1818

1919
import com.appmattus.kotlinfixture.decorator.fake.javafaker.option.CreditCard
20+
import com.appmattus.kotlinfixture.decorator.fake.javafaker.option.IpAddress
2021
import com.appmattus.kotlinfixture.decorator.fake.javafaker.option.Temperature
2122
import com.appmattus.kotlinfixture.decorator.fake.javafaker.option.UserAgent
22-
import com.appmattus.kotlinfixture.decorator.fake.javafaker.option.IpAddress
2323
import com.appmattus.kotlinfixture.toUnmodifiableMap
2424
import com.github.javafaker.Faker
2525
import java.util.Locale
2626

27-
class JavaFakerConfigurationBuilder(javaFakerConfiguration: JavaFakerConfiguration) {
27+
/**
28+
* Builder of [JavaFakerConfiguration].
29+
*/
30+
class JavaFakerConfigurationBuilder internal constructor(javaFakerConfiguration: JavaFakerConfiguration) {
2831

2932
/**
3033
* Generate `creditCard` properties in the style of the selected credit card company. See [CreditCard] for options.
@@ -77,15 +80,21 @@ class JavaFakerConfigurationBuilder(javaFakerConfiguration: JavaFakerConfigurati
7780

7881
private val properties = javaFakerConfiguration.properties.toMutableMap()
7982

83+
/**
84+
* Remove the [Java Faker](https://github.com/DiUS/java-faker) generator for [propertyName].
85+
*/
8086
fun removeProperty(propertyName: String) {
8187
properties.remove(propertyName)
8288
}
8389

90+
/**
91+
* Map a [Java Faker](https://github.com/DiUS/java-faker) generator to a [propertyName].
92+
*/
8493
fun putProperty(propertyName: String, fakeGenerator: Faker.(JavaFakerConfiguration) -> Any?) {
8594
properties[propertyName] = fakeGenerator
8695
}
8796

88-
fun build() = JavaFakerConfiguration(
97+
internal fun build() = JavaFakerConfiguration(
8998
creditCard = creditCard,
9099
ipAddress = ipAddress,
91100
isbn10Separator = isbn10Separator,

fixture-javafaker/src/main/kotlin/com/appmattus/kotlinfixture/decorator/fake/javafaker/JavaFakerStrategy.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import com.appmattus.kotlinfixture.decorator.fake.FakeStrategy
2222
import com.github.javafaker.Faker
2323
import kotlin.random.asJavaRandom
2424

25-
open class JavaFakerStrategy(
25+
internal class JavaFakerStrategy(
2626
private val fakerConfiguration: JavaFakerConfiguration = JavaFakerConfigurationBuilder(
2727
JavaFakerConfiguration()
2828
).build()

fixture-javafaker/src/main/kotlin/com/appmattus/kotlinfixture/decorator/fake/javafaker/option/CreditCard.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package com.appmattus.kotlinfixture.decorator.fake.javafaker.option
1818

1919
import com.github.javafaker.CreditCardType
2020

21+
/**
22+
* Different types of [CreditCard]
23+
*/
2124
@Suppress("unused")
2225
enum class CreditCard(internal val creditCardType: CreditCardType?) {
2326
Any(null),

fixture-javafaker/src/main/kotlin/com/appmattus/kotlinfixture/decorator/fake/javafaker/option/IpAddress.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package com.appmattus.kotlinfixture.decorator.fake.javafaker.option
1818

19+
/**
20+
* Different types of [IpAddress]
21+
*/
1922
enum class IpAddress {
2023
V4,
2124
V6

fixture-javafaker/src/main/kotlin/com/appmattus/kotlinfixture/decorator/fake/javafaker/option/Password.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package com.appmattus.kotlinfixture.decorator.fake.javafaker.option
1818

19+
/**
20+
* Configuration for password generation
21+
*/
1922
data class Password(
2023
val minimumLength: Int = 8,
2124
val maximumLength: Int = 16,

fixture-javafaker/src/main/kotlin/com/appmattus/kotlinfixture/decorator/fake/javafaker/option/Temperature.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

1717
package com.appmattus.kotlinfixture.decorator.fake.javafaker.option
1818

19+
/**
20+
* Different types of [Temperature]
21+
*/
1922
enum class Temperature {
2023
Celsius,
2124
Fahrenheit

fixture-javafaker/src/main/kotlin/com/appmattus/kotlinfixture/decorator/fake/javafaker/option/UserAgent.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ package com.appmattus.kotlinfixture.decorator.fake.javafaker.option
1818

1919
import com.github.javafaker.Internet
2020

21+
/**
22+
* Different types of [UserAgent]
23+
*/
2124
@Suppress("unused")
2225
enum class UserAgent(internal val userAgent: Internet.UserAgent?) {
2326
Any(null),

0 commit comments

Comments
 (0)