|
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.databind.JavaType; |
4 | 4 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 5 | +import com.mindee.parsing.common.Document; |
| 6 | +import com.mindee.parsing.common.Page; |
5 | 7 | import com.mindee.parsing.common.PredictResponse; |
6 | 8 | import org.junit.jupiter.api.Assertions; |
7 | 9 | import org.junit.jupiter.api.Test; |
8 | | - |
9 | | -import java.io.*; |
| 10 | +import java.io.File; |
| 11 | +import java.io.IOException; |
10 | 12 | import java.nio.file.Files; |
11 | 13 | import java.nio.file.Paths; |
12 | 14 | import java.util.List; |
13 | 15 |
|
14 | | -class InvoiceV4Test { |
15 | | - |
16 | | - @Test |
17 | | - void givenAnInvoiceV4_whenDeserialized_MustHaveAValidSummary() throws IOException { |
| 16 | +/** |
| 17 | + * Unit tests for InvoiceV4. |
| 18 | + */ |
| 19 | +public class InvoiceV4Test { |
18 | 20 |
|
| 21 | + protected PredictResponse<InvoiceV4> getPrediction() throws IOException { |
19 | 22 | ObjectMapper objectMapper = new ObjectMapper(); |
20 | 23 | objectMapper.findAndRegisterModules(); |
21 | 24 |
|
22 | | - JavaType type = objectMapper.getTypeFactory().constructParametricType(PredictResponse.class, |
23 | | - InvoiceV4.class); |
24 | | - PredictResponse<InvoiceV4> invoiceV4Prediction = objectMapper.readValue( |
25 | | - new File("src/test/resources/invoice/response_v4/complete.json"), |
26 | | - type); |
| 25 | + JavaType type = objectMapper.getTypeFactory().constructParametricType( |
| 26 | + PredictResponse.class, |
| 27 | + InvoiceV4.class |
| 28 | + ); |
| 29 | + return objectMapper.readValue( |
| 30 | + new File("src/test/resources/invoice/response_v4/complete.json"), |
| 31 | + type |
| 32 | + ); |
| 33 | + } |
27 | 34 |
|
28 | | - String[] actualLines = invoiceV4Prediction.getDocument().toString().split(System.lineSeparator()); |
29 | | - List<String> expectedLines = Files |
30 | | - .readAllLines(Paths.get("src/test/resources/invoice/response_v4/summary_full.rst")); |
| 35 | + @Test |
| 36 | + void whenCompleteDeserialized_mustHaveValidDocumentSummary() throws IOException { |
| 37 | + PredictResponse<InvoiceV4> prediction = getPrediction(); |
| 38 | + Document<InvoiceV4> doc = prediction.getDocument(); |
| 39 | + String[] actualLines = doc.toString().split(System.lineSeparator()); |
| 40 | + List<String> expectedLines = Files.readAllLines( |
| 41 | + Paths.get("src/test/resources/invoice/response_v4/summary_full.rst") |
| 42 | + ); |
31 | 43 | String expectedSummary = String.join(String.format("%n"), expectedLines); |
32 | 44 | String actualSummary = String.join(String.format("%n"), actualLines); |
33 | 45 |
|
34 | 46 | Assertions.assertEquals(expectedSummary, actualSummary); |
35 | 47 | } |
36 | 48 |
|
| 49 | + @Test |
| 50 | + void whenCompleteDeserialized_mustHaveValidPage0Summary() throws IOException { |
| 51 | + PredictResponse<InvoiceV4> prediction = getPrediction(); |
| 52 | + Page<InvoiceV4Document> page = prediction.getDocument().getInference().getPages().get(0); |
| 53 | + String[] actualLines = page.toString().split(System.lineSeparator()); |
| 54 | + List<String> expectedLines = Files.readAllLines( |
| 55 | + Paths.get("src/test/resources/invoice/response_v4/summary_page0.rst") |
| 56 | + ); |
| 57 | + String expectedSummary = String.join(String.format("%n"), expectedLines); |
| 58 | + String actualSummary = String.join(String.format("%n"), actualLines); |
| 59 | + |
| 60 | + Assertions.assertEquals(expectedSummary, actualSummary); |
| 61 | + } |
37 | 62 | } |
0 commit comments