Skip to content

Commit

Permalink
Remove deprecated functionality from data providers
Browse files Browse the repository at this point in the history
  • Loading branch information
serpro69 committed Mar 29, 2024
1 parent 64d8831 commit 00e02a5
Show file tree
Hide file tree
Showing 22 changed files with 54 additions and 282 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,12 @@ repositories {
</repositories>
```

#### BOM

Kotlin-faker provides a [Bill-of-Materials](https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html#bill-of-materials-bom-poms) that simplifies dependency management.

See [bom/README.md](bom/README.md) for more details.

#### Additional Fakers

Extra fakers covering a wide range of domains are available as separate dependencies. See [faker](faker) submodules in this repo for more details about each faker.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
},
{
"name":"io.github.serpro69.kfaker.books.provider.Dune",
"methods":[{"name":"quotes","parameterTypes":["io.github.serpro69.kfaker.books.provider.Dune$QuoteCharacter"] }, {"name":"quotes$default","parameterTypes":["io.github.serpro69.kfaker.books.provider.Dune","io.github.serpro69.kfaker.books.provider.Dune$QuoteCharacter","int","java.lang.Object"] }]
"methods":[{"name":"characters","parameterTypes":[] }, {"name":"cities","parameterTypes":[] }, {"name":"planets","parameterTypes":[] }, {"name":"quotes","parameterTypes":["io.github.serpro69.kfaker.books.provider.Dune$QuoteCharacter"] }, {"name":"quotes$default","parameterTypes":["io.github.serpro69.kfaker.books.provider.Dune","io.github.serpro69.kfaker.books.provider.Dune$QuoteCharacter","int","java.lang.Object"] }, {"name":"sayings","parameterTypes":["io.github.serpro69.kfaker.books.provider.Dune$SayingOrigin"] }, {"name":"sayings$default","parameterTypes":["io.github.serpro69.kfaker.books.provider.Dune","io.github.serpro69.kfaker.books.provider.Dune$SayingOrigin","int","java.lang.Object"] }, {"name":"titles","parameterTypes":[] }]
},
{
"name":"io.github.serpro69.kfaker.books.provider.Dune$QuoteCharacter"
Expand Down Expand Up @@ -304,9 +304,6 @@
},
{
"name":"io.github.serpro69.kfaker.edu.provider.Educator",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"campus","parameterTypes":[] }, {"name":"courseName","parameterTypes":[] }, {"name":"degree","parameterTypes":[] }, {"name":"getTertiary","parameterTypes":[] }, {"name":"primary","parameterTypes":[] }, {"name":"primarySchool","parameterTypes":[] }, {"name":"schoolName","parameterTypes":[] }, {"name":"secondary","parameterTypes":[] }, {"name":"secondarySchool","parameterTypes":[] }, {"name":"subject","parameterTypes":[] }, {"name":"university","parameterTypes":[] }]
},
{
Expand Down Expand Up @@ -535,9 +532,6 @@
},
{
"name":"io.github.serpro69.kfaker.japmedia.provider.OnePiece",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"akumaNoMi","parameterTypes":[] }, {"name":"characters","parameterTypes":[] }, {"name":"islands","parameterTypes":[] }, {"name":"locations","parameterTypes":[] }, {"name":"quotes","parameterTypes":[] }, {"name":"seas","parameterTypes":[] }]
},
{
Expand Down Expand Up @@ -766,9 +760,6 @@
},
{
"name":"io.github.serpro69.kfaker.music.provider.Music",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"albums","parameterTypes":[] }, {"name":"bands","parameterTypes":[] }, {"name":"genres","parameterTypes":[] }, {"name":"instruments","parameterTypes":[] }, {"name":"mamboNo5","parameterTypes":[] }]
},
{
Expand Down Expand Up @@ -812,9 +803,6 @@
},
{
"name":"io.github.serpro69.kfaker.provider.Address",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"buildingNumber","parameterTypes":[] }, {"name":"city","parameterTypes":[] }, {"name":"cityPrefix","parameterTypes":[] }, {"name":"citySuffix","parameterTypes":[] }, {"name":"cityWithState","parameterTypes":[] }, {"name":"community","parameterTypes":[] }, {"name":"communityPrefix","parameterTypes":[] }, {"name":"communitySuffix","parameterTypes":[] }, {"name":"country","parameterTypes":[] }, {"name":"countryByCode","parameterTypes":["java.lang.String"] }, {"name":"countryByName","parameterTypes":["java.lang.String"] }, {"name":"countryCode","parameterTypes":[] }, {"name":"countryCodeLong","parameterTypes":[] }, {"name":"defaultCountry","parameterTypes":[] }, {"name":"fullAddress","parameterTypes":[] }, {"name":"mailbox","parameterTypes":[] }, {"name":"postcode","parameterTypes":[] }, {"name":"postcodeByState","parameterTypes":["java.lang.String"] }, {"name":"secondaryAddress","parameterTypes":[] }, {"name":"state","parameterTypes":[] }, {"name":"stateAbbr","parameterTypes":[] }, {"name":"streetAddress","parameterTypes":[] }, {"name":"streetName","parameterTypes":[] }, {"name":"streetSuffix","parameterTypes":[] }, {"name":"timeZone","parameterTypes":[] }]
},
{
Expand All @@ -825,9 +813,6 @@
"name":"io.github.serpro69.kfaker.provider.Color",
"methods":[{"name":"name","parameterTypes":[] }]
},
{
"name":"io.github.serpro69.kfaker.provider.CountryCode"
},
{
"name":"io.github.serpro69.kfaker.provider.Currency",
"methods":[{"name":"code","parameterTypes":[] }, {"name":"name","parameterTypes":[] }, {"name":"symbol","parameterTypes":[] }]
Expand All @@ -841,9 +826,6 @@
},
{
"name":"io.github.serpro69.kfaker.provider.File",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"extension","parameterTypes":[] }, {"name":"getMimeType","parameterTypes":[] }]
},
{
Expand Down Expand Up @@ -878,19 +860,13 @@
},
{
"name":"io.github.serpro69.kfaker.provider.Name",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"femaleFirstName","parameterTypes":[] }, {"name":"firstName","parameterTypes":[] }, {"name":"lastName","parameterTypes":[] }, {"name":"maleFirstName","parameterTypes":[] }, {"name":"name","parameterTypes":[] }, {"name":"nameWithMiddle","parameterTypes":[] }, {"name":"neutralFirstName","parameterTypes":[] }]
},
{
"name":"io.github.serpro69.kfaker.provider.Person"
},
{
"name":"io.github.serpro69.kfaker.provider.PhoneNumber",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"areaCode","parameterTypes":[] }, {"name":"countryCode","parameterTypes":[] }, {"name":"exchangeCode","parameterTypes":[] }, {"name":"extension","parameterTypes":[] }, {"name":"getCellPhone","parameterTypes":[] }, {"name":"phoneNumber","parameterTypes":[] }, {"name":"subscriberNumber","parameterTypes":[] }]
},
{
Expand Down Expand Up @@ -990,9 +966,6 @@
},
{
"name":"io.github.serpro69.kfaker.tech.provider.Computer",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"getOs","parameterTypes":[] }, {"name":"platform","parameterTypes":[] }, {"name":"type","parameterTypes":[] }]
},
{
Expand Down Expand Up @@ -1121,9 +1094,6 @@
},
{
"name":"io.github.serpro69.kfaker.tv.provider.Buffy",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"actors","parameterTypes":[] }, {"name":"bigBads","parameterTypes":[] }, {"name":"characters","parameterTypes":[] }, {"name":"episodes","parameterTypes":[] }, {"name":"quotes","parameterTypes":[] }]
},
{
Expand All @@ -1144,9 +1114,6 @@
},
{
"name":"io.github.serpro69.kfaker.tv.provider.FreshPriceOfBelAir",
"allDeclaredFields":true,
"queryAllDeclaredMethods":true,
"queryAllDeclaredConstructors":true,
"methods":[{"name":"actors","parameterTypes":[] }, {"name":"characters","parameterTypes":[] }, {"name":"quotes","parameterTypes":[] }]
},
{
Expand Down Expand Up @@ -1253,6 +1220,10 @@
"name":"io.github.serpro69.kfaker.tv.provider.VentureBros",
"methods":[{"name":"character","parameterTypes":[] }, {"name":"organization","parameterTypes":[] }, {"name":"quote","parameterTypes":[] }, {"name":"vehicle","parameterTypes":[] }]
},
{
"name":"java.io.Console",
"methods":[{"name":"isTerminal","parameterTypes":[] }]
},
{
"name":"java.lang.ClassValue"
},
Expand All @@ -1264,6 +1235,10 @@
{
"name":"java.lang.String"
},
{
"name":"java.lang.System",
"methods":[{"name":"console","parameterTypes":[] }]
},
{
"name":"java.nio.file.Path"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Extras : DescribeSpec({
class Foo(val a: String)
class Bar(val foo: Foo)

val foo: Foo = faker.randomProvider.randomClassInstance()
val bar: Bar = faker.randomProvider.randomClassInstance()
val foo: Foo = faker.randomClass.randomClassInstance()
val bar: Bar = faker.randomClass.randomClassInstance()
// END extras_random_instance_one
}

Expand All @@ -31,7 +31,7 @@ class Extras : DescribeSpec({
// START extras_random_instance_two
class Baz(val id: Int, val uuid: UUID, val relatedUuid: UUID, val user: String)

val baz: Baz = faker.randomProvider.randomClassInstance {
val baz: Baz = faker.randomClass.randomClassInstance {
typeGenerator<UUID> { UUID.fromString("00000000-0000-0000-0000-000000000000") }
typeGenerator<Int> { 0 }
typeGenerator<String> { parameterInfo -> "${parameterInfo.name}_${randomString()}" }
Expand Down Expand Up @@ -75,7 +75,7 @@ class Extras : DescribeSpec({

it("should generate class with configured number of constructor args") {
// START extras_random_instance_four
val fooBarBaz: FooBarBaz = faker.randomProvider.randomClassInstance {
val fooBarBaz: FooBarBaz = faker.randomClass.randomClassInstance {
constructorParamSize = 3
fallbackStrategy = FallbackStrategy.USE_MAX_NUM_OF_ARGS
}
Expand All @@ -87,7 +87,7 @@ class Extras : DescribeSpec({

it("should use constructor filter strategy") {
// START extras_random_instance_five
val fooBarBaz: FooBarBaz = faker.randomProvider.randomClassInstance {
val fooBarBaz: FooBarBaz = faker.randomClass.randomClassInstance {
constructorFilterStrategy = ConstructorFilterStrategy.MAX_NUM_OF_ARGS
}
assertNotEquals(fooBarBaz.foo, null)
Expand All @@ -104,7 +104,7 @@ class Extras : DescribeSpec({
val map: Map<String, Int>
)

val foo = faker.randomProvider.randomClassInstance<Foo>()
val foo = faker.randomClass.randomClassInstance<Foo>()

assertEquals(foo.list.size, 1)
assertEquals(foo.set.size, 1)
Expand All @@ -120,7 +120,7 @@ class Extras : DescribeSpec({
val map: Map<String, Int>
)

val foo = faker.randomProvider.randomClassInstance<Foo> {
val foo = faker.randomClass.randomClassInstance<Foo> {
collectionsSize = 6
}

Expand All @@ -137,7 +137,7 @@ class Extras : DescribeSpec({
val set: Set<String>
)

val testClass = faker.randomProvider.randomClassInstance<TestClass> {
val testClass = faker.randomClass.randomClassInstance<TestClass> {
typeGenerator { "a string" }
collectionsSize = 10
}
Expand All @@ -156,7 +156,7 @@ class Extras : DescribeSpec({
val map: Map<String, Int>
)

val bar = faker.randomProvider.randomClassInstance<Bar> {
val bar = faker.randomClass.randomClassInstance<Bar> {
typeGenerator { emptyList<Foo>() }
typeGenerator { setOf("one", "two", "fortytwo") }
typeGenerator { mapOf("pwd" to 12177) }
Expand All @@ -183,39 +183,39 @@ class Extras : DescribeSpec({
}
}
val f = Faker(cfg)
val baz: Baz = f.randomProvider.randomClassInstance<Baz>()
val baz: Baz = f.randomClass.randomClassInstance<Baz>()
assertEquals(baz.bar, Bar(42, UUID.fromString("11111111-1111-1111-1111-111111111111")))
val anotherBaz = f.randomProvider.new().randomClassInstance<Baz>()
val anotherBaz = f.randomClass.new().randomClassInstance<Baz>()
assertEquals(anotherBaz.bar, Bar(42, UUID.fromString("11111111-1111-1111-1111-111111111111")))
// END extras_random_instance_eleven
}

it("should configure random class instance from randomProvider") {
it("should configure random class instance from randomClass") {
// START extras_random_instance_twelve
val cfg = fakerConfig {
randomClassInstance {
typeGenerator<Bar> { Bar(42, UUID.fromString("11111111-1111-1111-1111-111111111111")) }
}
}
val f = Faker(cfg).also {
it.randomProvider.configure {
it.randomClass.configure {
typeGenerator<UUID> { UUID.fromString("00000000-0000-0000-0000-000000000000") }
}
}

val bar: Bar = f.randomProvider.randomClassInstance()
val baz: Baz = f.randomProvider.randomClassInstance()
val bar: Bar = f.randomClass.randomClassInstance()
val baz: Baz = f.randomClass.randomClassInstance()
assertEquals(bar.uuid, UUID.fromString("00000000-0000-0000-0000-000000000000"))
assertEquals(baz.bar, Bar(42, UUID.fromString("11111111-1111-1111-1111-111111111111")))
// END extras_random_instance_twelve
}

it("should configure random class instance from function") {
// START extras_random_instance_thirteen
faker.randomProvider.configure {
faker.randomClass.configure {
typeGenerator<Bar> { Bar(42, UUID.fromString("11111111-1111-1111-1111-111111111111")) }
}
val baz: Baz = faker.randomProvider.randomClassInstance {
val baz: Baz = faker.randomClass.randomClassInstance {
typeGenerator<Bar> { Bar(1, UUID.fromString("00000000-0000-0000-0000-000000000000")) }
}
assertEquals(baz.bar, Bar(1, UUID.fromString("00000000-0000-0000-0000-000000000000")))
Expand All @@ -236,11 +236,11 @@ class Extras : DescribeSpec({
}
}
val f = Faker(cfg)
f.randomProvider.configure { //
f.randomClass.configure { //
typeGenerator<Bar> { Bar(42, UUID.fromString("11111111-1111-1111-1111-111111111111")) }
}
val new = f.randomProvider.new() //
val baz: Baz = f.randomProvider.randomClassInstance<Baz>()
val new = f.randomClass.new() //
val baz: Baz = f.randomClass.randomClassInstance<Baz>()
val newBaz: Baz = new.randomClassInstance<Baz>()
assertEquals(Bar(42, UUID.fromString("11111111-1111-1111-1111-111111111111")), baz.bar)
assertEquals(Bar(1, UUID.fromString("00000000-0000-0000-0000-000000000000")), newBaz.bar)
Expand All @@ -255,19 +255,19 @@ class Extras : DescribeSpec({
}
}
val f = Faker(cfg)
f.randomProvider.configure { //
f.randomClass.configure { //
typeGenerator<Bar> { Bar(42, UUID.fromString("11111111-1111-1111-1111-111111111111")) }
}
val copy = f.randomProvider.copy() //
val baz: Baz = f.randomProvider.randomClassInstance<Baz>()
val copy = f.randomClass.copy() //
val baz: Baz = f.randomClass.randomClassInstance<Baz>()
val bazCopy: Baz = copy.randomClassInstance<Baz>()
assertEquals(Bar(42, UUID.fromString("11111111-1111-1111-1111-111111111111")), baz.bar)
assertEquals(Bar(42, UUID.fromString("11111111-1111-1111-1111-111111111111")), bazCopy.bar)

copy.configure { //
typeGenerator<Bar> { Bar(0, UUID.fromString("22222222-2222-2222-2222-222222222222")) }
}
val originalBaz: Baz = f.randomProvider.randomClassInstance<Baz>()
val originalBaz: Baz = f.randomClass.randomClassInstance<Baz>()
val reconfiguredBazCopy = copy.randomClassInstance<Baz>()
assertEquals(Bar(42, UUID.fromString("11111111-1111-1111-1111-111111111111")), originalBaz.bar)
assertEquals(Bar(0, UUID.fromString("22222222-2222-2222-2222-222222222222")), reconfiguredBazCopy.bar)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class FakerConfiguration : DescribeSpec({
namedParameterGenerator("name") { faker {}.name.name() }
}
}
val test = Faker(config).randomProvider.randomClassInstance<Test>()
val test = Faker(config).randomClass.randomClassInstance<Test>()
assertEquals(test.uuid, UUID.fromString("00000000-0000-0000-0000-000000000000"))
// END faker_config_six
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,16 @@ class Homepage : DescribeSpec({
class Foo(val a: String)
class Bar(val foo: Foo)

val foo: Foo = faker.randomProvider.randomClassInstance()
val bar: Bar = faker.randomProvider.randomClassInstance()
val foo: Foo = faker.randomClass.randomClassInstance()
val bar: Bar = faker.randomClass.randomClassInstance()
// END random_class_instance_one
}
it("should generate types by configuration") {
fun randomString() = "X3a8s813dcb";
// START random_class_instance_two
class Baz(val id: Int, val uuid: UUID, val username: String)

val baz: Baz = faker.randomProvider.randomClassInstance {
val baz: Baz = faker.randomClass.randomClassInstance {
// ヽ(^o^)丿 ᕕ(ᐛ)ᕗ Prepend string type parameter values with parameter name!
typeGenerator<String> { parameterInfo -> "${parameterInfo.name}_${randomString()}" }
typeGenerator<UUID> { UUID.fromString("00000000-0000-0000-0000-000000000000") }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ class PhoneNumberIT : DescribeSpec({
}
it("should generate a countryCode run#$it") {
phone.countryCode() shouldNotBe ""
// test deprecated function until it's removed
phone.countryCode.code() shouldNotBe ""
}
}
}
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/kotlin/io/github/serpro69/kfaker/Faker.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,6 @@ class Faker @JvmOverloads constructor(config: FakerConfig = fakerConfig { }) : A
val randomClass: RandomClassProvider by lazy { RandomClassProvider(config) }
val string: StringProvider by lazy { StringProvider(fakerService) }

@Deprecated(
message = "This property is deprecated and will be removed in future releases",
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("randomClass")
)
val randomProvider: RandomClassProvider by lazy { RandomClassProvider(config) }

// yml dictionary-based providers
val address: Address by lazy { Address(fakerService) }
val color: Color by lazy { Color(fakerService) }
Expand Down
7 changes: 0 additions & 7 deletions core/src/main/kotlin/io/github/serpro69/kfaker/FakerConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,6 @@ class FakerConfig private constructor(
}
}

@Deprecated(
message = "This function is deprecated and will be removed in 1.9.0",
ReplaceWith("fakerConfig { }"),
level = DeprecationLevel.WARNING
)
fun FakerConfig.Builder.create(block: ConfigBuilder): FakerConfig = this.apply(block).build()

/**
* Applies the the [block] function to [ConfigBuilder]
* and returns as an instance of [FakerConfig] from that builder.
Expand Down
Loading

0 comments on commit 00e02a5

Please sign in to comment.