From a78016f95dd51682969854ef8a906b8c4f3f11d8 Mon Sep 17 00:00:00 2001 From: Justo Diaz Date: Fri, 1 Mar 2024 20:32:16 -0600 Subject: [PATCH] Updates to readme, pom, and test --- README.md | 16 +++++++++- pom.xml | 29 +++++++++++++++++++ .../java/org/example/ForismaticAPITest.java | 10 +++++-- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e7e871c..e9fe47a 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,17 @@ Simple Java app that queries `forismatic.com/api/1.0/` to get a random quote and author. -Takes in a command line argument that can be either "English" or "Russian" to choose the language of the quoute. +Takes in a command line argument that can be either "English" or "Russian" to choose the language of the quote. If no argument is passed or an invalid `String` is given, it defaults to "English" + +Project requires Maven and Java 21 to be installed. To run, it may be easier to use an IDE and import repo as a +Maven project. The `main` method is in `org.example.Quotely`. + +`pom.xml` file is configured to package all dependencies into 1 jar. +So it may be possible to run from command line with: + +`mvn package -f pom.xml` + +`java -jar Quotely-1.0-SNAPSHOT-jar-with-dependencies.jar` + +Optional params can go at the end e.g. + +`java -jar Quotely-1.0-SNAPSHOT-jar-with-dependencies.jar Russian` \ No newline at end of file diff --git a/pom.xml b/pom.xml index 40c8245..d89e617 100644 --- a/pom.xml +++ b/pom.xml @@ -7,6 +7,7 @@ org.example Quotely 1.0-SNAPSHOT + jar 21 @@ -33,6 +34,34 @@ + + + + org.apache.maven.plugins + maven-assembly-plugin + + + package + + single + + + + + + org.example.Quotely + + + + + jar-with-dependencies + + + + + + + \ No newline at end of file diff --git a/src/test/java/org/example/ForismaticAPITest.java b/src/test/java/org/example/ForismaticAPITest.java index 74260b4..8e3613a 100644 --- a/src/test/java/org/example/ForismaticAPITest.java +++ b/src/test/java/org/example/ForismaticAPITest.java @@ -8,14 +8,14 @@ import static org.junit.jupiter.api.Assertions.*; class ForismaticAPITest { - private ForismaticAPI forismaticAPI; + private final ForismaticAPI forismaticAPI; public ForismaticAPITest() { var mockRequester = new HTTPJsonRequestClient() { @Override public Optional send(HttpRequest httpRequest, Class type) { if (type.equals(Quote.class)) { - return Optional.of((T) new Quote("Java 21 is great", "Java Beans")); + return Optional.of((T) new Quote("Java 21 is great", "Java Beans")); } return Optional.empty(); } @@ -33,4 +33,10 @@ void getQuote() { assertEquals("Java 21 is great", actual.get().quoteText()); assertEquals("Java Beans", actual.get().quoteAuthor()); } + + @Test + void getQuote_UnknownLanguage_GetsEmptyResponse() { + var actual = forismaticAPI.getQuote(Language.UNKNOWN); + assertTrue(actual.isEmpty()); + } }