|
| 1 | +/* |
| 2 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 3 | + * the License. You may obtain a copy of the License at |
| 4 | + * |
| 5 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | + * |
| 7 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 8 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 9 | + * specific language governing permissions and limitations under the License. |
| 10 | + * |
| 11 | + * Copyright 2015-2021 the original author or authors. |
| 12 | + */ |
| 13 | +package org.assertj.db.api.assertions; |
| 14 | + |
| 15 | +import org.assertj.core.api.Assertions; |
| 16 | +import org.assertj.core.api.Condition; |
| 17 | +import org.assertj.core.api.HamcrestCondition; |
| 18 | +import org.assertj.db.api.ChangeRowAssert; |
| 19 | +import org.assertj.db.api.TableRowAssert; |
| 20 | +import org.assertj.db.common.AbstractTest; |
| 21 | +import org.assertj.db.common.NeedReload; |
| 22 | +import org.assertj.db.type.Changes; |
| 23 | +import org.assertj.db.type.Table; |
| 24 | +import org.hamcrest.CoreMatchers; |
| 25 | +import org.junit.Test; |
| 26 | + |
| 27 | +import java.util.UUID; |
| 28 | + |
| 29 | +import static org.assertj.db.api.Assertions.assertThat; |
| 30 | + |
| 31 | +/** |
| 32 | + * Tests on {@link AssertOnRowCondition} class : |
| 33 | + * {@link AssertOnRowCondition#hasValuesSatisfying(Object...)} method. |
| 34 | + * |
| 35 | + * @author Julien Roy |
| 36 | + * |
| 37 | + */ |
| 38 | +public class AssertOnRowCondition_HasValuesSatisfying_Test extends AbstractTest { |
| 39 | + |
| 40 | + /** |
| 41 | + * This method tests the {@code hasValuesSatisfying} assertion method. |
| 42 | + */ |
| 43 | + @Test |
| 44 | + @NeedReload |
| 45 | + public void test_has_values() { |
| 46 | + Table table = new Table(source, "actor"); |
| 47 | + Changes changes = new Changes(table).setStartPointNow(); |
| 48 | + updateChangesForTests(); |
| 49 | + changes.setEndPointNow(); |
| 50 | + |
| 51 | + ChangeRowAssert changeRowAssert = assertThat(changes).change().rowAtEndPoint(); |
| 52 | + ChangeRowAssert changeRowAssert2 = changeRowAssert |
| 53 | + .hasValuesSatisfying( |
| 54 | + 4, |
| 55 | + new Condition<String>(v -> v.equals("Murray"), "isMurray"), |
| 56 | + new HamcrestCondition<>(CoreMatchers.is("Bill")), |
| 57 | + "1950-09-21", |
| 58 | + "30B443AE-C0C9-4790-9BEC-CE1380808435" |
| 59 | + ) |
| 60 | + .hasValues(4, "Murray", "Bill", "1950-09-21", UUID.fromString("30B443AE-C0C9-4790-9BEC-CE1380808435")); |
| 61 | + Assertions.assertThat(changeRowAssert).isSameAs(changeRowAssert2); |
| 62 | + |
| 63 | + TableRowAssert tableRowAssert = assertThat(table).row(); |
| 64 | + TableRowAssert tableRowAssert2 = tableRowAssert |
| 65 | + .hasValues(1, "Weaver", "Susan Alexandra", "1949-10-08", "30B443AE-C0C9-4790-9BEC-CE1380808435") |
| 66 | + .hasValues(1, "Weaver", "Susan Alexandra", "1949-10-08", UUID.fromString("30B443AE-C0C9-4790-9BEC-CE1380808435")); |
| 67 | + Assertions.assertThat(tableRowAssert).isSameAs(tableRowAssert2); |
| 68 | + } |
| 69 | + |
| 70 | + /** |
| 71 | + * This method should fail because the values are different. |
| 72 | + */ |
| 73 | + @Test |
| 74 | + @NeedReload |
| 75 | + public void should_fail_because_values_are_different() { |
| 76 | + Table table = new Table(source, "actor"); |
| 77 | + Changes changes = new Changes(table).setStartPointNow(); |
| 78 | + updateChangesForTests(); |
| 79 | + changes.setEndPointNow(); |
| 80 | + |
| 81 | + try { |
| 82 | + assertThat(changes).change().rowAtEndPoint() |
| 83 | + .hasValues(4, "Murray", "Billy", "1950-09-21", UUID.fromString("30B443AE-C0C9-4790-9BEC-CE1380808435")); |
| 84 | + } catch (AssertionError e) { |
| 85 | + Assertions.assertThat(e.getMessage()).isEqualTo(String.format( |
| 86 | + "[Row at end point of Change at index 0 (with primary key : [4]) of Changes on ACTOR table of 'sa/jdbc:h2:mem:test' source] %n" |
| 87 | + + "Expecting that the value at index 2:%n" |
| 88 | + + " <\"Bill\">%n" |
| 89 | + + "to be equal to: %n" |
| 90 | + + " <\"Billy\">")); |
| 91 | + } |
| 92 | + try { |
| 93 | + assertThat(table).row().hasValues(1, "Weaver", "Sigourney", "1949-10-08", |
| 94 | + UUID.fromString("648DFAC8-14AC-47F7-95CF-3475525A3BE3")); |
| 95 | + } catch (AssertionError e) { |
| 96 | + Assertions.assertThat(e.getMessage()).isEqualTo(String.format("[Row at index 0 of ACTOR table] %n" |
| 97 | + + "Expecting that the value at index 2:%n" |
| 98 | + + " <\"Susan Alexandra\">%n" |
| 99 | + + "to be equal to: %n" |
| 100 | + + " <\"Sigourney\">")); |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments