Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ First and foremost thanks to anyone who contributes, very much appreciated.


## Guidelines
- Need to maintain compatibility with Java 1.6 (and Android). Therefore any attempt to migrate to 1.6 JDKs and above will not be merged back in.
- The minimum supported Java version is **1.8**. Please keep source/target compatibility at Java 1.8 and avoid APIs introduced in later JDKs. This baseline was raised from 1.6 so the project can stay on maintained dependency versions (for example `snakeyaml` 2.x, which requires Java 8+). Android is still supported on API levels that provide Java 8 language features (via desugaring), so no Android-specific artifact/classifier is required anymore.

- If you add new faker classes like `Address`, `Country`, and `Number` they should be accompanied by a unit test. Where relevant please add more assertions to the `com.github.javafaker.integration.FakerIT` class.
- If you add a new faker class, update the `README.md`.
Expand All @@ -13,3 +13,4 @@ First and foremost thanks to anyone who contributes, very much appreciated.
## Building

- Should be as easy as running `mvn clean install` on the root directory
- Requires a JDK 8 or newer to build
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ Java Faker
This library is a port of Ruby's [faker](https://github.com/stympy/faker) gem (as well as Perl's Data::Faker library) that generates fake data.
It's useful when you're developing a new project and need some pretty data for showcase.

Requirements
-----
* Java 1.8 or newer.
* Android is supported on API levels that enable Java 8 language features (via [desugaring](https://developer.android.com/studio/write/java8-support)).

Usage
-----
In pom.xml, add the following xml stanza between `<dependencies> ... </dependencies>`
Expand Down
7 changes: 3 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,7 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.26</version>
<classifier>android</classifier>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.github.mifmif</groupId>
Expand Down Expand Up @@ -112,8 +111,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down
28 changes: 28 additions & 0 deletions src/test/java/com/github/javafaker/service/FakeValuesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import org.junit.Before;
import org.junit.Test;

import java.util.List;
import java.util.Locale;
import java.util.Map;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.Matchers.*;
Expand Down Expand Up @@ -58,4 +60,30 @@ public void getAValueFromALocaleThatCantBeLoaded() {
assertThat(fakeValues.get(PATH), is(nullValue()));
}

@Test
public void getReturnsAMapForALoadedPath() {
assertThat(fakeValues.get(PATH), is(instanceOf(Map.class)));
}

@Test
public void yamlSequencesAreLoadedAsLists() {
Map<String, Object> address = (Map<String, Object>) fakeValues.get(PATH);
Object cityPrefix = address.get("city_prefix");
assertThat(cityPrefix, is(instanceOf(List.class)));
assertThat((List<String>) cityPrefix, hasItem("North"));
}

@Test
public void nestedYamlMappingsAreLoadedAsMaps() {
Map<String, Object> address = (Map<String, Object>) fakeValues.get(PATH);
Object countryByCode = address.get("country_by_code");
assertThat(countryByCode, is(instanceOf(Map.class)));
assertThat((Map<String, String>) countryByCode, hasEntry("AF", "Afghanistan"));
}

@Test
public void getIsCachedAcrossInvocations() {
assertThat(fakeValues.get(PATH), is(sameInstance(fakeValues.get(PATH))));
}

}