Skip to content

Commit

Permalink
Remove deprecated functionality from GlobalUniqueDataProvider
Browse files Browse the repository at this point in the history
  • Loading branch information
serpro69 committed Mar 29, 2024
1 parent 00e02a5 commit 434d2fe
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ class UniqueDataProviderIT : DescribeSpec({
context("collection of values is generated") {
val faker = Faker(config)

faker.unique.enable(faker::address)
faker.unique.enable(faker::color)
faker.unique.configuration {
enable(faker::address)
enable(faker::color)
}

val countries = (0..20).map { faker.address.country() }

Expand All @@ -211,7 +213,7 @@ class UniqueDataProviderIT : DescribeSpec({

context("used values are cleared") {
val faker = Faker(config).also {
it.unique.enable(it::address)
it.unique.configuration { enable(it::address) }
}
val countries = (0..20).map { faker.address.country() }

Expand All @@ -231,7 +233,7 @@ class UniqueDataProviderIT : DescribeSpec({
// repeat 10 times to make sure values are not included in the collection
repeat(10) {
val faker = Faker(config)
faker.unique.enable(faker::address)
faker.unique.configuration { enable(faker::address) }

val countries = (0..5).map { faker.address.country() }

Expand All @@ -245,7 +247,7 @@ class UniqueDataProviderIT : DescribeSpec({
"Angola"
)

faker.unique.exclude<Address>("country", excludedCountries)
faker.unique.configuration { excludeFromFunction<Address>("country", excludedCountries) }

val newCountries = (0..20).map { faker.address.country() }

Expand Down Expand Up @@ -299,7 +301,7 @@ class UniqueDataProviderIT : DescribeSpec({
"Bouvet Island"
)

faker.unique.exclude<Address>("country", excludedCountries)
faker.unique.configuration { excludeFromFunction<Address>("country", excludedCountries) }

val countries = (0..100).map { faker.address.country() }

Expand All @@ -315,7 +317,7 @@ class UniqueDataProviderIT : DescribeSpec({

context("values are generated for another category that is not marked for unique generation") {
val faker = Faker(config)
faker.unique.enable(faker::address)
faker.unique.configuration { enable(faker::address) }

val colors = (0..100).map { faker.color.name() }

Expand All @@ -326,10 +328,10 @@ class UniqueDataProviderIT : DescribeSpec({

context("unique generation for category is disabled") {
val faker = Faker(config)
faker.unique.enable(faker::address)
faker.unique.configuration { enable(faker::address) }
(0..20).map { faker.address.country() }

faker.unique.disable(faker::address)
faker.unique.configuration { disable(faker::address) }

context("collection of values is generated") {
val countries = (0..100).map { faker.address.country() }
Expand All @@ -342,8 +344,10 @@ class UniqueDataProviderIT : DescribeSpec({

context("unique generation is disabled for all categories") {
val faker = Faker(config)
faker.unique.enable(faker::address)
faker.unique.enable(faker::color)
faker.unique.configuration {
enable(faker::address)
enable(faker::color)
}

faker.unique.disableAll()

Expand All @@ -360,7 +364,7 @@ class UniqueDataProviderIT : DescribeSpec({
}

context("unique generation for a category is re-enabled") {
faker.unique.enable(faker::address)
faker.unique.configuration { enable(faker::address) }

context("collection of values is generated") {
val countries = (0..20).map { faker.address.country() }
Expand All @@ -374,8 +378,10 @@ class UniqueDataProviderIT : DescribeSpec({

context("unique generation is cleared for all categories") {
val faker = Faker(config)
faker.unique.enable(faker::address)
faker.unique.enable(faker::color)
faker.unique.configuration {
enable(faker::address)
enable(faker::color)
}

// Generate some values first
(0..20).map { faker.address.country() }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package io.github.serpro69.kfaker

import io.github.serpro69.kfaker.provider.unique.GlobalUniqueDataDataProvider
import io.github.serpro69.kfaker.provider.unique.GlobalUniqueDataProvider

abstract class AbstractFaker(internal val config: FakerConfig) {
protected val fakerService: FakerService
get() = FakerService(this)
protected val randomService: RandomService
get() = fakerService.randomService

val unique by lazy { GlobalUniqueDataDataProvider() }
val unique by lazy { GlobalUniqueDataProvider() }

@FakerDsl
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import kotlin.reflect.KProperty0
* ```
*/
@Suppress("UNCHECKED_CAST")
class GlobalUniqueDataDataProvider internal constructor() : UniqueDataProvider() {
class GlobalUniqueDataProvider internal constructor() : UniqueDataProvider() {

@JvmSynthetic
@PublishedApi
Expand All @@ -51,46 +51,6 @@ class GlobalUniqueDataDataProvider internal constructor() : UniqueDataProvider()
config.clear(providerProperty.returnType.classifier as KClass<T>)
}

@Deprecated(
level = DeprecationLevel.WARNING,
message = "This functionality is deprecated and will be removed in release 1.8.0",
replaceWith = ReplaceWith("faker.unique.configuration { this.exclude<T>(funcName, values) }")
)
inline fun <reified T : FakeDataProvider> exclude(funcName: String, values: List<String>) {
exclude<T>(funcName, *values.toTypedArray())
}

@Deprecated(
level = DeprecationLevel.WARNING,
message = "This functionality is deprecated and will be removed in release 1.8.0",
replaceWith = ReplaceWith("faker.unique.configuration { this.exclude<T>(funcName, values) }")
)
inline fun <reified T : FakeDataProvider> exclude(funcName: String, vararg values: String) {
if (config.markedUnique.contains(T::class)) {
config.usedProviderFunctionValues[T::class]?.merge(funcName, values.toMutableSet()) { oldSet, newSet ->
oldSet.apply { addAll(newSet) }
}
}
}

@Deprecated(
level = DeprecationLevel.WARNING,
message = "This functionality is deprecated and will be removed in release 1.8.0",
replaceWith = ReplaceWith("faker.unique.configuration { this.enable(providerProperty) }")
)
fun <T : FakeDataProvider> enable(providerProperty: KProperty0<T>) {
config.enable(providerProperty.returnType.classifier as KClass<T>)
}

@Deprecated(
level = DeprecationLevel.WARNING,
message = "This functionality is deprecated and will be removed in release 1.8.0",
replaceWith = ReplaceWith("faker.unique.configuration { this.disable(providerProperty) }")
)
fun <T : FakeDataProvider> disable(providerProperty: KProperty0<T>) {
config.disable(providerProperty.returnType.classifier as KClass<T>)
}

/**
* Configures `this` Unique provider.
*/
Expand Down

0 comments on commit 434d2fe

Please sign in to comment.