Merge pull request #67 from PascalSchumacher/add_book

Add book
This commit is contained in:
Ricky Yim
2016-04-15 09:12:16 +10:00
5 changed files with 75 additions and 2 deletions
@@ -0,0 +1,29 @@
package com.github.javafaker;
import com.github.javafaker.service.FakeValuesServiceInterface;
public class Book {
private final FakeValuesServiceInterface fakeValuesService;
private final Resolver resolver;
public Book(Resolver resolver, FakeValuesServiceInterface fakeValuesService) {
this.fakeValuesService = fakeValuesService;
this.resolver = resolver;
}
public String author() {
return fakeValuesService.resolve("book.author", this, resolver);
}
public String title() {
return fakeValuesService.fetchString("book.title");
}
public String publisher() {
return fakeValuesService.fetchString("book.publisher");
}
public String genre() {
return fakeValuesService.fetchString("book.genre");
}
}
@@ -26,6 +26,7 @@ public class Faker implements Resolver {
private final PhoneNumber phoneNumber;
private final Address address;
private final Business business;
private final Book book;
private final Company company;
private final Options options;
private final Code code;
@@ -56,6 +57,7 @@ public class Faker implements Resolver {
this.internet = new Internet(name, proxiedFakeValueService, randomService);
this.phoneNumber = new PhoneNumber(proxiedFakeValueService);
this.address = new Address(this, name, proxiedFakeValueService, randomService);
this.book = new Book(this, proxiedFakeValueService);
this.business = new Business(proxiedFakeValueService);
this.company = new Company(this, proxiedFakeValueService);
this.options = new Options(randomService);
@@ -128,6 +130,10 @@ public class Faker implements Resolver {
return address;
}
public Book book() {
return book;
}
public Business business() {
return business;
}
File diff suppressed because one or more lines are too long
@@ -0,0 +1,37 @@
package com.github.javafaker;
import static com.github.javafaker.matchers.MatchesRegularExpression.matchesRegularExpression;
import static org.hamcrest.MatcherAssert.assertThat;
import org.junit.Before;
import org.junit.Test;
public class BookTest {
private Faker faker;
@Before
public void before() {
faker = new Faker();
}
@Test
public void testTitle() {
assertThat(faker.book().title(), matchesRegularExpression("([\\p{L}'\\-\\?]+[!,]? ?){2,9}"));
}
@Test
public void testAuthor() {
assertThat(faker.book().author(), matchesRegularExpression("([\\w']+\\.? ?){2,3}"));
}
@Test
public void testPublisher() {
assertThat(faker.book().publisher(), matchesRegularExpression("([\\p{L}'&\\-]+[,.]? ?){1,5}"));
}
@Test
public void testGenre() {
assertThat(faker.book().genre(), matchesRegularExpression("([\\w/]+ ?){2,4}"));
}
}
@@ -73,6 +73,7 @@ public class FakerIT {
testAllMethodsThatReturnStringsActuallyReturnStrings(faker);
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.address());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.business());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.book());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.company());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.internet());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.lorem());