BAEL-5760: Change test names to BDD format (#12856)
Co-authored-by: Loredana Crusoveanu <lore.crusoveanu@gmail.com>
This commit is contained in:
parent
fe09cfb802
commit
88c31bab42
@ -41,6 +41,18 @@
|
|||||||
<artifactId>jimfs</artifactId>
|
<artifactId>jimfs</artifactId>
|
||||||
<version>${jimf.version}</version>
|
<version>${jimf.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>net.datafaker</groupId>
|
||||||
|
<artifactId>datafaker</artifactId>
|
||||||
|
<version>${datefaker.version}</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
@ -49,6 +61,8 @@
|
|||||||
<easymock.version>3.5.1</easymock.version>
|
<easymock.version>3.5.1</easymock.version>
|
||||||
<jmockit.version>1.41</jmockit.version>
|
<jmockit.version>1.41</jmockit.version>
|
||||||
<jimf.version>1.1</jimf.version>
|
<jimf.version>1.1</jimf.version>
|
||||||
|
<datefaker.version>1.6.0</datefaker.version>
|
||||||
|
<jackson.version>2.13.4</jackson.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
</project>
|
</project>
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import net.datafaker.Faker;
|
||||||
|
|
||||||
|
public class Collection {
|
||||||
|
public static final int MIN = 1;
|
||||||
|
public static final int MAX = 100;
|
||||||
|
private static final Faker faker = new Faker();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(getFictionalCharacters());
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<String> getFictionalCharacters() {
|
||||||
|
return faker.collection(
|
||||||
|
() -> faker.starWars().character(),
|
||||||
|
() -> faker.starTrek().character())
|
||||||
|
.len(MIN, MAX)
|
||||||
|
.generate();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import net.datafaker.Faker;
|
||||||
|
|
||||||
|
public class Csv {
|
||||||
|
private static final Faker faker = new Faker();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("First expression:\n" + getFirstExpression());
|
||||||
|
System.out.println("Second expression:\n" + getSecondExpression());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getSecondExpression() {
|
||||||
|
final String secondExpressionString
|
||||||
|
= "#{csv ',','\"','true','4','name_column','#{Name.first_name}','last_name_column','#{Name.last_name}'}";
|
||||||
|
return faker.expression(secondExpressionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getFirstExpression() {
|
||||||
|
final String firstExpressionString
|
||||||
|
= "#{csv '4','name_column','#{Name.first_name}','last_name_column','#{Name.last_name}'}";
|
||||||
|
return faker.expression(firstExpressionString);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
|
||||||
|
import net.datafaker.Faker;
|
||||||
|
|
||||||
|
public class Examplify {
|
||||||
|
private static final Faker faker = new Faker();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Expression: " + getExpression());
|
||||||
|
System.out.println("Number expression: " + getNumberExpression());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getNumberExpression() {
|
||||||
|
return faker.expression("#{examplify '123-123-123'}");
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getExpression() {
|
||||||
|
return faker.expression("#{examplify 'Cat in the Hat'}");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import net.datafaker.Faker;
|
||||||
|
|
||||||
|
public class Json {
|
||||||
|
private static final Faker faker = new Faker();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(getExpression());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getExpression() {
|
||||||
|
return faker.expression(
|
||||||
|
"#{json 'person'," +
|
||||||
|
"'#{json ''first_name'',''#{Name.first_name}'',''last_name'',''#{Name.last_name}''}'," +
|
||||||
|
"'address'," +
|
||||||
|
"'#{json ''country'',''#{Address.country}'',''city'',''#{Address.city}''}'}");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import net.datafaker.Faker;
|
||||||
|
|
||||||
|
public class MethodInvocation {
|
||||||
|
private static final Faker faker = new Faker();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Name from a method: " + getNameFromMethod());
|
||||||
|
System.out.println("Name from an expression: " + getNameFromExpression());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getNameFromExpression() {
|
||||||
|
return faker.expression("#{Name.first_Name}");
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getNameFromMethod() {
|
||||||
|
return faker.name().firstName();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import net.datafaker.Faker;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
public class MethodInvocationWithParams {
|
||||||
|
public static final int MIN = 1;
|
||||||
|
public static final int MAX = 10;
|
||||||
|
public static final String UNIT = "SECONDS";
|
||||||
|
private static final Faker faker = new Faker();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Duration from the method :" + getDurationFromMethod());
|
||||||
|
System.out.println("Duration from the expression: " + getDurationFromExpression());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getDurationFromExpression() {
|
||||||
|
return faker.expression("#{date.duration '1', '10', 'SECONDS'}");
|
||||||
|
}
|
||||||
|
|
||||||
|
static Duration getDurationFromMethod() {
|
||||||
|
return faker.date().duration(MIN, MAX, UNIT);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import net.datafaker.Faker;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class MixedCollection {
|
||||||
|
public static final int MIN = 1;
|
||||||
|
public static final int MAX = 20;
|
||||||
|
private static final Faker faker = new Faker();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println(getMixedCollection());
|
||||||
|
}
|
||||||
|
|
||||||
|
static List<? extends Serializable> getMixedCollection() {
|
||||||
|
return faker.collection(
|
||||||
|
() -> faker.date().birthday(),
|
||||||
|
() -> faker.name().fullName()
|
||||||
|
)
|
||||||
|
.len(MIN, MAX)
|
||||||
|
.generate();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import net.datafaker.Faker;
|
||||||
|
|
||||||
|
public class Option {
|
||||||
|
private static final Faker faker = new Faker();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("First expression: " + getFirstExpression());
|
||||||
|
System.out.println("Second expression: " + getSecondExpression());
|
||||||
|
System.out.println("Third expression: " + getThirdExpression());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getThirdExpression() {
|
||||||
|
return faker.expression("#{regexify '(Hi|Hello|Hey)'}");
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getSecondExpression() {
|
||||||
|
return faker.expression("#{options.option '1','2','3','4','*'}");
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getFirstExpression() {
|
||||||
|
return faker.expression("#{options.option 'Hi','Hello','Hey'}");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import com.github.javafaker.Faker;
|
||||||
|
|
||||||
|
public class Regexify {
|
||||||
|
private static final Faker faker = new Faker();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Expression: " + getExpression());
|
||||||
|
System.out.println("Regexify with a method: " + getMethodExpression());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getMethodExpression() {
|
||||||
|
return faker.regexify("[A-D]{4,10}");
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getExpression() {
|
||||||
|
return faker.expression("#{regexify '(hello|bye|hey)'}");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import net.datafaker.Faker;
|
||||||
|
|
||||||
|
public class Templatify {
|
||||||
|
private static final Faker faker = new Faker();
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
System.out.println("Expression: " + getExpression());
|
||||||
|
System.out.println("Expression with a placeholder: " + getExpressionWithPlaceholder());
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getExpressionWithPlaceholder() {
|
||||||
|
return faker.expression("#{templatify '#ight', '#', 'f', 'l', 'm', 'n'}");
|
||||||
|
}
|
||||||
|
|
||||||
|
static String getExpression() {
|
||||||
|
return faker.expression("#{templatify 'test','t','j','r'}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||||
|
|
||||||
|
class CollectionUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingFictionaCharacters_thenResultNotEmptyAndOfCorrectSize() {
|
||||||
|
assertAll(
|
||||||
|
() -> assertThat(Collection.getFictionalCharacters()).isNotEmpty(),
|
||||||
|
() -> assertThat(Collection.getFictionalCharacters()).size().isGreaterThanOrEqualTo(Collection.MIN),
|
||||||
|
() -> assertThat(Collection.getFictionalCharacters()).size().isLessThanOrEqualTo(Collection.MAX)
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||||
|
|
||||||
|
class CsvUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingFirstExpression_thenResultNotEmptyAndOfCorrectSizeAndFormat() {
|
||||||
|
assertAll(
|
||||||
|
() -> assertThat(Csv.getFirstExpression()).isNotBlank(),
|
||||||
|
() -> assertThat(Csv.getFirstExpression().split("\n")).hasSize(5),
|
||||||
|
() -> assertThat(Csv.getFirstExpression().split("\n")[0]).isEqualTo("\"name_column\",\"last_name_column\"")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingSecondExpression_thenResultNotEmptyAndOfCorrectSizeAndFormat() {
|
||||||
|
assertAll(
|
||||||
|
() -> assertThat(Csv.getFirstExpression()).isNotBlank(),
|
||||||
|
() -> assertThat(Csv.getFirstExpression().split("\n")).hasSize(5),
|
||||||
|
() -> assertThat(Csv.getFirstExpression().split("\n")[0]).isEqualTo("\"name_column\",\"last_name_column\"")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,26 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class ExamplifyUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingNumberExpression_thenResultNotEmptyAndMathesRegex() {
|
||||||
|
assertAll(
|
||||||
|
() -> assertThat(Examplify.getNumberExpression()).isNotBlank(),
|
||||||
|
() -> assertThat(Examplify.getNumberExpression()).matches("\\d{3}-\\d{3}-\\d{3}")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingExpression_thenResultNotEmptyAndMathesRegex() {
|
||||||
|
assertAll(
|
||||||
|
() -> assertThat(Examplify.getExpression()).isNotBlank(),
|
||||||
|
() -> assertThat(Examplify.getExpression())
|
||||||
|
.matches("[A-Z][a-z]{2} [a-z]{2} [a-z]{3} [A-Z][a-z]{2}")
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.assertj.core.api.Assertions.assertThatNoException;
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class JsonUnitTest {
|
||||||
|
|
||||||
|
private static final ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingJsonExpression_thenResultIsValidJson() {
|
||||||
|
assertAll(
|
||||||
|
() -> assertThatNoException().isThrownBy(() -> objectMapper.readTree(Json.getExpression())),
|
||||||
|
() -> assertThat(Json.getExpression()).isNotBlank()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class MethodInvocationUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingNameFromExpression_thenResultNotEmpty() {
|
||||||
|
assertThat(MethodInvocation.getNameFromMethod()).isNotBlank();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingNameFromMethod_thenResultNotEmpty() {
|
||||||
|
assertThat(MethodInvocation.getNameFromExpression()).isNotBlank();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class MethodInvocationWithParamsUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingDurationFromExpression_thenResultNotEmpty() {
|
||||||
|
assertThat(MethodInvocationWithParams.getDurationFromExpression()).isNotBlank();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingDurationFromMethod_thenResultNotNullAndInBoundaries() {
|
||||||
|
assertThat(MethodInvocationWithParams.getDurationFromMethod())
|
||||||
|
.isNotNull()
|
||||||
|
.isBetween(Duration.ofSeconds(MethodInvocationWithParams.MIN),
|
||||||
|
Duration.ofSeconds(MethodInvocationWithParams.MAX));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||||
|
|
||||||
|
class MixedCollectionUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingMixedCollection_thenResultNotEmptyAndOfCorrectSize() {
|
||||||
|
assertAll(
|
||||||
|
() -> assertThat(MixedCollection.getMixedCollection()).isNotEmpty(),
|
||||||
|
() -> assertThat(MixedCollection.getMixedCollection()).size().isGreaterThanOrEqualTo(MixedCollection.MIN),
|
||||||
|
() -> assertThat(MixedCollection.getMixedCollection()).size().isLessThanOrEqualTo(MixedCollection.MAX)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class OptionUnitTest {
|
||||||
|
@Test
|
||||||
|
void whenGettingThirdExpression_thenResultNotBlankAndMatchesRegex() {
|
||||||
|
assertThat(Option.getThirdExpression()).isNotBlank()
|
||||||
|
.matches("(Hi|Hello|Hey)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingSecondExpression_thenResultNotBlankAndMatchesRegex() {
|
||||||
|
assertThat(Option.getSecondExpression()).isNotBlank()
|
||||||
|
.matches("(1|2|3|4|\\*)");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingFirstExpression_thenResultNotBlankAndMatchesRegex() {
|
||||||
|
assertThat(Option.getFirstExpression()).isNotBlank()
|
||||||
|
.matches("(Hi|Hello|Hey)");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class RegexifyUnitTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingMethidExpression_thenResultNotBlankAndMatchesRegex() {
|
||||||
|
assertThat(Regexify.getMethodExpression()).isNotBlank()
|
||||||
|
.matches("[A-D]{4,10}");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingExpression_thenResultNotBlankAndMatchesRegex() {
|
||||||
|
assertThat(Regexify.getExpression()).isNotBlank()
|
||||||
|
.matches("(hello|bye|hey)");
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package com.baeldung.datafaker;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
class TemplatifyUnitTest {
|
||||||
|
@Test
|
||||||
|
void whenGettingPlaceholderExpression_thenResultNotBlankAndMatchesRegex() {
|
||||||
|
assertThat(Templatify.getExpressionWithPlaceholder()).isNotBlank()
|
||||||
|
.matches(".ight");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenGettingExpression_thenResultNotBlankAndMatchesRegex() {
|
||||||
|
assertThat(Templatify.getExpression()).isNotBlank()
|
||||||
|
.matches(".es.");
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user