File tree 18 files changed +566
-17
lines changed
main/kotlin/com/appmattus/kotlinfixture
test/kotlin/com/appmattus/kotlinfixture
18 files changed +566
-17
lines changed Original file line number Diff line number Diff line change @@ -46,6 +46,24 @@ val anotherRandomIntFromAList = fixture(1..5)
46
46
The default configuration can be overridden when creating the fixture object or
47
47
when creating a particular implementation.
48
48
49
+ It is possible to create a new fixture based on an existing one, which allows
50
+ the addition of configuration changes:
51
+
52
+ ``` kotlin
53
+ val baseFixture = kotlinFixture {
54
+ factory<Int > { 3 }
55
+ }
56
+
57
+ val fixture = baseFixture.new {
58
+ factory<Long > { 100L }
59
+ }
60
+
61
+ // Prints 100
62
+ println (fixture<Long >())
63
+ // Prints 3
64
+ println (fixture<Int >())
65
+ ```
66
+
49
67
#### repeatCount
50
68
51
69
Used to determine the length used for lists and maps.
@@ -129,6 +147,9 @@ This can be overridden using `factory` which has some built in constructs:
129
147
130
148
``` kotlin
131
149
val fixture = kotlinFixture {
150
+ // Generate using ranges (and iterables)
151
+ factory<Int > { range(1 .. 10 ) }
152
+
132
153
// Generate between two dates
133
154
factory<Date > { between(startDate, endDate) }
134
155
}
@@ -263,7 +284,7 @@ fixture<AnObject> {
263
284
classOverride<AnotherObject >(NeverOptionalStrategy )
264
285
265
286
// You can override the strategy for a property of a class
266
- propertyOverride(AnotherObject : property, RandomlyOptionalStrategy )
287
+ propertyOverride(AnotherObject :: property, RandomlyOptionalStrategy )
267
288
}
268
289
}
269
290
```
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2019 Appmattus Limited
2
+ * Copyright 2020 Appmattus Limited
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -19,7 +19,7 @@ import com.github.benmanes.gradle.versions.updates.DependencyUpdatesTask
19
19
20
20
plugins {
21
21
id(" com.github.ben-manes.versions" ) version " 0.27.0"
22
- id(" io.gitlab.arturbosch.detekt" ) version " 1.2 .1"
22
+ id(" io.gitlab.arturbosch.detekt" ) version " 1.5 .1"
23
23
id(" com.appmattus.markdown" ) version " 0.6.0"
24
24
}
25
25
@@ -30,7 +30,7 @@ buildscript {
30
30
}
31
31
dependencies {
32
32
classpath(" org.jetbrains.kotlin:kotlin-gradle-plugin:1.3.61" )
33
- classpath(" com.android.tools.build:gradle:3.5.2 " )
33
+ classpath(" com.android.tools.build:gradle:3.5.3 " )
34
34
}
35
35
}
36
36
@@ -67,7 +67,7 @@ tasks.withType(DependencyUpdatesTask::class.java).all {
67
67
}
68
68
69
69
dependencies {
70
- detektPlugins(" io.gitlab.arturbosch.detekt:detekt-formatting:1.2 .1" )
70
+ detektPlugins(" io.gitlab.arturbosch.detekt:detekt-formatting:1.5 .1" )
71
71
}
72
72
73
73
detekt {
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2019 Appmattus Limited
2
+ * Copyright 2020 Appmattus Limited
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -59,7 +59,7 @@ dependencies {
59
59
testImplementation(" androidx.test.ext:junit:1.1.1" )
60
60
testImplementation(" org.robolectric:robolectric:4.3.1" )
61
61
62
- testImplementation(" junit:junit:4.12 " )
62
+ testImplementation(" junit:junit:4.13 " )
63
63
testImplementation(kotlin(" test" ))
64
64
testImplementation(kotlin(" test-junit" ))
65
65
testImplementation(" com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" )
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2019 Appmattus Limited
2
+ * Copyright 2020 Appmattus Limited
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -29,7 +29,7 @@ dependencies {
29
29
api(project(" :fixture" ))
30
30
implementation(" io.kotlintest:kotlintest-runner-junit5:3.4.2" )
31
31
32
- testImplementation(" junit:junit:4.12 " )
32
+ testImplementation(" junit:junit:4.13 " )
33
33
testImplementation(kotlin(" test" ))
34
34
testImplementation(kotlin(" test-junit" ))
35
35
testImplementation(" com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" )
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2019 Appmattus Limited
2
+ * Copyright 2020 Appmattus Limited
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -26,18 +26,18 @@ apply(from = "$rootDir/gradle/scripts/jacoco.gradle.kts")
26
26
27
27
dependencies {
28
28
implementation(kotlin(" stdlib-jdk8" ))
29
- implementation(" io.github.classgraph:classgraph:4.8.58 " )
29
+ implementation(" io.github.classgraph:classgraph:4.8.62 " )
30
30
implementation(kotlin(" reflect" ))
31
31
32
32
compileOnly(" joda-time:joda-time:2.10.5" )
33
33
testImplementation(" joda-time:joda-time:2.10.5" )
34
34
35
- compileOnly(" org.threeten:threetenbp:1.4.0 " )
36
- testImplementation(" org.threeten:threetenbp:1.4.0 " )
35
+ compileOnly(" org.threeten:threetenbp:1.4.1 " )
36
+ testImplementation(" org.threeten:threetenbp:1.4.1 " )
37
37
38
38
compileOnly(files(" ${System .getenv(" ANDROID_HOME" )} /platforms/android-29/android.jar" ))
39
39
40
- testImplementation(" junit:junit:4.12 " )
40
+ testImplementation(" junit:junit:4.13 " )
41
41
testImplementation(kotlin(" test" ))
42
42
testImplementation(kotlin(" test-junit" ))
43
43
testImplementation(" com.nhaarman.mockitokotlin2:mockito-kotlin:2.2.0" )
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2019 Appmattus Limited
2
+ * Copyright 2020 Appmattus Limited
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -53,6 +53,10 @@ class Fixture(val fixtureConfiguration: Configuration) {
53
53
}
54
54
return result
55
55
}
56
+
57
+ fun new (configuration : ConfigurationBuilder .() -> Unit = {}): Fixture {
58
+ return Fixture (ConfigurationBuilder (fixtureConfiguration).apply (configuration).build())
59
+ }
56
60
}
57
61
58
62
fun kotlinFixture (init : ConfigurationBuilder .() -> Unit = {}) = Fixture (ConfigurationBuilder ().apply (init ).build())
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2019 Appmattus Limited
2
+ * Copyright 2020 Appmattus Limited
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -25,3 +25,6 @@ interface Generator<T> {
25
25
}
26
26
27
27
internal typealias GeneratorFun = Generator <Any ?>.() -> Any?
28
+
29
+ fun <T > Generator<T>.range (range : Iterable <T >) =
30
+ range.shuffled(random).firstOrNull() ? : throw NoSuchElementException (" Range is empty" )
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2020 Appmattus Limited
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com.appmattus.kotlinfixture.config
18
+
19
+ @Suppress(" FunctionName" , " NonAsciiCharacters" )
20
+ fun Generator <Boolean >.`¯\_(ツ)_/¯` (): Boolean = random.nextBoolean()
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2020 Appmattus Limited
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com.appmattus.kotlinfixture.config
18
+
19
+ @Suppress(" FunctionName" , " NonAsciiCharacters" )
20
+ fun Generator <Double >.`¯\_(ツ)_/¯` (): Double = random.nextDouble()
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2020 Appmattus Limited
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com.appmattus.kotlinfixture.config
18
+
19
+ @Suppress(" FunctionName" , " NonAsciiCharacters" )
20
+ fun Generator <Float >.`¯\_(ツ)_/¯` (): Float = random.nextFloat()
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2020 Appmattus Limited
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com.appmattus.kotlinfixture.config
18
+
19
+ @Suppress(" FunctionName" , " NonAsciiCharacters" )
20
+ fun Generator <Int >.`¯\_(ツ)_/¯` (): Int = random.nextInt()
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2020 Appmattus Limited
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com.appmattus.kotlinfixture.config
18
+
19
+ @Suppress(" FunctionName" , " NonAsciiCharacters" )
20
+ fun Generator <Long >.`¯\_(ツ)_/¯` (): Long = random.nextLong()
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2020 Appmattus Limited
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com.appmattus.kotlinfixture.config
18
+
19
+ import kotlin.random.nextUInt
20
+
21
+ @Suppress(" EXPERIMENTAL_API_USAGE" , " FunctionName" , " NonAsciiCharacters" )
22
+ fun Generator <UInt >.`¯\_(ツ)_/¯` (): UInt = random.nextUInt()
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright 2020 Appmattus Limited
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com.appmattus.kotlinfixture.config
18
+
19
+ import kotlin.random.nextULong
20
+
21
+ @Suppress(" EXPERIMENTAL_API_USAGE" , " FunctionName" , " NonAsciiCharacters" )
22
+ fun Generator <ULong >.`¯\_(ツ)_/¯` (): ULong = random.nextULong()
You can’t perform that action at this time.
0 commit comments