Skip to content

Commit

Permalink
Updates to readme, pom, and test
Browse files Browse the repository at this point in the history
  • Loading branch information
justodiaz committed Mar 2, 2024
1 parent 4a6f37a commit a78016f
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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`
29 changes: 29 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<groupId>org.example</groupId>
<artifactId>Quotely</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<maven.compiler.source>21</maven.compiler.source>
Expand All @@ -33,6 +34,34 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>
org.example.Quotely
</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>


</project>
10 changes: 8 additions & 2 deletions src/test/java/org/example/ForismaticAPITest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> Optional<T> send(HttpRequest httpRequest, Class<T> type) {
if (type.equals(Quote.class)) {
return Optional.<T>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();
}
Expand All @@ -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());
}
}

0 comments on commit a78016f

Please sign in to comment.