|
| 1 | +/* |
| 2 | + * Copyright 2023 webtau maintainers |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.testingisdocumenting.webtau.expectation.equality.handlers; |
| 18 | + |
| 19 | +import org.junit.Test; |
| 20 | +import org.testingisdocumenting.webtau.data.table.TableData; |
| 21 | + |
| 22 | +import static org.testingisdocumenting.webtau.Matchers.*; |
| 23 | +import static org.testingisdocumenting.webtau.WebTauCore.*; |
| 24 | +import static org.testingisdocumenting.webtau.testutils.TestConsoleOutput.*; |
| 25 | + |
| 26 | +public class TableDataMatchersJavaExamplesTest { |
| 27 | + @Test |
| 28 | + public void equalityMismatch() { |
| 29 | + runExpectExceptionCaptureAndValidateOutput(AssertionError.class, "table-equal-console-output", """ |
| 30 | + X failed expecting [value] to equal ColumnA │ ColumnB \s |
| 31 | + 10 │ <greater than 15> |
| 32 | + <any of [20, 22]> │ 40: |
| 33 | + [value][1].ColumnA: actual: 30 <java.lang.Integer> |
| 34 | + expected: 20 <java.lang.Integer> |
| 35 | + actual: 30 <java.lang.Integer> |
| 36 | + expected: 22 <java.lang.Integer> (Xms) |
| 37 | + \s |
| 38 | + ColumnA │ ColumnB |
| 39 | + 10 │ 20 |
| 40 | + **30** │ 40""", () -> { |
| 41 | + // table-equal-mismatch |
| 42 | + var summary = loadFromCsv("summary.csv"); |
| 43 | + TableData expected = table("ColumnA", "ColumnB", |
| 44 | + _________________________, |
| 45 | + 10, greaterThan(15), |
| 46 | + anyOf(20, 22), 40); |
| 47 | + |
| 48 | + actual(summary).should(equal(expected)); |
| 49 | + // table-equal-mismatch |
| 50 | + }); |
| 51 | + } |
| 52 | + |
| 53 | + @Test |
| 54 | + public void containsMismatch() { |
| 55 | + runExpectExceptionCaptureAndValidateOutput(AssertionError.class, "table-contain-console-output", """ |
| 56 | + X failed expecting [value] to contain {"ColumnA": 20, "ColumnB": <greater than 15>}: no match found (Xms) |
| 57 | + \s |
| 58 | + ColumnA │ ColumnB |
| 59 | + 10 │ 20 |
| 60 | + 30 │ 40""", () -> { |
| 61 | + // table-contain-mismatch |
| 62 | + var summary = loadFromCsv("summary.csv"); |
| 63 | + actual(summary).should(contain(map("ColumnA", 20, "ColumnB", greaterThan(15)))); |
| 64 | + // table-contain-mismatch |
| 65 | + }); |
| 66 | + } |
| 67 | + |
| 68 | + private static TableData loadFromCsv(String fileName) { |
| 69 | + return table("ColumnA", "ColumnB", |
| 70 | + ___________________, |
| 71 | + 10, 20, |
| 72 | + 30, 40); |
| 73 | + } |
| 74 | +} |
0 commit comments