Skip to content

Commit

Permalink
Day095
Browse files Browse the repository at this point in the history
  • Loading branch information
hbelmiro committed Aug 22, 2021
1 parent 6c0f0d0 commit 573d5a8
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 0 deletions.
47 changes: 47 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -3612,4 +3612,51 @@ public class Day094 {
}
}
}
----

== Day 95 - Using Java-faker to create fake data for testing.
[source,java]
----
package com.thegreatapi.ahundreddaysofjava.day095;
import com.github.javafaker.Faker;
import java.util.Date;
import java.util.List;
import java.util.stream.IntStream;
public class Day095 {
private static final Faker FAKER = new Faker();
public static void main(String[] args) {
List<Person> people = IntStream.rangeClosed(1, 10)
.mapToObj(i -> createPerson())
.toList();
people.forEach(System.out::println);
// Person[firstName=Randall, lastName=Oberbrunner, dateOfBirth=Tue Oct 02 06:16:54 BRT 1962]
// Person[firstName=Thanh, lastName=Lemke, dateOfBirth=Fri Feb 28 10:54:57 BRST 1964]
// Person[firstName=Walker, lastName=Waters, dateOfBirth=Fri Feb 21 16:55:01 BRT 1992]
// Person[firstName=Colin, lastName=Koelpin, dateOfBirth=Wed Jul 28 15:03:17 BRT 1982]
// Person[firstName=Velia, lastName=Corwin, dateOfBirth=Thu Nov 07 06:41:49 BRT 1974]
// Person[firstName=Dwayne, lastName=Wilkinson, dateOfBirth=Mon Apr 24 16:38:56 BRT 1972]
// Person[firstName=Lynn, lastName=Oberbrunner, dateOfBirth=Tue Mar 11 09:29:37 BRT 2003]
// Person[firstName=Cristie, lastName=Yundt, dateOfBirth=Thu Sep 04 05:28:06 BRT 1980]
// Person[firstName=Brynn, lastName=Tremblay, dateOfBirth=Thu Nov 03 10:28:57 BRST 1988]
// Person[firstName=Ahmad, lastName=Homenick, dateOfBirth=Tue Apr 19 15:46:28 BRT 1977]
}
private static Person createPerson() {
return new Person(
FAKER.name().firstName(),
FAKER.name().lastName(),
FAKER.date().birthday()
);
}
static record Person(String firstName, String lastName, Date dateOfBirth) {
}
}
----
27 changes: 27 additions & 0 deletions days/day095/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>days</artifactId>
<groupId>com.thegreatapi.100daysofjava</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>day095</artifactId>

<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.github.javafaker</groupId>
<artifactId>javafaker</artifactId>
<version>1.0.2</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.thegreatapi.ahundreddaysofjava.day095;

import com.github.javafaker.Faker;

import java.util.Date;
import java.util.List;
import java.util.stream.IntStream;

public class Day095 {

private static final Faker FAKER = new Faker();

public static void main(String[] args) {
List<Person> people = IntStream.rangeClosed(1, 10)
.mapToObj(i -> createPerson())
.toList();

people.forEach(System.out::println);

// Person[firstName=Randall, lastName=Oberbrunner, dateOfBirth=Tue Oct 02 06:16:54 BRT 1962]
// Person[firstName=Thanh, lastName=Lemke, dateOfBirth=Fri Feb 28 10:54:57 BRST 1964]
// Person[firstName=Walker, lastName=Waters, dateOfBirth=Fri Feb 21 16:55:01 BRT 1992]
// Person[firstName=Colin, lastName=Koelpin, dateOfBirth=Wed Jul 28 15:03:17 BRT 1982]
// Person[firstName=Velia, lastName=Corwin, dateOfBirth=Thu Nov 07 06:41:49 BRT 1974]
// Person[firstName=Dwayne, lastName=Wilkinson, dateOfBirth=Mon Apr 24 16:38:56 BRT 1972]
// Person[firstName=Lynn, lastName=Oberbrunner, dateOfBirth=Tue Mar 11 09:29:37 BRT 2003]
// Person[firstName=Cristie, lastName=Yundt, dateOfBirth=Thu Sep 04 05:28:06 BRT 1980]
// Person[firstName=Brynn, lastName=Tremblay, dateOfBirth=Thu Nov 03 10:28:57 BRST 1988]
// Person[firstName=Ahmad, lastName=Homenick, dateOfBirth=Tue Apr 19 15:46:28 BRT 1977]
}

private static Person createPerson() {
return new Person(
FAKER.name().firstName(),
FAKER.name().lastName(),
FAKER.date().birthday()
);
}

static record Person(String firstName, String lastName, Date dateOfBirth) {
}
}
1 change: 1 addition & 0 deletions days/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
<module>day092</module>
<module>day093</module>
<module>day094</module>
<module>day095</module>
</modules>

</project>

0 comments on commit 573d5a8

Please sign in to comment.