merged in app changes
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
package com.github.javafaker;
|
||||
|
||||
import com.github.javafaker.service.FakeValuesServiceInterface;
|
||||
|
||||
public class App {
|
||||
|
||||
private final Resolver resolver;
|
||||
private final FakeValuesServiceInterface fakeValuesService;
|
||||
|
||||
public App(Resolver resolver, FakeValuesServiceInterface fakeValuesService) {
|
||||
this.resolver = resolver;
|
||||
this.fakeValuesService = fakeValuesService;
|
||||
}
|
||||
|
||||
public String name() {
|
||||
return fakeValuesService.fetchString("app.name");
|
||||
}
|
||||
|
||||
public String version() {
|
||||
return fakeValuesService.numerify(fakeValuesService.fetchString("app.version"));
|
||||
}
|
||||
|
||||
public String author() {
|
||||
return fakeValuesService.resolve("app.name", this, resolver);
|
||||
}
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import java.util.Random;
|
||||
public class Faker implements Resolver {
|
||||
private final RandomService randomService;
|
||||
private final FakeValuesService fakeValuesService;
|
||||
private final App app;
|
||||
private final Lorem lorem;
|
||||
private final Name name;
|
||||
private final Number number;
|
||||
@@ -55,6 +56,7 @@ public class Faker implements Resolver {
|
||||
FakeValuesServiceInterface proxiedFakeValueService = createProxiedFakeValuesService(fakeValuesService,
|
||||
defaultEnglishFakeValuesService);
|
||||
|
||||
this.app = new App(this, proxiedFakeValueService);
|
||||
this.lorem = new Lorem(proxiedFakeValueService, randomService);
|
||||
this.name = new Name(this, proxiedFakeValueService);
|
||||
this.number = new Number(randomService);
|
||||
@@ -123,6 +125,10 @@ public class Faker implements Resolver {
|
||||
return fakeValuesService.regexify(regex);
|
||||
}
|
||||
|
||||
public App app() {
|
||||
return app;
|
||||
}
|
||||
|
||||
public Name name() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
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 AppTest {
|
||||
|
||||
private Faker faker;
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
faker = new Faker();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testName() {
|
||||
assertThat(faker.app().name(), matchesRegularExpression("\\w+"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testVersion() {
|
||||
assertThat(faker.app().version(), matchesRegularExpression("\\d\\.(\\d){1,2}(\\.\\d)?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAuthor() {
|
||||
assertThat(faker.app().author(), matchesRegularExpression("([\\w']+[-& ]?){2,9}"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user