This is an automated email from the ASF dual-hosted git repository.

sgoeschl pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git


The following commit(s) were added to refs/heads/master by this push:
     new 0f3b7d7  FREEMARKER-163 Integrate Java Faker library for test data 
generation (#23)
0f3b7d7 is described below

commit 0f3b7d72e27a925c631c29d808282e462a05d0ef
Author: Siegfried Goeschl <[email protected]>
AuthorDate: Mon Nov 9 20:15:30 2020 +0100

    FREEMARKER-163 Integrate Java Faker library for test data generation (#23)
---
 freemarker-generator-cli/CHANGELOG.md              |  4 +-
 .../src/app/config/freemarker-generator.properties |  3 +-
 .../examples/templates/javafaker/csv/testdata.ftl  | 45 +++++++++++++++
 .../src/app/scripts/run-examples.bat               |  6 ++
 .../src/app/scripts/run-examples.sh                |  7 +++
 .../markdown/cli/introduction/getting-started.md   | 61 ++++++++------------
 .../site/markdown/cli/usage/generating-testdata.md | 66 ++++++++++++++++++++++
 .../src/site/markdown/index.md                     |  1 +
 .../freemarker/generator/cli/ExamplesTest.java     |  5 ++
 freemarker-generator-tools/pom.xml                 |  6 ++
 .../generator/tools/javafaker/JavaFakerTool.java   | 63 +++++++++++++++++++++
 .../tools/javafaker/JavaFakerToolTest.java         | 60 ++++++++++++++++++++
 12 files changed, 287 insertions(+), 40 deletions(-)

diff --git a/freemarker-generator-cli/CHANGELOG.md 
b/freemarker-generator-cli/CHANGELOG.md
index d095c1c..549bd32 100644
--- a/freemarker-generator-cli/CHANGELOG.md
+++ b/freemarker-generator-cli/CHANGELOG.md
@@ -5,6 +5,7 @@ All notable changes to this project will be documented in this 
file. We try to a
 ## 0.1.0-SNAPSHOT
 
 ### Added
+* [FREEMARKER-163] Integrate Java Faker library for test data generation
 * [FREEMARKER-148] Make usage of "DataSources" more "Freemarker" like
 * [FREEMARKER-149] Support multiple template transformations on the command 
line
 * [FREEMARKER-144] Proof Of Concept for providing DataFrames
@@ -56,4 +57,5 @@ All notable changes to this project will be documented in 
this file. We try to a
 [FREEMARKER-149]: https://issues.apache.org/jira/browse/FREEMARKER-149
 [FREEMARKER-151]: https://issues.apache.org/jira/browse/FREEMARKER-151
 [FREEMARKER-153]: https://issues.apache.org/jira/browse/FREEMARKER-153
-[FREEMARKER-155]: https://issues.apache.org/jira/browse/FREEMARKER-155
\ No newline at end of file
+[FREEMARKER-155]: https://issues.apache.org/jira/browse/FREEMARKER-155
+[FREEMARKER-163]: https://issues.apache.org/jira/browse/FREEMARKER-163
\ No newline at end of file
diff --git 
a/freemarker-generator-cli/src/app/config/freemarker-generator.properties 
b/freemarker-generator-cli/src/app/config/freemarker-generator.properties
index fd4a8f9..25b7029 100644
--- a/freemarker-generator-cli/src/app/config/freemarker-generator.properties
+++ b/freemarker-generator-cli/src/app/config/freemarker-generator.properties
@@ -14,13 +14,11 @@
 ## See the License for the specific language governing permissions and
 ## limitations under the License.
 ## ---------------------------------------------------------------------------
-
 #############################################################################
 # General FreeMarker Configuration
 # See 
https://freemarker.apache.org/docs/api/freemarker/template/Configuration.html#setSetting-java.lang.String-java.lang.String-
 #############################################################################
 # freemarker.configuration.setting.locale=JVM default
-
 #############################################################################
 # Configure FreeMarker Tools (name -> implementation class)
 #############################################################################
@@ -31,6 +29,7 @@ 
freemarker.tools.exec=org.apache.freemarker.generator.tools.commonsexec.CommonsE
 
freemarker.tools.freemarker=org.apache.freemarker.generator.tools.freemarker.FreeMarkerTool
 freemarker.tools.grok=org.apache.freemarker.generator.tools.grok.GrokTool
 freemarker.tools.gson=org.apache.freemarker.generator.tools.gson.GsonTool
+freemarker.tools.javafaker=org.apache.freemarker.generator.tools.javafaker.JavaFakerTool
 
freemarker.tools.jsonpath=org.apache.freemarker.generator.tools.jsonpath.JsonPathTool
 freemarker.tools.jsoup=org.apache.freemarker.generator.tools.jsoup.JsoupTool
 
freemarker.tools.properties=org.apache.freemarker.generator.tools.properties.PropertiesTool
diff --git 
a/freemarker-generator-cli/src/app/examples/templates/javafaker/csv/testdata.ftl
 
b/freemarker-generator-cli/src/app/examples/templates/javafaker/csv/testdata.ftl
new file mode 100644
index 0000000..357a3ae
--- /dev/null
+++ 
b/freemarker-generator-cli/src/app/examples/templates/javafaker/csv/testdata.ftl
@@ -0,0 +1,45 @@
+<#--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+    http://www.apache.org/licenses/LICENSE-2.0
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<#assign faker = tools.javafaker.faker>
+<#assign nrOfRecords = tools.system.getString("NR_OF_RECORDS","10")>
+<#assign days = tools.javafaker.timeUnits["DAYS"]>
+<#assign csvTargetFormat = 
tools.csv.formats["DEFAULT"].withFirstRecordAsHeader()>
+<#assign csvPrinter = tools.csv.printer(csvTargetFormat)>
+<#assign csvHeaders = 
['ID','CUSTOMER_ID','FIRST_NAME','LAST_NAME','EMAIL','IBAN','CREATED_AT']>
+<#compress>
+    <#if csvTargetFormat.getSkipHeaderRecord()>
+        ${csvPrinter.printRecord(csvHeaders)}<#t>
+    </#if>
+    <#list 1..nrOfRecords?number as i>
+        <#assign id = tools.uuid.randomUUID()>
+        <#assign customerId = faker.bothify("?#######")>
+        <#assign firstName = faker.name().firstName()>
+        <#assign lastName = faker.name().lastName()>
+        <#assign email = firstName + "." + lastName + "@gmail.com">
+        <#assign iban = faker.finance().iban("DE")>
+
+        <#assign createAt = faker.date().past(3650, days)>
+        ${csvPrinter.printRecord(
+            id,
+            customerId,
+            firstName,
+            lastName,
+            email?lower_case
+            iban,
+            createAt?datetime?iso_local)}
+    </#list>
+</#compress>
diff --git a/freemarker-generator-cli/src/app/scripts/run-examples.bat 
b/freemarker-generator-cli/src/app/scripts/run-examples.bat
index c472333..4bb5e5e 100644
--- a/freemarker-generator-cli/src/app/scripts/run-examples.bat
+++ b/freemarker-generator-cli/src/app/scripts/run-examples.bat
@@ -127,6 +127,12 @@ echo "examples\templates\html\txt\licence.ftl"
 %FREEMARKER_CMD% -t examples\templates\html\txt\licence.ftl 
examples\data\html\dependencies.html > target\out\licence.txt
 
 REM =========================================================================
+REM Java Faker
+REM =========================================================================
+echo "examples/templates/javafaker/csv/testdata.ftl"
+%FREEMARKER_CMD% -t examples/templates/javafaker/csv/testdata.ftl > 
target/out/testdata.csv
+
+REM =========================================================================
 REM JSON
 REM =========================================================================
 
diff --git a/freemarker-generator-cli/src/app/scripts/run-examples.sh 
b/freemarker-generator-cli/src/app/scripts/run-examples.sh
index 89f86e7..316a098 100755
--- a/freemarker-generator-cli/src/app/scripts/run-examples.sh
+++ b/freemarker-generator-cli/src/app/scripts/run-examples.sh
@@ -147,6 +147,13 @@ echo "examples/templates/html/txt/licence.ftl"
 $FREEMARKER_CMD -t examples/templates/html/txt/licence.ftl 
examples/data/html/dependencies.html > target/out/licence.txt || { echo >&2 
"Test failed.  Aborting."; exit 1; }
 
 #############################################################################
+# Java Faker
+#############################################################################
+
+echo "examples/templates/javafaker/csv/testdata.ftl"
+$FREEMARKER_CMD -t examples/templates/javafaker/csv/testdata.ftl > 
target/out/testdata.csv || { echo >&2 "Test failed.  Aborting."; exit 1; }
+
+#############################################################################
 # JSON
 #############################################################################
 
diff --git 
a/freemarker-generator-cli/src/site/markdown/cli/introduction/getting-started.md
 
b/freemarker-generator-cli/src/site/markdown/cli/introduction/getting-started.md
index 74deace..f1bc312 100644
--- 
a/freemarker-generator-cli/src/site/markdown/cli/introduction/getting-started.md
+++ 
b/freemarker-generator-cli/src/site/markdown/cli/introduction/getting-started.md
@@ -91,53 +91,40 @@ to better understand `Apache FreeMarker Generator`
 FreeMarker Generator Information
 ------------------------------------------------------------------------------
 FreeMarker version     : 2.3.30
-Template name          : templates/info.ftl
+Template name          : info.ftl
 Language               : en
 Locale                 : en_US
-Timestamp              : Jun 26, 2020 10:44:15 AM
+Timestamp              : Nov 9, 2020 1:13:21 PM
 Output encoding        : UTF-8
 Output format          : plainText
 
 FreeMarker Generator Template Loader Directories
 ------------------------------------------------------------------------------
-[#1] /Users/sgoeschl/work/github/apache/freemarker-generator
-[#2] /Users/sgoeschl/.freemarker-generator
-[#3] /Applications/Java/freemarker-generator-2.0.0
-
-FreeMarker Generator Tools
-------------------------------------------------------------------------------
-- CSVTool              : Process CSV files using Apache Commons CSV (see 
https://commons.apache.org/proper/commons-csv/)
-- DataFrameTool        : Bridge to 
[nRo/DataFrame](https://github.com/nRo/DataFrame)
-- ExcelTool            : Process Excels files (XLS, XLSX) using Apache POI 
(see https://poi.apache.org)
-- ExecTool             : Execute command line tools using Apache Commons Exec 
(see https://commons.apache.org/proper/commons-exec/)
-- FreeMarkerTool       : Expose advanced Apache FreeMarker classes
-- GrokTool             : Process text files using Grok expressions (see 
https://github.com/thekrakken/java-grok)
-- GsonTool             : Process JSON files using GSON (see 
https://github.com/google/gson)
-- JsonPathTool         : Process JSON files using Java JSON Path (see 
https://github.com/json-path/JsonPath)
-- JsoupTool            : Process  HTML files using Jsoup (see 
https://jsoup.org)
-- PropertiesTool       : Process JDK properties files
-- SystemTool           : Expose System-related utility methods
-- UUIDTool             : Create UUIDs
-- XmlTool              : Process XML files using Apache FreeMarker (see 
https://freemarker.apache.org/docs/xgui.html)
-- YamlTool             : Process YAML files using SnakeYAML(see 
https://bitbucket.org/asomov/snakeyaml/wiki/Home)
+[#1] /Users/sgoeschl/.freemarker-generator/templates
+[#2] 
/Users/sgoeschl/work/github/apache/freemarker-generator/freemarker-generator-cli/target/appassembler/templates
 
 FreeMarker Generator Data Model
 ---------------------------------------------------------------------------
-- CSVTool
-- DataFrameTool
-- DataSources
-- ExcelTool
-- ExecTool
-- FreeMarkerTool
-- GrokTool
-- GsonTool
-- JsonPathTool
-- JsoupTool
-- PropertiesTool
-- SystemTool
-- UUIDTool
-- XmlTool
-- YamlTool
+- dataSources
+- tools
+
+FreeMarker Generator Tools
+------------------------------------------------------------------------------
+- csv                  : Process CSV files using Apache Commons CSV (see 
https://commons.apache.org/proper/commons-csv/)
+- dataframe            : Bridge to 
[nRo/DataFrame](https://github.com/nRo/DataFrame)
+- excel                : Process Excels files (XLS, XLSX) using Apache POI 
(see https://poi.apache.org)
+- exec                 : Execute command line tools using Apache Commons Exec 
(see https://commons.apache.org/proper/commons-exec/)
+- freemarker           : Expose advanced Apache FreeMarker classes
+- grok                 : Process text files using Grok expressions (see 
https://github.com/thekrakken/java-grok)
+- gson                 : Process JSON files using GSON (see 
https://github.com/google/gson)
+- javafaker            : Generate test data using Java Faker (see 
https://github.com/DiUS/java-faker)
+- jsonpath             : Process JSON files using Java JSON Path (see 
https://github.com/json-path/JsonPath)
+- jsoup                : Process  HTML files using Jsoup (see 
https://jsoup.org)
+- properties           : Process JDK properties files
+- system               : Expose System-related utility methods
+- uuid                 : Create UUIDs
+- xml                  : Process XML files using Apache FreeMarker (see 
https://freemarker.apache.org/docs/xgui.html)
+- yaml                 : Process YAML files using SnakeYAML(see 
https://bitbucket.org/asomov/snakeyaml/wiki/Home)
 ```
 
 * The "FreeMarker Generator Information" section provides insights into 
configuration and currently processed template.
diff --git 
a/freemarker-generator-cli/src/site/markdown/cli/usage/generating-testdata.md 
b/freemarker-generator-cli/src/site/markdown/cli/usage/generating-testdata.md
new file mode 100644
index 0000000..33e2fc7
--- /dev/null
+++ 
b/freemarker-generator-cli/src/site/markdown/cli/usage/generating-testdata.md
@@ -0,0 +1,66 @@
+## Generating Test Data
+
+The generation of test data is supported by [Java 
Faker](https://github.com/DiUS/java-faker).
+
+Let's assume that you need to populate a user table based on a CSV file with 
random data
+
+```
+freemarker-generator -DNR_OF_RECORDS=10 -t 
src/app/examples/templates/javafaker/csv/testdata.ftl
+```  
+
+will generate
+
+```
+ID,CUSTOMER_ID,FIRST_NAME,LAST_NAME,EMAIL,IBAN,CREATED_AT
+5c3dbf2b-2957-41fe-8566-e16c91d6bba7,e6044780,Audrey,Ryan,[email protected],DE69137185182464804325,2016-07-25T03:06:54+02:00
+34671167-92f8-46e3-874b-d488960eb320,z8394366,Herb,Lehner,[email protected],DE32993443443552974345,2019-10-11T23:27:32+02:00
+479855f6-cc98-4c46-99e4-b1d38d35a7b2,x8937857,Kirby,Wilkinson,[email protected],DE12566901129220359287,2020-04-12T04:49:00+02:00
+1a3c51b9-d168-4c0a-84ae-05e79cd181b1,t3486957,Charmaine,Bergstrom,[email protected],DE98964063811726229158,2015-07-24T23:19:19+02:00
+43b9f7ad-1aec-44ff-b3c1-de7688b5a729,z9190225,Sterling,Glover,[email protected],DE47207633748672977993,2019-11-04T04:45:06+01:00
+34ce2c9f-e5bb-44f4-a71f-40b0dfa8d0bf,a4406167,George,Marquardt,[email protected],DE79342449317255392445,2016-05-15T16:33:05+02:00
+1f9bbc16-8b17-4947-ab50-4abf6aa4cc46,s6438445,Arnoldo,Herzog,[email protected],DE20421444995381411375,2013-10-12T07:01:01+02:00
+30e3f7a2-7fe8-4ebf-b46b-4f59ab62ba45,o9507275,Nickie,Predovic,[email protected],DE06666930299990216198,2019-08-01T10:51:51+02:00
+f703e93e-7bc3-42c9-a7f5-f1db84d32fd1,z8385157,Clinton,Murphy,[email protected],DE27305002168865903990,2018-04-01T19:03:55+02:00
+7f6a8d29-2dfc-4467-b366-25b46aa5bc32,x5244747,Johnson,Blanda,[email protected],DE83757301199253406795,2012-06-23T18:04:38+02:00
+```
+
+using the following FreeMarker template
+
+```
+<#assign faker = tools.javafaker.faker>
+<#assign nrOfRecords = tools.system.getString("NR_OF_RECORDS","10")>
+<#assign days = tools.javafaker.timeUnits["DAYS"]>
+<#assign csvTargetFormat = 
tools.csv.formats["DEFAULT"].withFirstRecordAsHeader()>
+<#assign csvPrinter = tools.csv.printer(csvTargetFormat)>
+<#assign csvHeaders = 
['ID','CUSTOMER_ID','FIRST_NAME','LAST_NAME','EMAIL','IBAN','CREATED_AT']>
+<#compress>
+    <#if csvTargetFormat.getSkipHeaderRecord()>
+        ${csvPrinter.printRecord(csvHeaders)}<#t>
+    </#if>
+    <#list 1..nrOfRecords?number as i>
+        <#assign id = tools.uuid.randomUUID()>
+        <#assign customerId = faker.bothify("?#######")>
+        <#assign firstName = faker.name().firstName()>
+        <#assign lastName = faker.name().lastName()>
+        <#assign email = firstName + "." + lastName + "@gmail.com">
+        <#assign iban = faker.finance().iban("DE")>
+
+        <#assign createAt = faker.date().past(3650, days)>
+        ${csvPrinter.printRecord(
+            id,
+            customerId,
+            firstName,
+            lastName,
+            email?lower_case
+            iban,
+            createAt?datetime?iso_local)}
+    </#list>
+</#compress>
+```
+
+Some thoughts along the line
+
+* [Java Faker](https://github.com/DiUS/java-faker) does not create coherent 
test data, e.g. each invocation of "name" creates a new random name - hence we 
create the email address ourselves
+* The created IBAN does not use a valid bank code but structure and checksum 
is correct
+* The "createdAt" generates a creation date from the last 10 years to have 
some proper distribution
+* See [A Guide to JavaFaker](https://www.baeldung.com/java-faker) for a quick 
overview
\ No newline at end of file
diff --git a/freemarker-generator-cli/src/site/markdown/index.md 
b/freemarker-generator-cli/src/site/markdown/index.md
index 1b33d5c..9a6ecc4 100644
--- a/freemarker-generator-cli/src/site/markdown/index.md
+++ b/freemarker-generator-cli/src/site/markdown/index.md
@@ -30,6 +30,7 @@
 * [Transforming Directories](cli/usage/transforming-directories.html)
 * [Using DataFrames](cli/usage/using-dataframes.html)
 * [Transforming CSV](cli/usage/transforming-csv.html)
+* [Generating Test Data](cli/usage/generating-testdata.html)
 
 ### Advanced Topics
 
diff --git 
a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java
 
b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java
index a2e7c79..045bb42 100644
--- 
a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java
+++ 
b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java
@@ -113,6 +113,11 @@ public class ExamplesTest extends AbstractMainTest {
     }
 
     @Test
+    public void shouldRunJavaFakerExamples() throws IOException {
+        assertValid(execute("-t 
src/app/examples/templates/javafaker/csv/testdata.ftl"));
+    }
+
+    @Test
     public void shouldRunInteractiveTemplateExamples() throws IOException {
         assertValid(execute("-i 
${tools.jsonpath.parse(dataSources?values[0]).read(\"$.info.title\")} 
src/app/examples/data/json/swagger-spec.json"));
         assertValid(execute("-i 
${tools.xml.parse(dataSources?values[0])[\"recipients/person[1]/name\"]} 
src/app/examples/data/xml/recipients.xml"));
diff --git a/freemarker-generator-tools/pom.xml 
b/freemarker-generator-tools/pom.xml
index 2d590a2..c533a6d 100644
--- a/freemarker-generator-tools/pom.xml
+++ b/freemarker-generator-tools/pom.xml
@@ -93,6 +93,12 @@
             <artifactId>gson</artifactId>
             <version>2.8.6</version>
         </dependency>
+        <!-- Java Faker -->
+        <dependency>
+            <groupId>com.github.javafaker</groupId>
+            <artifactId>javafaker</artifactId>
+            <version>1.0.2</version>
+        </dependency>
         <!-- JsonPath Tool -->
         <dependency>
             <groupId>com.jayway.jsonpath</groupId>
diff --git 
a/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/javafaker/JavaFakerTool.java
 
b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/javafaker/JavaFakerTool.java
new file mode 100644
index 0000000..c5ee43a
--- /dev/null
+++ 
b/freemarker-generator-tools/src/main/java/org/apache/freemarker/generator/tools/javafaker/JavaFakerTool.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.freemarker.generator.tools.javafaker;
+
+import com.github.javafaker.Faker;
+import org.apache.freemarker.generator.base.util.LocaleUtils;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+
+public class JavaFakerTool {
+
+    /**
+     * @return Java Faker instance with default locale
+     */
+    public Faker getFaker() {
+        return getFaker(Locale.getDefault());
+    }
+
+    public Faker getFaker(String localeString) {
+        return getFaker(LocaleUtils.parseLocale(localeString));
+    }
+
+    public Faker getFaker(Locale locale) {
+        return new Faker(locale);
+    }
+
+    public Map<String, TimeUnit> getTimeUnits() {
+        return createTimeUnitMap();
+    }
+
+    @Override
+    public String toString() {
+        return "Generate test data using Java Faker (see 
https://github.com/DiUS/java-faker)";
+    }
+
+    private static Map<String, TimeUnit> createTimeUnitMap() {
+        final Map<String, TimeUnit> result = new HashMap<>();
+        result.put("MICROSECONDS", TimeUnit.MICROSECONDS);
+        result.put("MILLISECONDS", TimeUnit.MILLISECONDS);
+        result.put("SECONDS", TimeUnit.SECONDS);
+        result.put("MINUTES", TimeUnit.MINUTES);
+        result.put("HOURS", TimeUnit.HOURS);
+        result.put("DAYS", TimeUnit.DAYS);
+        return result;
+    }
+}
diff --git 
a/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/javafaker/JavaFakerToolTest.java
 
b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/javafaker/JavaFakerToolTest.java
new file mode 100644
index 0000000..d54395c
--- /dev/null
+++ 
b/freemarker-generator-tools/src/test/java/org/apache/freemarker/generator/tools/javafaker/JavaFakerToolTest.java
@@ -0,0 +1,60 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.freemarker.generator.tools.javafaker;
+
+import com.github.javafaker.Faker;
+import org.junit.Test;
+
+import java.util.Locale;
+import java.util.concurrent.TimeUnit;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+public class JavaFakerToolTest {
+
+    private final Faker faker = javaFakerTool().getFaker();
+
+    @Test
+    public void shouldCreateFakerFromLocale() {
+        assertNotNull(new JavaFakerTool().getFaker(Locale.ENGLISH));
+    }
+
+    @Test
+    public void shouldCreateFakerFromLocaleString() {
+        assertNotNull(new JavaFakerTool().getFaker("de-DE"));
+    }
+
+    @Test
+    public void shouldCreateFakeData() {
+        assertFalse(faker.name().fullName().isEmpty());
+        assertFalse(faker.internet().emailAddress().isEmpty());
+        assertNotNull(faker.date().past(12, TimeUnit.DAYS));
+        assertTrue(faker.finance().iban("AT").startsWith("AT"));
+    }
+
+    @Test
+    public void shouldGetTimeUnits() {
+        assertEquals(6, javaFakerTool().getTimeUnits().size());
+    }
+
+    private static JavaFakerTool javaFakerTool() {
+        return new JavaFakerTool();
+    }
+}

Reply via email to