-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Passes either `null` or empty string or string with spaces.
- Loading branch information
Showing
12 changed files
with
98 additions
and
39 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
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
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
22 changes: 6 additions & 16 deletions
22
junit5/src/main/java/io/qala/datagen/junit5/AlphanumericArgumentProvider.java
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
23 changes: 6 additions & 17 deletions
23
junit5/src/main/java/io/qala/datagen/junit5/AlphanumericsArgumentProvider.java
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,31 +1,20 @@ | ||
package io.qala.datagen.junit5; | ||
|
||
import org.junit.jupiter.api.extension.ContainerExtensionContext; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.ArgumentsProvider; | ||
import org.junit.jupiter.params.support.AnnotationConsumer; | ||
|
||
import java.util.Arrays; | ||
import java.util.stream.Stream; | ||
|
||
class AlphanumericsArgumentProvider implements ArgumentsProvider, AnnotationConsumer<Alphanumerics> { | ||
class AlphanumericsArgumentProvider extends RandomizedArgumentProvider<Alphanumerics> { | ||
private Alphanumerics annotation; | ||
|
||
@Override | ||
public void accept(Alphanumerics annotation) { | ||
this.annotation = annotation; | ||
} | ||
|
||
@Override | ||
public Stream<? extends Arguments> provideArguments(ContainerExtensionContext context) throws Exception { | ||
DatagenUtils.setCurrentSeedIfNotSetYet(context); | ||
if (DatagenUtils.passCaseNameToTestMethod(context)) | ||
return Arrays.stream(annotation.value()) | ||
.map(AlphanumericArgumentProvider::generateParams) | ||
.map(Arguments::of); | ||
return Arrays.stream(annotation.value()) | ||
.map(AlphanumericArgumentProvider::generateParam) | ||
.map(Arguments::of); | ||
@Override Stream<Object[]> getValueWithDescription() { | ||
return Arrays.stream(annotation.value()).map(AlphanumericArgumentProvider::generateParams); | ||
} | ||
@Override Stream<Object> getValue() { | ||
return Arrays.stream(annotation.value()).map(AlphanumericArgumentProvider::generateParam); | ||
} | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
junit5/src/main/java/io/qala/datagen/junit5/BlankString.java
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,20 @@ | ||
package io.qala.datagen.junit5; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.ArgumentsSource; | ||
|
||
import java.lang.annotation.*; | ||
|
||
/** Passes either {@code null} or empty string or string with spaces to JUnit5 tests. */ | ||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target({ElementType.METHOD}) | ||
|
||
@ArgumentsSource(BlankStringProvider.class) | ||
@ParameterizedTest | ||
public @interface BlankString { | ||
/** | ||
* Is passed to the test case if 2nd parameter is available in the test method. If left blank it's going to be | ||
* filled with the description of what's passed - null or empty string or string with spaces. | ||
*/ | ||
String name() default ""; | ||
} |
38 changes: 38 additions & 0 deletions
38
junit5/src/main/java/io/qala/datagen/junit5/BlankStringProvider.java
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,38 @@ | ||
package io.qala.datagen.junit5; | ||
|
||
import java.util.stream.Stream; | ||
|
||
import static io.qala.datagen.RandomShortApi.nullOrBlank; | ||
|
||
public class BlankStringProvider extends RandomizedArgumentProvider<BlankString> { | ||
private BlankString annotation; | ||
|
||
@Override | ||
public void accept(BlankString annotation) { | ||
this.annotation = annotation; | ||
} | ||
|
||
@Override Stream<Object[]> getValueWithDescription() { | ||
return Stream.of(annotation) | ||
.map(BlankStringProvider::generateParams); | ||
} | ||
|
||
@Override Stream<Object> getValue() { | ||
return Stream.of(generateParam()); | ||
} | ||
|
||
static String generateParam() { | ||
return nullOrBlank(); | ||
} | ||
|
||
static Object[] generateParams(BlankString annotation) { | ||
String randomValue = generateParam(); | ||
String name = annotation.name(); | ||
if(name.isEmpty()) { | ||
if(randomValue == null) name = "null"; | ||
else if(randomValue.isEmpty()) name = "empty string"; | ||
else name = "string with spaces only"; | ||
} | ||
return new Object[]{randomValue, name}; | ||
} | ||
} |
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