Created random Relationship terms

This commit is contained in:
SS007979
2019-07-23 16:08:43 -04:00
parent e6f798f85e
commit 5bbfbeeb39
4 changed files with 112 additions and 0 deletions
@@ -89,6 +89,7 @@ public class Faker {
private final Animal animal;
private final BackToTheFuture backToTheFuture;
private final PrincessBride princessBride;
private final Relationships relationships;
public Faker() {
this(Locale.ENGLISH);
@@ -179,6 +180,7 @@ public class Faker {
this.animal = new Animal(this);
this.backToTheFuture = new BackToTheFuture(this);
this.princessBride = new PrincessBride(this);
this.relationships = new Relationships(this);
}
/**
@@ -585,6 +587,10 @@ public class Faker {
return princessBride;
}
public Relationships relationships() {
return relationships;
}
public String resolve(String key) {
return this.fakeValuesService.resolve(key, this, this);
}
@@ -0,0 +1,59 @@
package com.github.javafaker;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
public class Relationships {
private final Faker faker;
protected Relationships(final Faker faker) {
this.faker = faker;
}
public String direct() {
return faker.resolve("relationship.familial.direct");
}
public String extended() {
return faker.resolve("relationship.familial.extended");
}
public String in_law() {
return faker.resolve("relationship.in_law");
}
public String spouse() {
return faker.resolve("relationship.spouse");
}
public String parent() {
return faker.resolve("relationship.parent");
}
public String sibling() {
return faker.resolve("relationship.sibling");
}
public String any() {
String[] relationships = new String[] {"direct", "extended", "in_law", "spouse",
"parent", "sibling"};
int idx = faker.random().nextInt(relationships.length);
String methodName = relationships[idx];
try {
Method m = Relationships.class.getMethod(methodName);
Relationships relInstance = new Relationships(faker);
return (String)m.invoke(relInstance);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (SecurityException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
return null;
}
}
@@ -0,0 +1,46 @@
package com.github.javafaker;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static org.hamcrest.core.IsNot.not;
import static org.junit.Assert.assertThat;
import org.junit.Test;
public class RelationshipTest extends AbstractFakerTest {
@Test
public void anyTest() {
assertThat(faker.relationships().any(), not(isEmptyOrNullString()));
}
@Test
public void directTest() {
assertThat(faker.relationships().direct(), not(isEmptyOrNullString()));
}
@Test
public void extendedTest() {
assertThat(faker.relationships().extended(), not(isEmptyOrNullString()));
}
@Test
public void in_lawTest() {
assertThat(faker.relationships().in_law(), not(isEmptyOrNullString()));
}
@Test
public void spouseTest() {
assertThat(faker.relationships().spouse(), not(isEmptyOrNullString()));
}
@Test
public void parentTest() {
assertThat(faker.relationships().parent(), not(isEmptyOrNullString()));
}
@Test
public void siblingTest() {
assertThat(faker.relationships().sibling(), not(isEmptyOrNullString()));
}
}
@@ -155,6 +155,7 @@ public class FakerIT {
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.animal());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.princessBride());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.elderScrolls());
testAllMethodsThatReturnStringsActuallyReturnStrings(faker.relationships());
}
private void testAllMethodsThatReturnStringsActuallyReturnStrings(Object object) throws Exception {