|
| 1 | +package com.mindee.v2.product; |
| 2 | + |
| 3 | +import static com.mindee.TestingUtilities.getV2ResourcePath; |
| 4 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 5 | +import static org.junit.jupiter.api.Assertions.assertNotNull; |
| 6 | + |
| 7 | +import com.mindee.input.LocalResponse; |
| 8 | +import com.mindee.v2.product.split.SplitRange; |
| 9 | +import com.mindee.v2.product.split.SplitResponse; |
| 10 | +import java.io.IOException; |
| 11 | +import java.util.ArrayList; |
| 12 | +import org.junit.jupiter.api.DisplayName; |
| 13 | +import org.junit.jupiter.api.Nested; |
| 14 | +import org.junit.jupiter.api.Test; |
| 15 | + |
| 16 | +@DisplayName("MindeeV2 - Split Model Tests") |
| 17 | +public class SplitTest { |
| 18 | + private SplitResponse loadResponse(String filePath) throws IOException { |
| 19 | + LocalResponse localResponse = new LocalResponse(getV2ResourcePath(filePath)); |
| 20 | + return localResponse.deserializeResponse(SplitResponse.class); |
| 21 | + } |
| 22 | + |
| 23 | + @Nested |
| 24 | + @DisplayName("Result with single value") |
| 25 | + class SinglePredictionTest { |
| 26 | + @Test |
| 27 | + @DisplayName("all properties must be valid") |
| 28 | + void mustHaveValidProperties() throws IOException { |
| 29 | + SplitResponse response = loadResponse("products/split/split_single.json"); |
| 30 | + assertNotNull(response.getInference()); |
| 31 | + |
| 32 | + ArrayList<SplitRange> splits = response.getInference().getResult().getSplits(); |
| 33 | + assertEquals(1, splits.size()); |
| 34 | + assertEquals("receipt", splits.get(0).getDocumentType()); |
| 35 | + assertEquals(0, splits.get(0).getPageRange().get(0)); |
| 36 | + } |
| 37 | + } |
| 38 | + |
| 39 | + @Nested |
| 40 | + @DisplayName("Result with multiple values") |
| 41 | + class MultiPredictionTest { |
| 42 | + @Test |
| 43 | + @DisplayName("all properties must be valid") |
| 44 | + void mustHaveValidProperties() throws IOException { |
| 45 | + SplitResponse response = loadResponse("products/split/split_multiple.json"); |
| 46 | + assertNotNull(response.getInference()); |
| 47 | + |
| 48 | + ArrayList<SplitRange> splits = response.getInference().getResult().getSplits(); |
| 49 | + assertEquals(3, splits.size()); |
| 50 | + |
| 51 | + SplitRange split1 = splits.get(0); |
| 52 | + assertEquals("invoice", split1.getDocumentType()); |
| 53 | + assertEquals(0, split1.getPageRange().get(0)); |
| 54 | + |
| 55 | + SplitRange split2 = splits.get(1); |
| 56 | + assertEquals("invoice", split2.getDocumentType()); |
| 57 | + assertEquals(1, split2.getPageRange().get(0)); |
| 58 | + |
| 59 | + SplitRange split3 = splits.get(2); |
| 60 | + assertEquals("invoice", split3.getDocumentType()); |
| 61 | + assertEquals(4, split3.getPageRange().get(0)); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments