From 677a39ffceea457556b4bb2ee558cb335381f8e2 Mon Sep 17 00:00:00 2001 From: Pascal Schumacher Date: Fri, 29 Apr 2016 20:52:15 +0200 Subject: [PATCH] added Shakespeare --- README.md | 1 + src/main/java/com/github/javafaker/Faker.java | 7 ++ .../com/github/javafaker/Shakespeare.java | 86 +++++++++++++++++++ .../com/github/javafaker/ShakespeareTest.java | 39 +++++++++ .../github/javafaker/integration/FakerIT.java | 1 + 5 files changed, 134 insertions(+) create mode 100644 src/main/java/com/github/javafaker/Shakespeare.java create mode 100644 src/test/java/com/github/javafaker/ShakespeareTest.java diff --git a/README.md b/README.md index 9a2cf692..5dddfc97 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,7 @@ Fakers * Number * Options * PhoneNumber +* Shakespeare * Superhero * Team diff --git a/src/main/java/com/github/javafaker/Faker.java b/src/main/java/com/github/javafaker/Faker.java index f576285a..24fd5596 100644 --- a/src/main/java/com/github/javafaker/Faker.java +++ b/src/main/java/com/github/javafaker/Faker.java @@ -38,6 +38,7 @@ public class Faker implements Resolver { private final Code code; private final Finance finance; private final DateAndTime dateAndTime; + private final Shakespeare shakespeare; private final Superhero superhero; private final Bool bool; private final Team team; @@ -80,6 +81,7 @@ public class Faker implements Resolver { this.code = new Code(randomService); this.finance = new Finance(proxiedFakeValueService, randomService); this.dateAndTime = new DateAndTime(randomService); + this.shakespeare = new Shakespeare(randomService); this.superhero = new Superhero(this, proxiedFakeValueService); this.team = new Team(this, proxiedFakeValueService); this.bool = new Bool(randomService); @@ -207,6 +209,10 @@ public class Faker implements Resolver { return dateAndTime; } + public Shakespeare shakespeare() { + return shakespeare; + } + public Superhero superhero() { return superhero; } @@ -244,4 +250,5 @@ public class Faker implements Resolver { throw new RuntimeException(e); } } + } diff --git a/src/main/java/com/github/javafaker/Shakespeare.java b/src/main/java/com/github/javafaker/Shakespeare.java new file mode 100644 index 00000000..43b6af8d --- /dev/null +++ b/src/main/java/com/github/javafaker/Shakespeare.java @@ -0,0 +1,86 @@ +package com.github.javafaker; + +import com.github.javafaker.service.RandomService; + +public class Shakespeare { + + private static final String [] hamletQuotes = { + "To be, or not to be: that is the question.", + "Neither a borrower nor a lender be; For loan oft loses both itself and friend, and borrowing dulls the edge of husbandry.", + "This above all: to thine own self be true.", + "Though this be madness, yet there is method in 't.", + "That it should come to this!.", + "There is nothing either good or bad, but thinking makes it so.", + "What a piece of work is man! how noble in reason! how infinite in faculty! in form and moving how express and admirable! in action how like an angel! in apprehension how like a god! the beauty of the world, the paragon of animals! .", + "The lady doth protest too much, methinks.", + "In my mind's eye.", + "A little more than kin, and less than kind.", + "The play 's the thing wherein I'll catch the conscience of the king.", + "And it must follow, as the night the day, thou canst not then be false to any man.", + "Brevity is the soul of wit.", + "Doubt that the sun doth move, doubt truth to be a liar, but never doubt I love.", + "Rich gifts wax poor when givers prove unkind.", + "Do you think I am easier to be played on than a pipe?", + "I will speak daggers to her, but use none.", + "When sorrows come, they come not single spies, but in battalions." }; + + private static final String [] asYouLikeItQuotes = { + "All the world 's a stage, and all the men and women merely players. They have their exits and their entrances; And one man in his time plays many parts.", + "Can one desire too much of a good thing?.", + "I like this place and willingly could waste my time in it.", + "How bitter a thing it is to look into happiness through another man's eyes!", + "Blow, blow, thou winter wind! Thou art not so unkind as man's ingratitude.", + "True is it that we have seen better days.", + "For ever and a day.", + "The fool doth think he is wise, but the wise man knows himself to be a fool." }; + + private static final String [] kingRichardIIIQuotes = { + "Now is the winter of our discontent.", + "A horse! a horse! my kingdom for a horse!.", + "Conscience is but a word that cowards use, devised at first to keep the strong in awe.", + "So wise so young, they say, do never live long.", + "Off with his head!", + "An honest tale speeds best, being plainly told.", + "The king's name is a tower of strength.", + "The world is grown so bad, that wrens make prey where eagles dare not perch." }; + + private static final String [] romeoAndJulietQuotes = { + "O Romeo, Romeo! wherefore art thou Romeo?.", + "It is the east, and Juliet is the sun.", + "Good Night, Good night! Parting is such sweet sorrow, that I shall say good night till it be morrow.", + "What's in a name? That which we call a rose by any other name would smell as sweet.", + "Wisely and slow; they stumble that run fast.", + "Tempt not a desperate man.", + "For you and I are past our dancing days.", + "O! she doth teach the torches to burn bright.", + "It seems she hangs upon the cheek of night like a rich jewel in an Ethiope's ear.", + "See, how she leans her cheek upon her hand! O that I were a glove upon that hand, that I might touch that cheek!.", + "Not stepping o'er the bounds of modesty." }; + + private final RandomService randomService; + + public Shakespeare(RandomService randomService) { + this.randomService = randomService; + } + + public String hamletQuote() { + return randomElement(hamletQuotes); + } + + public String asYouLikeItQuote() { + return randomElement(asYouLikeItQuotes); + } + + public String kingRichardIIIQuote() { + return randomElement(kingRichardIIIQuotes); + } + + public String romeoAndJulietQuote() { + return randomElement(romeoAndJulietQuotes); + } + + private String randomElement(String[] values) { + return values[randomService.nextInt(values.length)]; + } + +} diff --git a/src/test/java/com/github/javafaker/ShakespeareTest.java b/src/test/java/com/github/javafaker/ShakespeareTest.java new file mode 100644 index 00000000..474cc10b --- /dev/null +++ b/src/test/java/com/github/javafaker/ShakespeareTest.java @@ -0,0 +1,39 @@ +package com.github.javafaker; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.isEmptyOrNullString; +import static org.hamcrest.Matchers.not; + +import org.junit.Before; +import org.junit.Test; + +public class ShakespeareTest { + + private Faker faker; + + @Before + public void before() { + faker = new Faker(); + } + + @Test + public void testHamletQuote() { + assertThat(faker.shakespeare().hamletQuote(), not(isEmptyOrNullString())); + } + + @Test + public void testAsYouLikeItQuote() { + assertThat(faker.shakespeare().asYouLikeItQuote(), not(isEmptyOrNullString())); + } + + @Test + public void testKingRichardIIIQuote() { + assertThat(faker.shakespeare().kingRichardIIIQuote(), not(isEmptyOrNullString())); + } + + @Test + public void testRomeoAndJulietQuote() { + assertThat(faker.shakespeare().romeoAndJulietQuote(), not(isEmptyOrNullString())); + } + +} diff --git a/src/test/java/com/github/javafaker/integration/FakerIT.java b/src/test/java/com/github/javafaker/integration/FakerIT.java index a29f1d6d..bda4f398 100644 --- a/src/test/java/com/github/javafaker/integration/FakerIT.java +++ b/src/test/java/com/github/javafaker/integration/FakerIT.java @@ -82,6 +82,7 @@ public class FakerIT { testAllMethodsThatReturnStringsActuallyReturnStrings(faker.phoneNumber()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.name()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.finance()); + testAllMethodsThatReturnStringsActuallyReturnStrings(faker.shakespeare()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.superhero()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.team()); testAllMethodsThatReturnStringsActuallyReturnStrings(faker.beer());