Skip to content

Commit

Permalink
+ testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
joethei committed Nov 10, 2020
1 parent f093370 commit c745dff
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/main/java/xyz/joethei/recipe/RecipeParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

import java.io.IOException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -36,6 +38,11 @@ public static Recipe parse(@NotNull final String data) throws IOException {
return null;
}

@Nullable
public static Recipe parse(@NotNull final Path path) throws IOException {
return parseContent(Files.readString(path));
}


@Nullable
private static Recipe parseWebsite(@NotNull final String url) throws IOException {
Expand Down
20 changes: 19 additions & 1 deletion src/test/java/xyz/joethei/recipe/test/TextParsing.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,18 @@
package xyz.joethei.recipe.test;

import org.junit.jupiter.api.Test;
import xyz.joethei.recipe.Recipe;
import xyz.joethei.recipe.RecipeParser;

import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Objects;
import java.util.Optional;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

/**
* @author Johannes Theiner
Expand All @@ -14,7 +26,13 @@
public class TextParsing {

@Test
public void validParsing() {
public void validParsing() throws IOException, URISyntaxException {

Recipe recipe = RecipeParser.parse(Path.of(Objects.requireNonNull(getClass().getClassLoader().getResource("recipe.json")).toURI()));
assertNotNull(recipe);
assertEquals("Tomatenspaghetti", recipe.name());
assertEquals(Arrays.asList("300 g Spaghetti", "40 g Butter", "400 g passierte Tomaten"), recipe.recipeIngredient());
assertEquals(Optional.empty(), recipe.cookTime());
assertEquals(Optional.of("P0DT0H15M"), recipe.totalTime());
}
}
69 changes: 69 additions & 0 deletions src/test/resources/recipe.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"@context": "http://schema.org",
"@type": "Recipe",
"image": "https://example.com/image.png",
"recipeCategory": "Pasta & Nudel",
"recipeIngredient": [
"300 g Spaghetti",
"40 g Butter",
"400 g passierte Tomaten"
],
"name": "Tomatenspaghetti",
"description": "Tomatenspaghetti ",
"recipeInstructions": "Die Nudeln kochen.",
"author": {
"@type": "Person",
"name": "Testing"
},
"publisher": {
"@type": "Organization",
"name": "Nobody"
},
"datePublished": "2009-04-09",
"prepTime": "P0DT0H15M",
"totalTime": "P0DT0H15M",
"recipeYield": "4 Portion(en)",
"aggregateRating": {
"@type": "AggregateRating",
"ratingCount": 7,
"ratingValue": 4.22,
"reviewCount": 6,
"worstRating": 0,
"bestRating": 5
},
"nutrition": {
"@type": "NutritionInformation",
"servingSize": "1",
"calories": "603 kcal",
"proteinContent": "17,20g",
"fatContent": "29,86g",
"carbohydrateContent": "66,12g"
},
"keywords": [
"Hauptspeise",
"Nudeln",
"Pasta",
"Vegetarisch"
],
"reviews": [
{
"@type": "Review",
"reviewBody": "Hello World",
"datePublished": "2019-11-27",
"author": {
"@type": "Person",
"name": "TestUser"
}
},
{
"@type": "Review",
"reviewBody": "Nice",
"datePublished": "2018-08-30",
"author": {
"@type": "Person",
"name": "user"
}
}
]
}

0 comments on commit c745dff

Please sign in to comment.