refactored tests to make all the boring tests in the IntegrationTest class
This commit is contained in:
@@ -58,6 +58,12 @@
|
||||
<version>4.11</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.9.9-RC1</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
@RunWith(value = Parameterized.class)
|
||||
public abstract class AbstractFakerTest {
|
||||
|
||||
private static final Locale FINNISH_LOCALE = new Locale("fi", "FI");
|
||||
protected static final Logger logger = LoggerFactory.getLogger(AbstractFakerTest.class);
|
||||
protected Faker faker;
|
||||
|
||||
public AbstractFakerTest(Locale locale, Random random) {
|
||||
if (locale != null && random != null) {
|
||||
faker = new Faker(locale, random);
|
||||
} else if (locale != null) {
|
||||
faker = new Faker(locale);
|
||||
} else if (random != null) {
|
||||
faker = new Faker(random);
|
||||
} else {
|
||||
faker = new Faker();
|
||||
}
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name = "testing locale {0} and random {1}")
|
||||
public static Collection<Object[]> data() {
|
||||
Object[][] data = new Object[][]{
|
||||
{Locale.ENGLISH, null},
|
||||
{Locale.FRENCH, null},
|
||||
{FINNISH_LOCALE, null},
|
||||
{Locale.ENGLISH, new Random()},
|
||||
{null, new Random()},
|
||||
{null, null}};
|
||||
return Arrays.asList(data);
|
||||
}
|
||||
}
|
||||
@@ -1,120 +1,21 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import static com.github.javafaker.matchers.IsANumber.isANumber;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
@RunWith(value = Parameterized.class)
|
||||
public class AddressTest extends AbstractFakerTest {
|
||||
public class AddressTest {
|
||||
|
||||
public AddressTest(Locale locale, Random random) {
|
||||
super(locale, random);
|
||||
}
|
||||
private static final Logger logger = LoggerFactory.getLogger(AddressTest.class);
|
||||
private Faker faker;
|
||||
|
||||
@Test
|
||||
public void testStreetName() {
|
||||
String streetName = faker.streetName();
|
||||
logger.info("Street name: " + streetName);
|
||||
assertNotNull(streetName);
|
||||
|
||||
streetName = faker.address().streetName();
|
||||
logger.info("Street name: " + streetName);
|
||||
assertNotNull(streetName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreetAddress() {
|
||||
String streetAddress = faker.streetAddress(true);
|
||||
logger.info("Street address: " + streetAddress);
|
||||
assertNotNull(streetAddress);
|
||||
|
||||
streetAddress = faker.address().streetAddress(true);
|
||||
logger.info("Street address: " + streetAddress);
|
||||
assertNotNull(streetAddress);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSecondaryAddress() {
|
||||
String secondaryAddress = faker.secondaryAddress();
|
||||
logger.info("Secondary address: " + secondaryAddress);
|
||||
assertNotNull(secondaryAddress);
|
||||
|
||||
secondaryAddress = faker.address().secondaryAddress();
|
||||
logger.info("Secondary address: " + secondaryAddress);
|
||||
assertNotNull(secondaryAddress);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testZipCode() {
|
||||
String zip = faker.zipCode();
|
||||
logger.info("Address zip code: " + zip);
|
||||
assertNotNull(zip);
|
||||
|
||||
zip = faker.address().zipCode();
|
||||
logger.info("Address zip code: " + zip);
|
||||
assertNotNull(zip);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStreetSuffix() {
|
||||
String streetSuffix = faker.streetSuffix();
|
||||
logger.info("Street suffix: " + streetSuffix);
|
||||
assertNotNull(streetSuffix);
|
||||
|
||||
streetSuffix = faker.address().streetSuffix();
|
||||
logger.info("Street suffix: " + streetSuffix);
|
||||
assertNotNull(streetSuffix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCitySuffix() {
|
||||
String citySuffix = faker.citySuffix();
|
||||
logger.info("City suffix: " + citySuffix);
|
||||
assertNotNull(citySuffix);
|
||||
|
||||
citySuffix = faker.address().citySuffix();
|
||||
logger.info("City suffix: " + citySuffix);
|
||||
assertNotNull(citySuffix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCityPrefix() {
|
||||
String cityPrefix = faker.cityPrefix();
|
||||
logger.info("City prefix: " + cityPrefix);
|
||||
assertNotNull(cityPrefix);
|
||||
|
||||
cityPrefix = faker.address().cityPrefix();
|
||||
logger.info("City prefix: " + cityPrefix);
|
||||
assertNotNull(cityPrefix);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStateAbbr() {
|
||||
String stateAbbr = faker.stateAbbr();
|
||||
logger.info("State abbr: " + stateAbbr);
|
||||
assertNotNull(stateAbbr);
|
||||
|
||||
stateAbbr = faker.address().stateAbbr();
|
||||
logger.info("State abbr: " + stateAbbr);
|
||||
assertNotNull(stateAbbr);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCountry() {
|
||||
String country = faker.country();
|
||||
logger.info("Country: " + country);
|
||||
assertNotNull(country);
|
||||
|
||||
country = faker.address().country();
|
||||
logger.info("Country: " + country);
|
||||
assertNotNull(country);
|
||||
@Before
|
||||
public void before() {
|
||||
faker = new Faker();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class BusinessTest extends AbstractFakerTest {
|
||||
|
||||
public BusinessTest(Locale locale, Random random) {
|
||||
super(locale, random);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreditCardNumber() {
|
||||
final String creditCardNumber = faker.business().creditCardNumber();
|
||||
logger.info("Credit card number is " + creditCardNumber);
|
||||
assertNotNull(creditCardNumber);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreditCardExpiry() {
|
||||
final String creditCardExpiry = faker.business().creditCardExpiry();
|
||||
logger.info("Credit card expiry is " + creditCardExpiry);
|
||||
assertNotNull(creditCardExpiry);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreditCardTypes() {
|
||||
final String creditCardType = faker.business().creditCardType();
|
||||
logger.info("Credit card type is " + creditCardType);
|
||||
assertNotNull(creditCardType);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class InternetTest extends AbstractFakerTest {
|
||||
|
||||
public InternetTest(Locale locale, Random random) {
|
||||
super(locale, random);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmailAddress() {
|
||||
String emailAddress = faker.emailAddress();
|
||||
logger.info("Test email address: " + emailAddress);
|
||||
assertNotNull(emailAddress);
|
||||
|
||||
emailAddress = faker.internet().emailAddress();
|
||||
logger.info("Test email address: " + emailAddress);
|
||||
assertNotNull(emailAddress);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,86 +1,17 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class LoremTest extends AbstractFakerTest {
|
||||
public class LoremTest {
|
||||
|
||||
public LoremTest(Locale locale, Random random) {
|
||||
super(locale, random);
|
||||
}
|
||||
private Faker faker;
|
||||
|
||||
@Test
|
||||
public void testSpecifiedNumOfWords() {
|
||||
List<String> words = faker.words(4);
|
||||
logger.info("Test words: " + words.toString());
|
||||
assertEquals(4, words.size());
|
||||
|
||||
words = faker.lorem().words(4);
|
||||
logger.info("Test words: " + words.toString());
|
||||
assertEquals(4, words.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSentence() {
|
||||
String sentence = faker.sentence(7);
|
||||
logger.info("Test sentence: " + sentence);
|
||||
assertNotNull(sentence);
|
||||
|
||||
sentence = faker.lorem().sentence(7);
|
||||
logger.info("Test sentence: " + sentence);
|
||||
assertNotNull(sentence);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSentences() {
|
||||
List<String> sentences = faker.sentences(3);
|
||||
logger.info("Test sentences: " + sentences);
|
||||
assertEquals(3, sentences.size());
|
||||
|
||||
sentences = faker.lorem().sentences(3);
|
||||
logger.info("Test sentences: " + sentences);
|
||||
assertEquals(3, sentences.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecifiedNumOfParagraphs() {
|
||||
String paragraph = faker.paragraph(5);
|
||||
logger.info("Test paragraph: " + paragraph);
|
||||
assertNotNull(paragraph);
|
||||
|
||||
paragraph = faker.lorem().paragraph(5);
|
||||
logger.info("Test paragraph: " + paragraph);
|
||||
assertNotNull(paragraph);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParagraph() {
|
||||
String paragraph = faker.paragraph();
|
||||
logger.info("Paragraph: " + paragraph);
|
||||
assertNotNull(paragraph);
|
||||
|
||||
paragraph = faker.lorem().paragraph();
|
||||
logger.info("Paragraph: " + paragraph);
|
||||
assertNotNull(paragraph);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParagraphs() {
|
||||
final int paragraphCount = 10;
|
||||
List<String> paragraphs = faker.paragraphs(paragraphCount);
|
||||
logger.info("Paragraphs: " + paragraphs);
|
||||
assertEquals(paragraphCount, paragraphs.size());
|
||||
|
||||
paragraphs = faker.lorem().paragraphs(paragraphCount);
|
||||
logger.info("Paragraphs: " + paragraphs);
|
||||
assertEquals(paragraphCount, paragraphs.size());
|
||||
@Before
|
||||
public void before() {
|
||||
faker = new Faker();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class NameTest extends AbstractFakerTest {
|
||||
public NameTest(Locale locale, Random random) {
|
||||
super(locale, random);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNames() {
|
||||
String fullName = faker.name().fullName();
|
||||
logger.info("Test full name: " + fullName);
|
||||
assertNotNull(fullName);
|
||||
|
||||
String firstName = faker.firstName();
|
||||
logger.info("Test first name: " + firstName);
|
||||
assertNotNull(firstName);
|
||||
|
||||
firstName = faker.name().firstName();
|
||||
logger.info("Test first name: " + firstName);
|
||||
assertNotNull(firstName);
|
||||
|
||||
String lastName = faker.lastName();
|
||||
logger.info("Test last name: " + lastName);
|
||||
assertNotNull(lastName);
|
||||
|
||||
lastName = faker.name().lastName();
|
||||
logger.info("Test last name: " + lastName);
|
||||
assertNotNull(lastName);
|
||||
|
||||
String prefix = faker.prefix();
|
||||
logger.info("Test prefix: " + prefix);
|
||||
assertNotNull(prefix);
|
||||
|
||||
prefix = faker.name().prefix();
|
||||
logger.info("Test prefix: " + prefix);
|
||||
assertNotNull(prefix);
|
||||
|
||||
String suffix = faker.suffix();
|
||||
logger.info("Test suffix: " + suffix);
|
||||
assertNotNull(suffix);
|
||||
|
||||
suffix = faker.name().suffix();
|
||||
logger.info("Test suffix: " + suffix);
|
||||
assertNotNull(suffix);
|
||||
|
||||
String name = faker.name().name();
|
||||
logger.info("Test name: " + name);
|
||||
assertNotNull(name);
|
||||
}
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class PhoneNumberTest extends AbstractFakerTest {
|
||||
public PhoneNumberTest(Locale locale, Random random) {
|
||||
super(locale, random);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPhoneNumber() {
|
||||
String phoneNumber = faker.phoneNumber().phoneNumber();
|
||||
logger.info("Phone number: " + phoneNumber);
|
||||
assertNotNull(phoneNumber);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,114 @@
|
||||
package com.github.javafaker.integration;
|
||||
|
||||
import com.github.javafaker.Faker;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Locale;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.IsNull.notNullValue;
|
||||
import static org.reflections.ReflectionUtils.getAllMethods;
|
||||
import static org.reflections.ReflectionUtils.withModifier;
|
||||
import static org.reflections.ReflectionUtils.withParametersCount;
|
||||
import static org.reflections.ReflectionUtils.withReturnType;
|
||||
|
||||
/**
|
||||
* The purpose of these tests is to ensure that the Locales have been properly configured
|
||||
* and that methods return values. The unit tests should ensure what the values returned
|
||||
* are correct. These tests just ensure that the methods can be invoked.
|
||||
*/
|
||||
@RunWith(value = Parameterized.class)
|
||||
public class FakerIntegrationTest {
|
||||
|
||||
private static final Locale FINNISH_LOCALE = new Locale("fi", "FI");
|
||||
private static final Logger logger = LoggerFactory.getLogger(FakerIntegrationTest.class);
|
||||
private Faker faker;
|
||||
|
||||
public FakerIntegrationTest(Locale locale, Random random) {
|
||||
if (locale != null && random != null) {
|
||||
faker = new Faker(locale, random);
|
||||
} else if (locale != null) {
|
||||
faker = new Faker(locale);
|
||||
} else if (random != null) {
|
||||
faker = new Faker(random);
|
||||
} else {
|
||||
faker = new Faker();
|
||||
}
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name = "testing locale {0} and random {1}")
|
||||
public static Collection<Object[]> data() {
|
||||
Object[][] data = new Object[][]{
|
||||
{Locale.ENGLISH, null},
|
||||
{Locale.FRENCH, null},
|
||||
{FINNISH_LOCALE, null},
|
||||
{Locale.ENGLISH, new Random()},
|
||||
{null, new Random()},
|
||||
{null, null}};
|
||||
return Arrays.asList(data);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAllFakerMethodsThatReturnStrings() throws Exception {
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker);
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.address());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.business());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.internet());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.lorem());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.phoneNumber());
|
||||
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.name());
|
||||
}
|
||||
|
||||
|
||||
private void testAllMethodsThatReturnStringsActuallyReturnStrings(Object object) throws IllegalAccessException, InvocationTargetException {
|
||||
Set<Method> methodsThatReturnStrings = getAllMethods(object.getClass(),
|
||||
withModifier(Modifier.PUBLIC),
|
||||
withReturnType(String.class),
|
||||
withParametersCount(0));
|
||||
|
||||
for (Method method : methodsThatReturnStrings) {
|
||||
final Object returnValue = method.invoke(object);
|
||||
|
||||
logger.info(String.format("Invoked %s.%s and got this value back %s", object.getClass().getSimpleName(), method.getName(), returnValue));
|
||||
assertThat(returnValue, is(notNullValue()));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExceptionsNotCoveredInAboveTest() throws Exception {
|
||||
assertThat(faker.bothify("####???"), is(notNullValue()));
|
||||
assertThat(faker.letterify("????"), is(notNullValue()));
|
||||
assertThat(faker.numerify("####"), is(notNullValue()));
|
||||
|
||||
assertThat(faker.paragraph(1), is(notNullValue()));
|
||||
assertThat(faker.lorem().paragraph(1), is(notNullValue()));
|
||||
|
||||
assertThat(faker.paragraphs(1), is(notNullValue()));
|
||||
assertThat(faker.lorem().paragraphs(1), is(notNullValue()));
|
||||
|
||||
assertThat(faker.sentence(1), is(notNullValue()));
|
||||
assertThat(faker.lorem().sentence(1), is(notNullValue()));
|
||||
|
||||
assertThat(faker.sentences(1), is(notNullValue()));
|
||||
assertThat(faker.lorem().sentences(1), is(notNullValue()));
|
||||
|
||||
assertThat(faker.streetAddress(true), is(notNullValue()));
|
||||
assertThat(faker.address().streetAddress(true), is(notNullValue()));
|
||||
|
||||
assertThat(faker.words(1), is(notNullValue()));
|
||||
assertThat(faker.lorem().words(1), is(notNullValue()));
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user