-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
524 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,3 @@ | ||
plugins { `kotlin-dsl` } | ||
|
||
repositories { gradlePluginPortal() } | ||
|
||
dependencies { | ||
implementation("info.solidsoft.gradle.pitest:gradle-pitest-plugin:1.15.0") | ||
implementation("com.diffplug.spotless:spotless-plugin-gradle:6.24.0") | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
= Random | ||
|
||
The Random module contains a collection of builders and utility functions to generate random data. | ||
|
||
|
||
== Random Integer | ||
|
||
The link:{javadoc-url}/http/org/stubit/random/RandomIntBuilder.html[`RandomIntBuilder` class] allows to generate random Integer values within a defined min and max range (both inclusive). | ||
|
||
NOTE:: It is not possible to set max to Integer.MAX_VALUE. | ||
The maximum value is Integer.MAX_VALUE - 1. | ||
This is due to the fact that the SecureRandom.nextInt(int) method is exclusive of the upper bound. | ||
|
||
|
||
=== Min and Max | ||
|
||
[source,java,indent=0] | ||
---- | ||
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=anInt] | ||
---- | ||
|
||
|
||
=== Positive Integer | ||
|
||
[source,java,indent=0] | ||
---- | ||
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=aPositiveInt] | ||
---- | ||
|
||
|
||
=== Negative Integer | ||
|
||
|
||
[source,java,indent=0] | ||
---- | ||
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=aNegativeInt] | ||
---- | ||
|
||
|
||
== Random Choice | ||
|
||
The link:{javadoc-url}/http/org/stubit/random/RandomChoiceBuilder.html[`RandomChoiceBuilder` class] allows to make a random choice from the objects in a Collection, an Array, or the values of an Enum type. | ||
|
||
|
||
=== From Collection | ||
|
||
[source,java,indent=0] | ||
---- | ||
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=from_list] | ||
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=from_map] | ||
---- | ||
|
||
|
||
=== From Array | ||
|
||
[source,java,indent=0] | ||
---- | ||
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=from_ellipsis] | ||
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=from_array] | ||
---- | ||
|
||
|
||
=== From Enum Type | ||
|
||
[source,java,indent=0] | ||
---- | ||
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=from_enum_values] | ||
---- | ||
|
||
|
||
=== Excluding Choices | ||
|
||
[source,java,indent=0] | ||
---- | ||
include::../../../test/java/org/stubit/random/RandomDocTest.java[tag=save] | ||
---- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package org.stubit.random; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.stubit.random.RandomChoiceBuilder.from; | ||
import static org.stubit.random.RandomChoiceBuilder.fromValuesOf; | ||
import static org.stubit.random.RandomIntBuilder.*; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class RandomDocTest { | ||
|
||
@Test | ||
void randomInt_examples() { | ||
// tag::anInt[] | ||
int someInt = anInt().build(); | ||
assertThat(someInt).isBetween(Integer.MIN_VALUE, Integer.MAX_VALUE - 1); | ||
|
||
int someIntBetween42And4711 = anInt().min(42).max(4711).build(); | ||
assertThat(someIntBetween42And4711).isBetween(42, 4711); | ||
|
||
int someIntLessThan4711 = anInt().max(4711).build(); | ||
assertThat(someIntLessThan4711).isLessThanOrEqualTo(4711); | ||
|
||
int someIntGreaterThanMinus10 = anInt().min(-42).build(); | ||
assertThat(someIntGreaterThanMinus10).isGreaterThanOrEqualTo(-42); | ||
// end::anInt[] | ||
|
||
// tag::aPositiveInt[] | ||
int somePositiveInt = aPositiveInt().build(); | ||
assertThat(somePositiveInt).isPositive().isNotZero().isLessThan(Integer.MAX_VALUE); | ||
// end::aPositiveInt[] | ||
|
||
// tag::aNegativeInt[] | ||
int someNegativeInt = aNegativeInt().build(); | ||
assertThat(someNegativeInt).isNegative().isNotZero().isGreaterThanOrEqualTo(Integer.MIN_VALUE); | ||
// end::aNegativeInt[] | ||
} | ||
|
||
@Test | ||
void anyOf_examples() { | ||
// tag::from_ellipsis[] | ||
assertThat(from("a", "b", "c").chooseAny()).isIn("a", "b", "c"); | ||
// end::from_ellipsis[] | ||
|
||
// tag::from_array[] | ||
String[] choiceArray = {"a", "b", "c"}; | ||
assertThat(from(choiceArray).chooseAny()).isIn((Object[]) choiceArray); | ||
// end::from_array[] | ||
|
||
// tag::from_list[] | ||
var choicesList = List.of("a", "b", "c"); | ||
assertThat(from(choicesList).chooseAny()).isIn(choicesList); | ||
// end::from_list[] | ||
|
||
// tag::from_map[] | ||
var choicesMap = Map.of("a", 1, "b", 2, "c", 3); | ||
assertThat(from(choicesMap).chooseAny()).isIn(choicesMap); | ||
// end::from_map[] | ||
|
||
// tag::from_enum_values[] | ||
enum Color { | ||
RED, | ||
GREEN, | ||
BLUE | ||
} | ||
assertThat(fromValuesOf(Color.class).chooseAny()).isIn(Color.RED, Color.GREEN, Color.BLUE); | ||
// end::from_enum_values[] | ||
|
||
// tag::save[] | ||
var allChoices = List.of("a", "b", "c"); | ||
var excludedChoice = "a"; | ||
assertThat(from(allChoices).save(excludedChoice).chooseAny()).isNotEqualTo(excludedChoice); | ||
// end::save[] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.